Browse Source

fixed day 0 bug; reformatted

quotes
angerstoner 7 years ago
parent
commit
21988f52ad
  1. 123
      schneiderbot.py

123
schneiderbot.py

@ -12,68 +12,68 @@ import cat
import pydog import pydog
DIETS = { DIETS = {
"veggy" : "fleischlos",
"fleisch" : "mit Fleisch",
"fisch" : "mit Fisch/ Meeresfrüchten"
}
"veggy" : "fleischlos",
"fleisch" : "mit Fleisch",
"fisch" : "mit Fisch/ Meeresfrüchten"
}
WEEKDAYS = { 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 = { MENSA_URL = {
"zentral": "zentralmensa",
"nord": "nordmensa",
"turm": "turmmensa"
}
"zentral": "zentralmensa",
"nord": "nordmensa",
"turm": "turmmensa"
}
MENSA_NAME = { MENSA_NAME = {
"zentral": "Zentralmensa",
"nord": "Nordmensa",
"turm": "Turmmensa"
}
"zentral": "Zentralmensa",
"nord": "Nordmensa",
"turm": "Turmmensa"
}
HIDE_CATEGORIES_LIGHT = { 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 = { 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 = { MODES = {
"light" : HIDE_CATEGORIES_LIGHT,
"full" : HIDE_CATEGORIES_FULL
}
"light" : HIDE_CATEGORIES_LIGHT,
"full" : HIDE_CATEGORIES_FULL
}
# Enable logging # Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -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