Browse Source

fixed day 0 bug; reformatted

pull/1/head
angerstoner 7 years ago
parent
commit
21988f52ad
  1. 45
      schneiderbot.py

45
schneiderbot.py

@ -15,7 +15,7 @@ DIETS = {
"veggy" : "fleischlos", "veggy" : "fleischlos",
"fleisch" : "mit Fleisch", "fleisch" : "mit Fleisch",
"fisch" : "mit Fisch/ Meeresfrüchten" "fisch" : "mit Fisch/ Meeresfrüchten"
}
}
WEEKDAYS = { WEEKDAYS = {
"montag" : 1, "montag" : 1,
@ -24,19 +24,19 @@ WEEKDAYS = {
"donnerstag" : 4, "donnerstag" : 4,
"freitag" : 5, "freitag" : 5,
"samstag" : 6 "samstag" : 6
}
}
MENSA_URL = { MENSA_URL = {
"zentral": "zentralmensa", "zentral": "zentralmensa",
"nord": "nordmensa", "nord": "nordmensa",
"turm": "turmmensa" "turm": "turmmensa"
}
}
MENSA_NAME = { MENSA_NAME = {
"zentral": "Zentralmensa", "zentral": "Zentralmensa",
"nord": "Nordmensa", "nord": "Nordmensa",
"turm": "Turmmensa" "turm": "Turmmensa"
}
}
HIDE_CATEGORIES_LIGHT = { HIDE_CATEGORIES_LIGHT = {
"CampusCurry", "CampusCurry",
@ -57,18 +57,18 @@ HIDE_CATEGORIES_LIGHT = {
## Turmmensa: ## Turmmensa:
"Beilagen", "Beilagen",
"Last Minute ab 14:00Uhr" "Last Minute ab 14:00Uhr"
}
}
HIDE_CATEGORIES_FULL = { HIDE_CATEGORIES_FULL = {
"Last Minute ab 14:30 Uhr", "Last Minute ab 14:30 Uhr",
"Last Minute ab 13:30 Uhr", "Last Minute ab 13:30 Uhr",
"Last Minute ab 14:00Uhr" "Last Minute ab 14:00Uhr"
}
}
MODES = { MODES = {
"light" : HIDE_CATEGORIES_LIGHT, "light" : HIDE_CATEGORIES_LIGHT,
"full" : HIDE_CATEGORIES_FULL "full" : HIDE_CATEGORIES_FULL
}
}
# Enable logging # Enable logging
@ -88,24 +88,24 @@ with open("manta.txt", "r") as tmp_file:
def start(bot, update): def start(bot, update):
"""Was ist das hier für eins Bot?""" """Was ist das hier für eins Bot?"""
update.message.reply_text("""Hallo, ich bin ein 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): def help(bot, update):
"""Send a message when the command /help is issued.""" """Send a message when the command /help is issued."""
update.message.reply_text("""Commands: 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)
*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
*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)
/help - this help text""", parse_mode=ParseMode.MARKDOWN)
def sendCat(bot, update): def sendCat(bot, update):
"""CUTE""" """CUTE"""
@ -152,10 +152,9 @@ def mensa(bot, update, args):
today += 1 today += 1
today = today % 7 today = today % 7
for arg in args: for arg in args:
if arg in MENSA_NAME: if arg in MENSA_NAME:
which = args[0]
which = arg
elif arg in MODES: elif arg in MODES:
filter_categories = MODES[arg] filter_categories = MODES[arg]
elif arg in WEEKDAYS: elif arg in WEEKDAYS:
@ -165,7 +164,9 @@ def mensa(bot, update, args):
else: else:
update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.") update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
return 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) url = "https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today)
request = requests.get(url) request = requests.get(url)
request.encoding = 'utf-8' request.encoding = 'utf-8'

Loading…
Cancel
Save