Browse Source

added filtering

master
angerstoner 7 years ago
parent
commit
9c80bf8634
  1. 94
      schneiderbot.py

94
schneiderbot.py

@ -13,12 +13,82 @@ MENSA_URL = {
"nord": "nordmensa", "nord": "nordmensa",
"turm": "turmmensa" "turm": "turmmensa"
} }
MENSA_NAME = { MENSA_NAME = {
"zentral": "Zentralmensa", "zentral": "Zentralmensa",
"nord": "Nordmensa", "nord": "Nordmensa",
"turm": "Turmmensa" "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 # 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)
@ -56,8 +126,13 @@ def manta(bot, update):
def mensa(bot, update, args): def mensa(bot, update, args):
which = "zentral" 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: if which not in MENSA_NAME:
update.message.reply_text("Diese Mensa gibt es nicht! RTFM und versuchs nochmal.") 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: if len(data["meals"]) > 0:
for meal in data["meals"]: 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 # 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) update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN)
else: else:
update.message.reply_text("Nix zu futtern heute :(") update.message.reply_text("Nix zu futtern heute :(")

Loading…
Cancel
Save