Skip to content

Commit

Permalink
Update cafmenu
Browse files Browse the repository at this point in the history
  • Loading branch information
WarpWing authored Apr 9, 2024
1 parent 3f45b47 commit dcc94b5
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions bin/cafmenu
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
#!/usr/bin/env python3

import os
import time
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from typing_extensions import *

def find_week():
return f"Meal for {datetime.now().strftime('%A, %B %d')}"

def get_menu_from_website():
url = 'https://www.dickinson.edu/info/20205/campus_dining/4425/dining_menus'
# Configure Chrome options for headless mode

# Configure Firefox options
options = Options()
options.add_argument("--headless") # Explicitly add headless argument
options.add_argument("--disable-gpu") # Disable GPU hardware acceleration
options.add_argument("--no-sandbox") # Bypass OS security model
options.add_argument("--disable-dev-shm-usage") # Overcome limited resource problems
options.add_argument("--log-level=3") # Suppress logging messages
options.add_experimental_option("excludeSwitches", ["enable-logging"]) # exclude switching and disable high level of logs.

# Use webdriver_manager to automatically manage the ChromeDriver
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
options.add_argument("-headless")
options.add_argument("-disable-gpu")
options.add_argument("-no-sandbox") # Bypass OS security model
options.add_argument("-disable-dev-shm-usage") # Overcome limited resource problems
options.log.level = "fatal" # Suppress logging messages

# Use webdriver_manager to automatically manage Firefox (disabled logging to suppress warnings by piping to devnull)
service = Service(GeckoDriverManager().install(),log_path=os.devnull)
driver = webdriver.Firefox(service=service, options=options)

menu_data = ""
try:
driver.get(url)
time.sleep(5) # Adjust based on the page load time
time.sleep(2) # Adjust based on the page load time

# Find all menu item elements for each meal type
meals = ['Breakfast', 'Lunch', 'Dinner']
Expand All @@ -54,8 +51,6 @@ def get_menu_from_website():

return menu_data

week = find_week()
print(f"Getting the menu for {datetime.now().strftime('%A, %B %d')}...")
menu = get_menu_from_website()

print(week)
print(menu)

0 comments on commit dcc94b5

Please sign in to comment.