mirror of https://github.com/stijndcl/didier
Fix food
parent
7ab72aabfd
commit
1ee9900891
|
@ -20,27 +20,29 @@ class School(commands.Cog):
|
|||
@commands.command(name="Eten", aliases=["Food", "Menu"], usage="[Dag]*")
|
||||
# @commands.check(checks.allowedChannels)
|
||||
@help.Category(category=Category.School)
|
||||
async def eten(self, ctx, *day):
|
||||
async def eten(self, ctx, day: str = None):
|
||||
day_dt = les.find_target_date(day if day else None)
|
||||
day_dt = skip_weekends(day_dt)
|
||||
day = intToWeekday(day_dt.weekday())
|
||||
|
||||
# Create embed
|
||||
menu = eten.etenScript(day)
|
||||
menu = eten.etenScript(day_dt)
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_author(name="Menu voor {}".format(day))
|
||||
embed.set_author(name="Menu voor {}".format(day.lower()))
|
||||
|
||||
if "gesloten" in menu[0].lower():
|
||||
embed.description = "Restaurant gesloten"
|
||||
else:
|
||||
embed.add_field(name="Soep:", value=menu[0], inline=False)
|
||||
embed.add_field(name="Hoofdgerechten:", value=menu[1], inline=False)
|
||||
embed.add_field(name="🥣 Soep:", value=menu[0], inline=False)
|
||||
embed.add_field(name="🍴 Hoofdgerechten:", value=menu[1], inline=False)
|
||||
|
||||
if menu[2]:
|
||||
embed.add_field(name="Groenten:", value=menu[2], inline=False)
|
||||
embed.add_field(name="❄️ Koud:", value=menu[2], inline=False)
|
||||
|
||||
embed.set_footer(text="Omwille van de coronamaatregelen is er een beperkter aanbod, en kan je enkel nog eten afhalen. Ter plaatse eten is niet meer mogelijk.")
|
||||
await ctx.send(embed=embed)
|
||||
if menu[3]:
|
||||
embed.add_field(name="🥦 Groenten:", value=menu[3], inline=False)
|
||||
|
||||
await ctx.reply(embed=embed, mention_author=False)
|
||||
|
||||
@commands.command(name="Les", aliases=["Class", "Classes", "Sched", "Schedule"], usage="[Dag]*")
|
||||
# @commands.check(checks.allowedChannels)
|
||||
|
|
|
@ -1,29 +1,39 @@
|
|||
import datetime
|
||||
from datetime import datetime
|
||||
from typing import Dict
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def etenScript(weekDag, resto: str = "sterre"):
|
||||
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
|
||||
|
||||
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"]))
|
||||
|
||||
return acc
|
||||
|
||||
|
||||
def etenScript(dag: datetime, resto: str = "sterre"):
|
||||
# What day
|
||||
weekdagen = ('ma', 'di', 'wo', 'do', 'vr', 'za', 'zo')
|
||||
deltas = {'morgen': 1,
|
||||
'overmorgen': 2,
|
||||
'volgende': 7}
|
||||
|
||||
d = datetime.date.today()
|
||||
|
||||
if weekDag in deltas:
|
||||
d += datetime.timedelta(deltas[weekDag])
|
||||
if weekDag[0:2] in weekdagen:
|
||||
while d.weekday() != weekdagen.index(weekDag[0:2]):
|
||||
d += datetime.timedelta(1)
|
||||
|
||||
menuSoep = ""
|
||||
menuHoofdgerechten = ""
|
||||
menuKoud = ""
|
||||
menuGroenten = ""
|
||||
|
||||
# Fetch from API
|
||||
try:
|
||||
menu = requests.get(f"https://zeus.ugent.be/hydra/api/2.0/resto/menu/nl-{resto}/{d.year}/{d.month}/{d.day}.json").json()
|
||||
menu = requests.get(f"https://zeus.ugent.be/hydra/api/2.0/resto/menu/nl-{resto}/{dag.year}/{dag.month}/{dag.day}.json").json()
|
||||
|
||||
if not menu["meals"]:
|
||||
raise Exception()
|
||||
|
@ -34,20 +44,14 @@ def etenScript(weekDag, resto: str = "sterre"):
|
|||
if s["kind"] == "soup":
|
||||
menuSoep += ("* {} ({})\n".format(s["name"], s["price"]))
|
||||
|
||||
for m in menu["meals"]:
|
||||
if m["kind"] == "meat":
|
||||
menuHoofdgerechten += ("* Vlees: {} ({})\n".format(m["name"], m["price"]))
|
||||
elif m["kind"] == "fish":
|
||||
menuHoofdgerechten += ("* Vis: {} ({})\n".format(m["name"], m["price"]))
|
||||
elif m["kind"] == "vegetarian":
|
||||
menuHoofdgerechten += ("* Vegetarisch: {} ({})\n".format(m["name"], m["price"]))
|
||||
elif m["kind"] == "vegan":
|
||||
menuHoofdgerechten += ("* Vegan: {} ({})\n".format(m["name"], m["price"]))
|
||||
menuHoofdgerechten = get_type(menu, "main")
|
||||
menuKoud = get_type(menu, "cold")
|
||||
|
||||
for v in menu["vegetables"]:
|
||||
menuGroenten += ("* {}\n".format(v))
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
menuSoep += "Restaurant gesloten"
|
||||
menuGroenten += "Restaurant gesloten"
|
||||
menuHoofdgerechten += "Restaurant gesloten"
|
||||
return menuSoep, menuHoofdgerechten, menuGroenten
|
||||
menuKoud += "Restaurant gesloten"
|
||||
return menuSoep, menuHoofdgerechten, menuKoud, menuGroenten
|
||||
|
|
Loading…
Reference in New Issue