2021-09-26 13:10:57 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from typing import Dict
|
|
|
|
|
2020-10-13 21:02:40 +02:00
|
|
|
import requests
|
|
|
|
|
|
|
|
|
2021-09-26 13:10:57 +02:00
|
|
|
def get_type(menu: Dict, type_: str) -> str:
|
|
|
|
acc = ""
|
|
|
|
|
|
|
|
for m in menu["meals"]:
|
|
|
|
# API sometimes has empty results, also filter out wrong type
|
|
|
|
if not m["name"] or m["type"] != type_:
|
|
|
|
continue
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-09-26 13:10:57 +02:00
|
|
|
if m["kind"] == "meat":
|
|
|
|
acc += ("* Vlees: {} ({})\n".format(m["name"], m["price"]))
|
|
|
|
elif m["kind"] == "fish":
|
|
|
|
acc += ("* Vis: {} ({})\n".format(m["name"], m["price"]))
|
|
|
|
elif m["kind"] == "vegetarian":
|
|
|
|
acc += ("* Vegetarisch: {} ({})\n".format(m["name"], m["price"]))
|
|
|
|
elif m["kind"] == "vegan":
|
|
|
|
acc += ("* Vegan: {} ({})\n".format(m["name"], m["price"]))
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-09-26 13:10:57 +02:00
|
|
|
return acc
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-09-26 13:10:57 +02:00
|
|
|
|
|
|
|
def etenScript(dag: datetime, resto: str = "sterre"):
|
|
|
|
# What day
|
2020-10-13 21:02:40 +02:00
|
|
|
menuSoep = ""
|
|
|
|
menuHoofdgerechten = ""
|
2021-09-26 13:10:57 +02:00
|
|
|
menuKoud = ""
|
2020-10-13 21:02:40 +02:00
|
|
|
menuGroenten = ""
|
|
|
|
|
|
|
|
# Fetch from API
|
|
|
|
try:
|
2021-09-26 13:10:57 +02:00
|
|
|
menu = requests.get(f"https://zeus.ugent.be/hydra/api/2.0/resto/menu/nl-{resto}/{dag.year}/{dag.month}/{dag.day}.json").json()
|
2021-08-19 19:45:00 +02:00
|
|
|
|
|
|
|
if not menu["meals"]:
|
|
|
|
raise Exception()
|
|
|
|
|
2020-10-13 21:02:40 +02:00
|
|
|
# Print menu
|
|
|
|
|
|
|
|
for s in menu["meals"]:
|
|
|
|
if s["kind"] == "soup":
|
|
|
|
menuSoep += ("* {} ({})\n".format(s["name"], s["price"]))
|
|
|
|
|
2021-09-26 13:10:57 +02:00
|
|
|
menuHoofdgerechten = get_type(menu, "main")
|
|
|
|
menuKoud = get_type(menu, "cold")
|
2020-10-13 21:02:40 +02:00
|
|
|
|
|
|
|
for v in menu["vegetables"]:
|
|
|
|
menuGroenten += ("* {}\n".format(v))
|
2021-09-26 22:12:52 +02:00
|
|
|
except Exception:
|
2020-10-13 21:02:40 +02:00
|
|
|
menuSoep += "Restaurant gesloten"
|
|
|
|
menuGroenten += "Restaurant gesloten"
|
|
|
|
menuHoofdgerechten += "Restaurant gesloten"
|
2021-09-26 13:10:57 +02:00
|
|
|
menuKoud += "Restaurant gesloten"
|
|
|
|
return menuSoep, menuHoofdgerechten, menuKoud, menuGroenten
|