From cff984b341703dc7735fb8a0ff8ca9b0fd147c50 Mon Sep 17 00:00:00 2001 From: angerstoner Date: Sat, 7 Apr 2018 00:26:30 +0200 Subject: [PATCH] added day specific mensa commands --- schneiderbot.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/schneiderbot.py b/schneiderbot.py index a170fbf..10fc885 100644 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -11,6 +11,15 @@ import datetime import cat import pydog +WEEKDAYS = { + "montag" : 1, + "dienstag" : 2, + "mittwoch" : 3, + "donnerstag" : 4, + "freitag" : 5, + "samstag" : 6 +} + MENSA_URL = { "zentral": "zentralmensa", "nord": "nordmensa", @@ -131,22 +140,25 @@ def shrug(bot, update): def mensa(bot, update, args): which = "zentral" filter_categories = MODES["light"] + + today = datetime.datetime.now().date().weekday() + 1 + if datetime.datetime.now().time() > datetime.time(hour=16): + # Es ist zu spät am Tag, zeig das essen für morgen an + today += 1 + + today = today % 7 + for arg in args: if arg in MENSA_NAME: which = args[0] elif arg in MODES: filter_categories = MODES[arg] + elif arg in WEEKDAYS: + today = WEEKDAYS[arg] else: update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.") return - - today = datetime.datetime.now().date().weekday() + 1 - if datetime.datetime.now().time() > datetime.time(hour=16): - # Es ist zu spät am Tag, zeig das essen für morgen an - today += 1 - - today = today % 7 - + url = "https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today) request = requests.get(url) request.encoding = 'utf-8'