From 9c80bf8634bcdbc431edecaea95ea93e1c3409e2 Mon Sep 17 00:00:00 2001 From: angerstoner Date: Sat, 31 Mar 2018 00:50:47 +0200 Subject: [PATCH] added filtering --- schneiderbot.py | 94 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/schneiderbot.py b/schneiderbot.py index 4f2f623..1118296 100644 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -13,12 +13,82 @@ MENSA_URL = { "nord": "nordmensa", "turm": "turmmensa" } + MENSA_NAME = { "zentral": "Zentralmensa", "nord": "Nordmensa", "turm": "Turmmensa" } +## TODO: rather use filter list, this is bloated; mensa italia missing +CATEGORIES_LIGHT = { + "Eintopf", + "Menü I", + "Menü II", + "Vegan", + "Vegetarisch", + "Grill III", + "Al dente", + "Pasta und Gratins", + "Kartoffeln und Co.", + ## Nordmensa: + "Stamm 1 vegetarisch", + "Nordmensa-Fit", + "Stamm 2", + "Stamm 3", + ## Turmmensa: + "Turm vegetarisch Kombi", + "Turm 2b", + "Turm 3a", + "Turm Vegan", + "Regionale Linie" +} + +CATEGORIES_FULL = { + "Eintopf", + "Menü I", + "Menü II", + "Vegan", + "Vegetarisch", + "Grill III", + "CampusCurry", + "natürlich fit", + "Al dente", + "Pasta und Gratins", + "Fitnesscenter", + "Salatbuffet", + "Studentenfutter", + "Süße Versuchung", + "Süße Spezial Tagesangebot", + "Kartoffeln und Co.", + "Vollwert & Co. Stärke", + "Vollwert & Co. Gemüse", + "Bio-Beilagen", + "Dessertbuffet", + "Last Minute ab 14:30 Uhr", + ## Nordmensa: + "Stamm 1 vegetarisch", + "Nordmensa-Fit", + "Stamm 2", + "Stamm 3", + "Salatbuffet/Pastapoint", + "Last Minute ab 13:30 Uhr", + ## Turmmensa: + "Turm vegetarisch Kombi", + "Turm 2b", + "Turm 3a", + "Turm Vegan", + "Regionale Linie", + "Beilagen", + "Last Minute ab 14:00Uhr" +} + +MODES = { + "light" : CATEGORIES_LIGHT, + "full" : CATEGORIES_FULL +} + + # Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) @@ -56,8 +126,13 @@ def manta(bot, update): def mensa(bot, update, args): which = "zentral" - if len(args): - which = args[0] + categories = CATEGORIES_LIGHT + for arg in args: + if arg in MENSA_NAME: + which = args[0] + elif arg in MODES: + categories = MODES[arg] + if which not in MENSA_NAME: update.message.reply_text("Diese Mensa gibt es nicht! RTFM und versuchs nochmal.") @@ -80,15 +155,16 @@ def mensa(bot, update, args): if len(data["meals"]) > 0: for meal in data["meals"]: - meal_line = "*%s*\n" % meal["category"] - meal_line += meal["title"].strip() + "\n" + if meal["category"] in categories: + meal_line = "*%s*\n" % meal["category"] + meal_line += meal["title"].strip() + "\n" # Discord only allows up to 2000 chars per message - if len(message) + len(meal_line) > 2000: - update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN) - message = meal_line + "\n" - else: - message += meal_line + "\n" + if len(message) + len(meal_line) > 2000: + update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN) + message = meal_line + "\n" + else: + message += meal_line + "\n" update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN) else: update.message.reply_text("Nix zu futtern heute :(")