mirror of
https://github.com/traberph/mensa-check.git
synced 2026-10-06 10:14:46 +00:00
enforce formatting
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Run Ruff
|
||||||
|
run: |
|
||||||
|
pip install ruff
|
||||||
|
ruff format --check
|
||||||
|
ruff check
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[lint]
|
||||||
|
extend-select = ["I"]
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "charliermarsh.ruff"
|
||||||
|
}
|
||||||
+23
-19
@@ -1,33 +1,32 @@
|
|||||||
from fastapi import FastAPI
|
|
||||||
from fastapi import FastAPI, Request
|
|
||||||
from fastapi.responses import HTMLResponse
|
|
||||||
from fastapi.responses import FileResponse
|
|
||||||
from fastapi.templating import Jinja2Templates
|
|
||||||
from cachetools import cached, TTLCache
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
import requests
|
|
||||||
import re
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from cachetools import TTLCache, cached
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
|
from fastapi.responses import FileResponse, HTMLResponse
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn.error")
|
logger = logging.getLogger("uvicorn.error")
|
||||||
|
|
||||||
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>', re.IGNORECASE)
|
regex = re.compile(r"spätzle <sup>([^/]*)</sup>", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
@cached(cache)
|
@cached(cache)
|
||||||
def checkMensa():
|
def checkMensa():
|
||||||
logger.info("Checking Mensa")
|
logger.info("Checking Mensa")
|
||||||
|
|
||||||
try:
|
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")
|
||||||
|
|
||||||
today = soup.find('a', class_='heute')['rel'][0]
|
today = soup.find("a", class_="heute")["rel"][0]
|
||||||
today_menu = soup.find('div', id=f'tab{today}')
|
today_menu = soup.find("div", id=f"tab{today}")
|
||||||
meals = today_menu.find_all('div', class_='title')
|
meals = today_menu.find_all("div", class_="title")
|
||||||
|
|
||||||
spaetzle = None
|
spaetzle = None
|
||||||
for m in meals:
|
for m in meals:
|
||||||
@@ -37,7 +36,7 @@ def checkMensa():
|
|||||||
|
|
||||||
if spaetzle is not None:
|
if spaetzle is not None:
|
||||||
ingredients = re.search(regex, str(spaetzle)).group(1)
|
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 = "✅"
|
||||||
@@ -50,7 +49,7 @@ def checkMensa():
|
|||||||
answer = "No Spätzle today "
|
answer = "No Spätzle today "
|
||||||
color = "grey"
|
color = "grey"
|
||||||
emoji = "🤷"
|
emoji = "🤷"
|
||||||
except Exception as e:
|
except Exception:
|
||||||
answer = "No menu today"
|
answer = "No menu today"
|
||||||
color = "grey"
|
color = "grey"
|
||||||
emoji = "⛱️"
|
emoji = "⛱️"
|
||||||
@@ -58,17 +57,22 @@ def checkMensa():
|
|||||||
logger.info(f"Answer: {answer}, Color: {color}, Emoji: {emoji}")
|
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)
|
||||||
async def root(request: Request):
|
async def root(request: Request):
|
||||||
answer, color, emoji = checkMensa()
|
answer, color, emoji = checkMensa()
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
request=request, name="main.html", context={"text": answer, "color": color , "emoji": emoji}
|
request=request,
|
||||||
|
name="main.html",
|
||||||
|
context={"text": answer, "color": color, "emoji": emoji},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/manifest.json")
|
@app.get("/manifest.json")
|
||||||
async def manifest(request: Request):
|
async def manifest(request: Request):
|
||||||
return FileResponse(path="assets/manifest.json")
|
return FileResponse(path="assets/manifest.json")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/icons/512.png")
|
@app.get("/icons/512.png")
|
||||||
async def icon(request: Request):
|
async def icon(request: Request):
|
||||||
return FileResponse(path="assets/logo.png")
|
return FileResponse(path="assets/logo.png")
|
||||||
|
|||||||
Reference in New Issue
Block a user