From 0c8b0c15eb4d432f05028a8042054a18e76095d0 Mon Sep 17 00:00:00 2001 From: Angerstoner Date: Sat, 9 Feb 2019 16:39:20 +0100 Subject: [PATCH] fixed filtering by diet --- mensa.py | 27 ++++++++++++++++----------- schneiderbot.py | 14 ++++++++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/mensa.py b/mensa.py index d6e6504..955ac64 100644 --- a/mensa.py +++ b/mensa.py @@ -5,9 +5,8 @@ import requests DISABLED_GROUPS = [-1001301570558] DIETS = { - "veggy": "fleischlos", - "fleisch": "mit Fleisch", - "fisch": "mit Fisch/Meeresfrüchten" + "veggy": ["Vegetarisch", "Vegan"], + "vegan": ["Vegan"] } WEEKDAYS = { @@ -74,6 +73,7 @@ def mensa(bot, update, args): return which = "zentral" filter_categories = MODES["light"] + diet = [""] auto_next_day = True today = datetime.datetime.now().date() @@ -87,8 +87,8 @@ def mensa(bot, update, args): date_offset = (6 - today.weekday() + WEEKDAYS[arg]) today += datetime.timedelta(days=date_offset) auto_next_day = False - # elif arg in DIETS: - # diet = DIETS[arg] + elif arg in DIETS: + diet = DIETS[arg] else: update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.") return @@ -111,9 +111,14 @@ def mensa(bot, update, args): else: 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: - meal_line = "*%s*\n" % cat['name'] - for meal in cat['meals']: + 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' @@ -121,6 +126,6 @@ def mensa(bot, update, args): def get_data_for_day(day, complete_data): - for date in complete_data['days']: - if day.isoformat() == date['iso-date']: - return date + for data in complete_data['days']: + if day.isoformat() == data['iso-date']: + return data diff --git a/schneiderbot.py b/schneiderbot.py index dd113b5..f125ac6 100755 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -1,15 +1,17 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from telegram.ext import Updater, CommandHandler, MessageHandler, Filters -from telegram import ParseMode -from db import Db -from mensa import mensa -from coding_love import send_coding_love_gif import logging import random -import requests + import pydog +import requests +from telegram import ParseMode +from telegram.ext import Updater, CommandHandler + +from coding_love import send_coding_love_gif +from db import Db +from mensa import mensa # Enable logging