Browse Source

fixed filtering by diet

master
Angerstoner 6 years ago
parent
commit
0c8b0c15eb
  1. 27
      mensa.py
  2. 14
      schneiderbot.py

27
mensa.py

@ -5,9 +5,8 @@ import requests
DISABLED_GROUPS = [-1001301570558]
DIETS = {
"veggy": "fleischlos",
"fleisch": "mit Fleisch",
"fisch": "mit Fisch/Meeresfrüchten"
"veggy": ["Vegetarisch", "Vegan"],
"vegan": ["Vegan"]
}
WEEKDAYS = {
@ -74,6 +73,7 @@ def mensa(bot, update, args):
return
which = "zentral"
filter_categories = MODES["light"]
diet = [""]
auto_next_day = True
today = datetime.datetime.now().date()
@ -87,8 +87,8 @@ def mensa(bot, update, args):
date_offset = (6 - today.weekday() + WEEKDAYS[arg])
today += datetime.timedelta(days=date_offset)
auto_next_day = False
# elif arg in DIETS:
# diet = DIETS[arg]
elif arg in DIETS:
diet = DIETS[arg]
else:
update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
return
@ -111,9 +111,14 @@ def mensa(bot, update, args):
else:
message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
for cat in today_data['categories']:
if cat['name'] not in filter_categories:
meal_line = "*%s*\n" % cat['name']
for meal in cat['meals']:
label = cat['name']
meals = cat['meals']
if label not in filter_categories and (
any(filtered in label for filtered in diet) or
[item['name'].replace('\xad', '') for item in meals if
any(filtered in item['name'].replace('\xad', '') for filtered in diet)]): # TODO: simplify
meal_line = "*%s*\n" % label
for meal in meals:
meal_line += meal['name'].strip() + "\n"
message += meal_line + '\n'
@ -121,6 +126,6 @@ def mensa(bot, update, args):
def get_data_for_day(day, complete_data):
for date in complete_data['days']:
if day.isoformat() == date['iso-date']:
return date
for data in complete_data['days']:
if day.isoformat() == data['iso-date']:
return data

14
schneiderbot.py

@ -1,15 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import ParseMode
from db import Db
from mensa import mensa
from coding_love import send_coding_love_gif
import logging
import random
import requests
import pydog
import requests
from telegram import ParseMode
from telegram.ext import Updater, CommandHandler
from coding_love import send_coding_love_gif
from db import Db
from mensa import mensa
# Enable logging

Loading…
Cancel
Save