1 Commits
Author SHA1 Message Date
Philipp Traber 72266fe2e8 check the right ingredients 2024-10-08 13:52:55 +02:00
+4 -1
View File
@@ -5,11 +5,13 @@ from fastapi.templating import Jinja2Templates
from cachetools import cached, TTLCache from cachetools import cached, TTLCache
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests import requests
import re
cache = TTLCache(maxsize=1, ttl=3600) cache = TTLCache(maxsize=1, ttl=3600)
app = FastAPI() app = FastAPI()
templates = Jinja2Templates(directory="template") templates = Jinja2Templates(directory="template")
regex = re.compile(r'Spätzle <sup>([^/]*)<\/sup>')
@cached(cache) @cached(cache)
def checkMensa(): def checkMensa():
@@ -30,11 +32,12 @@ def checkMensa():
break break
if spaetzle is not None: if spaetzle is not None:
ingredients = spaetzle.find('sup').text ingredients = re.search(regex, str(spaetzle)).group(1)
if '28' in ingredients: if '28' in ingredients:
answer = "Spätzle with egg today" answer = "Spätzle with egg today"
color = "green" color = "green"
emoji = "✅" emoji = "✅"
else: else:
answer = "WARNING: Spätzle without egg today" answer = "WARNING: Spätzle without egg today"
color = "red" color = "red"