diff --git a/mensa.py b/mensa.py index 76c9d3b..a60d15c 100644 --- a/mensa.py +++ b/mensa.py @@ -69,12 +69,9 @@ MODES = { def mensa(bot, update, args): which = "zentral" filter_categories = MODES["light"] - offset = 0 - # today = datetime.datetime.now().date().weekday() + 1 + today = datetime.datetime.now().date() if datetime.datetime.now().time() > datetime.time(hour=16): - offset += 1 - # - # today = today % 7 + today += datetime.timedelta(days=1) for arg in args: arg = arg.lower() @@ -98,8 +95,7 @@ def mensa(bot, update, args): request.encoding = 'utf-8' data = request.json() - today_data = data['days'][offset] - + today_data = get_data_for_day(today, data) message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which]) for cat in today_data['categories']: if cat['name'] not in filter_categories: @@ -109,3 +105,9 @@ def mensa(bot, update, args): message += meal_line + '\n' update.message.reply_text(message, ParseMode.MARKDOWN) + + +def get_data_for_day(day, complete_data): + for date in complete_data['days']: + if day.isoformat() == date['iso-date']: + return date