From 21988f52adbcb22ddc03fa289a863af9afb6f168 Mon Sep 17 00:00:00 2001 From: angerstoner Date: Sun, 8 Apr 2018 13:01:56 +0200 Subject: [PATCH] fixed day 0 bug; reformatted --- schneiderbot.py | 129 ++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/schneiderbot.py b/schneiderbot.py index 7ec59ea..a6b57b0 100644 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -12,68 +12,68 @@ import cat import pydog DIETS = { - "veggy" : "fleischlos", - "fleisch" : "mit Fleisch", - "fisch" : "mit Fisch/ Meeresfrüchten" -} + "veggy" : "fleischlos", + "fleisch" : "mit Fleisch", + "fisch" : "mit Fisch/ Meeresfrüchten" + } WEEKDAYS = { - "montag" : 1, - "dienstag" : 2, - "mittwoch" : 3, - "donnerstag" : 4, - "freitag" : 5, - "samstag" : 6 -} + "montag" : 1, + "dienstag" : 2, + "mittwoch" : 3, + "donnerstag" : 4, + "freitag" : 5, + "samstag" : 6 + } MENSA_URL = { - "zentral": "zentralmensa", - "nord": "nordmensa", - "turm": "turmmensa" -} + "zentral": "zentralmensa", + "nord": "nordmensa", + "turm": "turmmensa" + } MENSA_NAME = { - "zentral": "Zentralmensa", - "nord": "Nordmensa", - "turm": "Turmmensa" -} + "zentral": "Zentralmensa", + "nord": "Nordmensa", + "turm": "Turmmensa" + } HIDE_CATEGORIES_LIGHT = { - "CampusCurry", - "natürlich fit", - "Fitnesscenter", - "Salatbuffet", - "Studentenfutter", - "Süße Versuchung", - "Süße Spezial Tagesangebot", - "Vollwert & Co. Stärke", - "Vollwert & Co. Gemüse", - "Bio-Beilagen", - "Dessertbuffet", - "Last Minute ab 14:30 Uhr", - ## Nordmensa: - "Salatbuffet/Pastapoint", - "Last Minute ab 13:30 Uhr", - ## Turmmensa: - "Beilagen", - "Last Minute ab 14:00Uhr" -} + "CampusCurry", + "natürlich fit", + "Fitnesscenter", + "Salatbuffet", + "Studentenfutter", + "Süße Versuchung", + "Süße Spezial Tagesangebot", + "Vollwert & Co. Stärke", + "Vollwert & Co. Gemüse", + "Bio-Beilagen", + "Dessertbuffet", + "Last Minute ab 14:30 Uhr", + ## Nordmensa: + "Salatbuffet/Pastapoint", + "Last Minute ab 13:30 Uhr", + ## Turmmensa: + "Beilagen", + "Last Minute ab 14:00Uhr" + } HIDE_CATEGORIES_FULL = { - "Last Minute ab 14:30 Uhr", - "Last Minute ab 13:30 Uhr", - "Last Minute ab 14:00Uhr" -} + "Last Minute ab 14:30 Uhr", + "Last Minute ab 13:30 Uhr", + "Last Minute ab 14:00Uhr" + } MODES = { - "light" : HIDE_CATEGORIES_LIGHT, - "full" : HIDE_CATEGORIES_FULL -} + "light" : HIDE_CATEGORIES_LIGHT, + "full" : HIDE_CATEGORIES_FULL + } # Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.INFO) + level=logging.INFO) logger = logging.getLogger(__name__) @@ -88,24 +88,24 @@ with open("manta.txt", "r") as tmp_file: def start(bot, update): """Was ist das hier für eins Bot?""" update.message.reply_text("""Hallo, ich bin ein Bot. -Ich liefere tolle Informationen über die Mensa. Die Infos kommen von -https://mensa.schneider-hosting.de -Mhmm, lecker. Guten Appetit!""") + Ich liefere tolle Informationen über die Mensa. Die Infos kommen von + https://mensa.schneider-hosting.de + Mhmm, lecker. Guten Appetit!""") def help(bot, update): """Send a message when the command /help is issued.""" update.message.reply_text("""Commands: -*Mensa*: -/mensa _mensa_ - prints filtered list of meals for _mensa_ (if no _mensa_ given, zentralmensa is used) -/mensa _mensa_ full - prints full list of meals for _mensa_ (if no _mensa_ given, zentralmensa is used) - -*Fun*: -/cat - random cat (using thecatapi.com) -/dog - random dog (https://dog.ceo/dog-api) -/magie - random Axel Stoll qoute -/manta - random Opel Manta joke - -/help - this help text""", parse_mode=ParseMode.MARKDOWN) + *Mensa*: + /mensa _mensa_ - prints filtered list of meals for _mensa_ (if no _mensa_ given, zentralmensa is used) + /mensa _mensa_ full - prints full list of meals for _mensa_ (if no _mensa_ given, zentralmensa is used) + + *Fun*: + /cat - random cat (using thecatapi.com) + /dog - random dog (https://dog.ceo/dog-api) + /magie - random Axel Stoll qoute + /manta - random Opel Manta joke + + /help - this help text""", parse_mode=ParseMode.MARKDOWN) def sendCat(bot, update): """CUTE""" @@ -152,10 +152,9 @@ def mensa(bot, update, args): today += 1 today = today % 7 - for arg in args: if arg in MENSA_NAME: - which = args[0] + which = arg elif arg in MODES: filter_categories = MODES[arg] elif arg in WEEKDAYS: @@ -165,14 +164,16 @@ def mensa(bot, update, args): else: update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.") return - + if today == 0: + update.message.reply_text("Sonntags hat die Mensa zu") + return url = "https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today) request = requests.get(url) request.encoding = 'utf-8' data = request.json() message = "Das Essen für %s in der %s \n\n" % (data["date"], MENSA_NAME[which]) - + if len(data["meals"]) > 1: for meal in data["meals"]: if meal["category"] not in filter_categories and diet in meal["diet"]: