Catch missing fields in menu

pull/128/head
stijndcl 2022-08-29 01:30:58 +02:00
parent 9225f61e47
commit b85f5a612a
4 changed files with 14 additions and 7 deletions

View File

@ -12,4 +12,5 @@ async def fetch_menu(http_session: ClientSession, day_dt: date) -> Menu:
"""Fetch the menu for a given day"""
endpoint = f"https://hydra.ugent.be/api/2.0/resto/menu/nl/{day_dt.year}/{day_dt.month}/{day_dt.day}.json"
async with ensure_get(http_session, endpoint, log_exceptions=False) as response:
print(response)
return Menu.parse_obj(response)

View File

@ -94,12 +94,17 @@ class Menu(EmbedPydantic):
return embed
def _regular_embed(self, embed: discord.Embed) -> discord.Embed:
embed.add_field(name="🥣 Soep", value=self._get_soups(), inline=False)
embed.add_field(name="🍴 Hoofdgerechten", value=self._get_main_courses(), inline=False)
embed.add_field(name="Koud", value=self._get_cold_meals(), inline=False)
if soups := self._get_soups():
embed.add_field(name="🥣 Soep", value=soups, inline=False)
vegetables = "\n".join(list(sorted(self.vegetables)))
embed.add_field(name="🥦 Groenten", value=vegetables, inline=False)
if mains := self._get_main_courses():
embed.add_field(name="🍴 Hoofdgerechten", value=mains, inline=False)
if cold := self._get_cold_meals():
embed.add_field(name="Koud", value=cold, inline=False)
if vegetables := "\n".join(list(sorted(self.vegetables))):
embed.add_field(name="🥦 Groenten", value=vegetables, inline=False)
return embed

View File

@ -15,7 +15,7 @@ from didier.utils.types.datetime import (
str_to_weekday,
)
__all__ = ["date_converter"]
__all__ = ["date_converter", "DateTransformer"]
def date_converter(argument: Optional[str]) -> date:
@ -56,6 +56,7 @@ def date_converter(argument: Optional[str]) -> date:
class DateTransformer(app_commands.Transformer):
"""Application commands transformer for dates"""
@overrides
async def autocomplete(
self, interaction: discord.Interaction, value: Union[int, float, str]
) -> list[app_commands.Choice[Union[int, float, str]]]:

View File

@ -2,7 +2,7 @@ aiohttp==3.8.1
alembic==1.8.0
asyncpg==0.25.0
beautifulsoup4==4.11.1
discord.py==2.0.0
discord.py==2.0.1
environs==9.5.0
feedparser==6.0.10
markdownify==0.11.2