Browse Source

quickfix mensa json parsing

master
angerstoner 3 years ago
parent
commit
7ac746809f
  1. 23
      mensa.py

23
mensa.py

@ -119,16 +119,19 @@ def mensa(update: Update, context: CallbackContext):
else: else:
message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which]) message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
for cat in today_data['categories']: for cat in today_data['categories']:
label = cat['name']
meals = cat['meals']
if label not in filter_categories and (
any(filtered in label for filtered in diet) or
[item['name'].replace('\xad', '') for item in meals if
any(filtered in item['name'].replace('\xad', '') for filtered in diet)]): # TODO: simplify
meal_line = "*%s*\n" % label
for meal in meals:
meal_line += meal['name'].strip() + "\n"
message += meal_line + '\n'
try:
label = cat['name']
meals = cat['meals']
if label not in filter_categories and (
any(filtered in label for filtered in diet) or
[item['name'].replace('\xad', '') for item in meals if
any(filtered in item['name'].replace('\xad', '') for filtered in diet)]): # TODO: simplify
meal_line = "*%s*\n" % label
for meal in meals:
meal_line += meal['name'].strip() + "\n"
message += meal_line + '\n'
except: # TODO: catch correct exception
print("Could not fetch meal. Skipping.")
update.message.reply_text(message, ParseMode.MARKDOWN) update.message.reply_text(message, ParseMode.MARKDOWN)

Loading…
Cancel
Save