Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scraper for URL structure #487

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions server/scraper/resto/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,24 @@
# The url containing the list of week menus.
WEEK_MENU_URL = {
"en": "https://www.ugent.be/en/facilities/restaurants/weekly-menu",
"nl": "https://www.ugent.be/student/nl/meer-dan-studeren/resto/weekmenu"
"nl": "https://www.ugent.be/student/nl/meer-dan-studeren/resto/weekmenu",
"nl-sterre": "https://www.ugent.be/student/nl/meer-dan-studeren/resto/weekmenu",
"nl-debrug": "https://www.ugent.be/student/nl/meer-dan-studeren/resto/weekmenu",
"nl-coupure": "https://www.ugent.be/student/nl/meer-dan-studeren/resto/weekmenu"
}

NORMAL_WEEK = re.compile(r"week(\d+)$")
INDIVIDUAL_DAY_URL_OVERRIDE = {
"nl-coupure": r"week(\d+)coupure$",
"nl-debrug": r"week(\d+)brugsterre|week(27)duurzaam|week(28)duurzaam",
"nl-sterre": r"week(\d+)(brugsterre|sterre)|week(27)duurzaam",
"nl-ardoyen": r"week(\d+)ardoyen"
"nl-coupure": r"week(\d+)-?(ardoyen-)?coupure$",
"nl-debrug": r"week(\d+)-?(brugsterre|brug)|week(27)duurzaam|week(28)duurzaam",
"nl-sterre": r"week(\d+)-?(brugsterre|sterre)|week(27)duurzaam",
"nl-ardoyen": r"week(\d+)-?ardoyen(-coupure)?"
}

# These endpoints are copies of another endpoint.
# While this seems useless, it allows messages per endpoint,
# which is very useful.
# TODO: there is currently no "nl" endpoint, so this is pointless.
COPIED_ENDPOINTS = {
"nl-debrug": "nl",
"nl-coupure": "nl",
Expand Down Expand Up @@ -244,6 +248,11 @@ def get_weeks(which):
page_type = WEEK_MENU_PAGE_TYPE[which]
week_parser = WEEK_MENU_PARSERS[page_type]
week_urls = week_parser(WEEK_MENU_URL[which], which)
# If there are no week urls for "nl", which is our fallback,
# use those from "nl-debrug".
if not week_urls:
# This is an ugly hack :(
week_urls = week_parser(WEEK_MENU_URL["nl-debrug"], "nl-debrug")
r = {}
for url in week_urls:
try:
Expand Down
Loading