mirror of
https://github.com/traberph/mensa-check.git
synced 2026-10-06 10:14:46 +00:00
init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*.*.*' # Trigger on version tags
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Docker Registry
|
||||
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
|
||||
|
||||
- name: Extract repo name
|
||||
id: repo
|
||||
run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV
|
||||
|
||||
- name: Set image tags
|
||||
id: tags
|
||||
run: |
|
||||
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
TAG="${GITHUB_SHA::7}" # Short SHA for non-tag builds
|
||||
fi
|
||||
echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV
|
||||
echo "IMAGE_TAG_LATEST=latest" >> $GITHUB_ENV
|
||||
|
||||
- name: Build Docker image
|
||||
run: docker build -t ${{ secrets.REGISTRY_URL }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} .
|
||||
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
docker push ${{ secrets.REGISTRY_URL }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}
|
||||
docker tag ${{ secrets.REGISTRY_URL }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} ${{ secrets.REGISTRY_URL }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG_LATEST }}
|
||||
docker push ${{ secrets.REGISTRY_URL }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG_LATEST }}
|
||||
|
||||
- name: Logout of Docker Registry
|
||||
run: docker logout ${{ secrets.REGISTRY_URL }}
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM python:3
|
||||
WORKDIR /app
|
||||
COPY requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY src/ .
|
||||
CMD [ "fastapi", "run", "api.py" ]
|
||||
@@ -0,0 +1,17 @@
|
||||
# Spätzle check
|
||||
|
||||
Me and my colleges have been eating in the Mensa at our university for a while now. If spätzle are on the menu it was always a gamble if they are good or really bad. Until somebody told us the problem of the bad spätzle is that they are vegan (no hate against vegan products but some products just shouldn't be vegan).
|
||||
|
||||
|
||||
Because of the lack of eggs the spätzle are not sticking together and are just a big pile of mush.
|
||||
|
||||
Using the allergen information on the mensa website we can check if the spätzle are vegan or not and therefore can decide if one can eat them or not.
|
||||
|
||||
This project serves a simple [website](spaetzle.traberph.de) that checks the spätzle for you.
|
||||
|
||||
## How to run
|
||||
Simply run it with docker-compose
|
||||
|
||||
```
|
||||
docker-compose up
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
@@ -0,0 +1,4 @@
|
||||
fastapi[standard]==0.114.0
|
||||
Jinja2==3.1.4
|
||||
requests==2.32.3
|
||||
cachetools==5.5.0
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
import requests
|
||||
from cachetools import cached, TTLCache
|
||||
|
||||
cache = TTLCache(maxsize=1, ttl=3600)
|
||||
app = FastAPI()
|
||||
templates = Jinja2Templates(directory="template")
|
||||
|
||||
@cached(cache)
|
||||
def checkMensa():
|
||||
print("Checking Mensa")
|
||||
url = 'https://seezeit.com/essen/speiseplaene/mensa-giessberg/'
|
||||
r = requests.get(url)
|
||||
text = r.text
|
||||
pos = text.find('Spätzle')
|
||||
if pos != -1:
|
||||
cut = r.text[r.text.find('Spätzle'):r.text.find('Spätzle')+50]
|
||||
ingredients = cut.split('(')[1].split(')')[0].split(',')
|
||||
if '28' in ingredients:
|
||||
answer = "Spätzle with egg today"
|
||||
color = "green"
|
||||
emoji = "✅"
|
||||
else:
|
||||
answer = "WARNING: Spätzle without egg today"
|
||||
color = "red"
|
||||
emoji = "❌"
|
||||
else:
|
||||
answer = "No Spätzle today "
|
||||
color = "grey"
|
||||
emoji = "🤷🏻♂️"
|
||||
|
||||
return answer, color, emoji
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def root(request: Request):
|
||||
answer, color, emoji = checkMensa()
|
||||
return templates.TemplateResponse(
|
||||
request=request, name="main.html", context={"text": answer, "color": color , "emoji": emoji}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
|
||||
<title>{{text}} - {{emoji}}</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: {{ color}};
|
||||
color: #f0f0f0;
|
||||
font-family: Roboto,
|
||||
sans-serif;
|
||||
font-weight: 300;
|
||||
margin: 0;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1,
|
||||
div {
|
||||
font-size: 4vh;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
max-width: 1000px;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background-color: #333;
|
||||
color: #f0f0f0;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
span {
|
||||
background-color: salmon;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
border-radius: 5px;
|
||||
color: white;
|
||||
}
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>👮</h1>
|
||||
<h1 style="margin-bottom: 30px;">Spätzle Check:</h1>
|
||||
<div>
|
||||
{{ text }}
|
||||
</div>
|
||||
<div>{{emoji}}</div>
|
||||
|
||||
<footer>
|
||||
<p>Powered by:
|
||||
<a href="https://kubernetes.io/de/"><span>k8s</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://seezeit.com/essen/speiseplaene/mensa-giessberg/"><span>seezeit</span></a></p>
|
||||
<p>Imprint: <a href="https://github.com/traberph">Philipp Traber</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user