mirror of
https://github.com/traberph/mensa-check.git
synced 2026-10-06 10:14:46 +00:00
error handling
This commit is contained in:
+10
-2
@@ -7,7 +7,9 @@ from cachetools import cached, TTLCache
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger("uvicorn.error")
|
||||||
|
|
||||||
cache = TTLCache(maxsize=1, ttl=3600)
|
cache = TTLCache(maxsize=1, ttl=3600)
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@@ -16,8 +18,9 @@ regex = re.compile(r'spätzle <sup>([^/]*)</sup>', re.IGNORECASE)
|
|||||||
|
|
||||||
@cached(cache)
|
@cached(cache)
|
||||||
def checkMensa():
|
def checkMensa():
|
||||||
print("Checking Mensa")
|
logger.info("Checking Mensa")
|
||||||
|
|
||||||
|
try:
|
||||||
url = 'https://seezeit.com/essen/speiseplaene/mensa-giessberg/'
|
url = 'https://seezeit.com/essen/speiseplaene/mensa-giessberg/'
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
soup = BeautifulSoup(r.text, 'html.parser')
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
@@ -47,7 +50,12 @@ def checkMensa():
|
|||||||
answer = "No Spätzle today "
|
answer = "No Spätzle today "
|
||||||
color = "grey"
|
color = "grey"
|
||||||
emoji = "🤷"
|
emoji = "🤷"
|
||||||
|
except Exception as e:
|
||||||
|
answer = "No menu today"
|
||||||
|
color = "grey"
|
||||||
|
emoji = "⛱️"
|
||||||
|
finally:
|
||||||
|
logger.info(f"Answer: {answer}, Color: {color}, Emoji: {emoji}")
|
||||||
return answer, color, emoji
|
return answer, color, emoji
|
||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
|
|||||||
Reference in New Issue
Block a user