added notification when menu is unavailable
This commit is contained in:
parent
2cb5186258
commit
c9c95350a8
@ -215,9 +215,14 @@ class BeeBot:
|
||||
async with self.fetch_lock:
|
||||
if not os.path.exists(menu_path) or self.is_outdated(menu_id, today_only):
|
||||
if today_only:
|
||||
await self.fetch_today_menu()
|
||||
available = await self.fetch_today_menu()
|
||||
else:
|
||||
await self.fetch_week_menu()
|
||||
available = await self.fetch_week_menu()
|
||||
|
||||
if not available:
|
||||
await msg.edit_text(self.i18n(prefs["lang"], "notif.unavailable"))
|
||||
return
|
||||
|
||||
await msg.delete()
|
||||
|
||||
# If image needs to be (re)generated
|
||||
@ -338,33 +343,41 @@ class BeeBot:
|
||||
self.cache[menu_id] = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||
self.save_cache()
|
||||
|
||||
async def fetch_week_menu(self) -> None:
|
||||
async def fetch_week_menu(self) -> bool:
|
||||
logger.info("Fetching week menu")
|
||||
today = datetime.datetime.today()
|
||||
delta = datetime.timedelta(days=today.weekday())
|
||||
monday = today - delta
|
||||
days = []
|
||||
menus_count = 0
|
||||
for i in range(5):
|
||||
dt = datetime.timedelta(days=i)
|
||||
date = monday + dt
|
||||
menus = await self.fetch_menu(date)
|
||||
menus_count += len(menus)
|
||||
days.append({
|
||||
"date": date.strftime("%Y-%m-%d"),
|
||||
"menus": menus
|
||||
})
|
||||
if menus_count == 0:
|
||||
return False
|
||||
|
||||
self.save_menu(days, "week_menu", "menus_week.json")
|
||||
return True
|
||||
|
||||
async def fetch_today_menu(self) -> None:
|
||||
async def fetch_today_menu(self) -> bool:
|
||||
logger.info("Fetching today menu")
|
||||
today = datetime.datetime.today()
|
||||
menus = await self.fetch_menu(today)
|
||||
if len(menus) == 0:
|
||||
return False
|
||||
days = [{
|
||||
"date": today.strftime("%Y-%m-%d"),
|
||||
"menus": menus
|
||||
}]
|
||||
|
||||
self.save_menu(days, "today_menu", "menus_today.json")
|
||||
return True
|
||||
|
||||
async def fetch_menu(self, date: datetime.date) -> list:
|
||||
url = self.MENU_URL.format(date=date.strftime("%Y-%m-%d"))
|
||||
|
@ -10,7 +10,8 @@
|
||||
"menu.back_to_settings": "Retour aux paramètres",
|
||||
"setting.language": "Langue: {}",
|
||||
"setting.categories": "Catégories: {}",
|
||||
"notif.wait_updating": "Le menu est en train d'être mis à jour, veuillez patienter..."
|
||||
"notif.wait_updating": "Le menu est en train d'être mis à jour, veuillez patienter...",
|
||||
"notif.unavailable": "Il semblerait que le menu ne soit actuellement pas disponible"
|
||||
},
|
||||
"en": {
|
||||
"category.student": "Student",
|
||||
@ -23,7 +24,8 @@
|
||||
"menu.back_to_settings": "Back to settings",
|
||||
"setting.language": "Language: {}",
|
||||
"setting.categories": "Categories: {}",
|
||||
"notif.wait_updating": "The menu is being updated, please wait..."
|
||||
"notif.wait_updating": "The menu is being updated, please wait...",
|
||||
"notif.unavailable": "It seems that the menu is currently unavailable"
|
||||
},
|
||||
"de": {
|
||||
"category.student": "Student",
|
||||
@ -36,6 +38,7 @@
|
||||
"menu.back_to_settings": "Zurück zu Einstellungen",
|
||||
"setting.language": "Sprache: {}",
|
||||
"setting.categories": "Kategorien: {}",
|
||||
"notif.wait_updating": "Das Menü wird gerade aktualisiert, bitte warten Sie..."
|
||||
"notif.wait_updating": "Das Menü wird gerade aktualisiert, bitte warten Sie...",
|
||||
"notif.unavailable": "Es scheint, dass das Menü derzeit nicht verfügbar ist"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user