mirror of
https://github.com/traberph/mensa-check.git
synced 2026-10-06 18:24:45 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72266fe2e8 | ||
|
|
4f4ec345fb |
@@ -0,0 +1 @@
|
|||||||
|
.venv
|
||||||
@@ -2,3 +2,4 @@ fastapi[standard]==0.114.0
|
|||||||
Jinja2==3.1.4
|
Jinja2==3.1.4
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
cachetools==5.5.0
|
cachetools==5.5.0
|
||||||
|
beautifulsoup4==4.12.3
|
||||||
+21
-6
@@ -2,27 +2,42 @@ from fastapi import FastAPI
|
|||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
import requests
|
|
||||||
from cachetools import cached, TTLCache
|
from cachetools import cached, TTLCache
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
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():
|
||||||
print("Checking Mensa")
|
print("Checking Mensa")
|
||||||
|
|
||||||
url = 'https://seezeit.com/essen/speiseplaene/mensa-giessberg/'
|
url = 'https://seezeit.com/essen/speiseplaene/mensa-giessberg/'
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
text = r.text
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
pos = text.find('Spätzle')
|
|
||||||
if pos != -1:
|
today = soup.find('a', class_='heute')['rel'][0]
|
||||||
cut = r.text[r.text.find('Spätzle'):r.text.find('Spätzle')+50]
|
today_menu = soup.find('div', id=f'tab{today}')
|
||||||
ingredients = cut.split('(')[1].split(')')[0].split(',')
|
meals = today_menu.find_all('div', class_='title')
|
||||||
|
|
||||||
|
spaetzle = None
|
||||||
|
for m in meals:
|
||||||
|
if "Spätzle" in m.text:
|
||||||
|
spaetzle = m
|
||||||
|
break
|
||||||
|
|
||||||
|
if spaetzle is not None:
|
||||||
|
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"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<title>{{text}} - {{emoji}}</title>
|
<title>{{text}} - {{emoji}}</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: {{ color}};
|
background-color: {{ color }};
|
||||||
color: #f0f0f0;
|
color: #f0f0f0;
|
||||||
font-family: Roboto,
|
font-family: Roboto,
|
||||||
sans-serif;
|
sans-serif;
|
||||||
@@ -40,7 +40,9 @@
|
|||||||
color: #f0f0f0;
|
color: #f0f0f0;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
font-size: smaller;
|
||||||
}
|
}
|
||||||
|
|
||||||
span {
|
span {
|
||||||
background-color: salmon;
|
background-color: salmon;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
@@ -48,6 +50,7 @@
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: white;
|
color: white;
|
||||||
@@ -68,8 +71,10 @@
|
|||||||
<a href="https://kubernetes.io/de/"><span>k8s</span></a>
|
<a href="https://kubernetes.io/de/"><span>k8s</span></a>
|
||||||
<a href="https://fastapi.tiangolo.com/"><span>fastapi</span></a>
|
<a href="https://fastapi.tiangolo.com/"><span>fastapi</span></a>
|
||||||
<a href="https://github.com/traberph/mensa-check"><span>github</span></a>
|
<a href="https://github.com/traberph/mensa-check"><span>github</span></a>
|
||||||
<a href="https://seezeit.com/essen/speiseplaene/mensa-giessberg/"><span>seezeit</span></a></p>
|
<a href="https://seezeit.com/essen/speiseplaene/mensa-giessberg/"><span>seezeit</span></a>
|
||||||
<p>Imprint: <a href="https://github.com/traberph">Philipp Traber</a></p>
|
</p>
|
||||||
|
<p>Imprint: <a href="https://github.com/traberph">Philipp Traber</a>; Legal Notice: Not associated with seezeit
|
||||||
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user