11 Commits
0.0.1 ... 0.0.8

Author SHA1 Message Date
5948cf3840 postgres, fix 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:48:31 +01:00
63dbfcc89f postgres, fix 2 2024-01-30 14:47:36 +01:00
439f6085e7 postgres 2024-01-30 14:47:07 +01:00
21479212f8 fix 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:18:52 +01:00
5d8997d45e fix 2024-01-30 14:16:59 +01:00
6e6effb1bc fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:07:42 +01:00
00d48b4de1 roles
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:00:41 +01:00
fc9cd70776 Merge branch 'main' of gitea.hottis.de:moerp/elo-rezept-rechner 2024-01-30 13:59:13 +01:00
8b9654370c roles 2024-01-30 13:59:02 +01:00
4471c140c1 placeholder 2024-01-30 13:53:30 +01:00
e87675dcbd fix namespace
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 13:41:59 +01:00
5 changed files with 52 additions and 100 deletions

View File

@ -6,8 +6,8 @@ if [ "$IMAGE_TAG" == "" ]; then
fi fi
IMAGE_NAME=gitea.hottis.de/wn/oidc-python-example IMAGE_NAME=gitea.hottis.de/moerp/elo-rezept-rechner
NAMESPACE=oidc-python-example NAMESPACE=moerp
DEPLOYMENT_DIR=$PWD/deployment DEPLOYMENT_DIR=$PWD/deployment
pushd $DEPLOYMENT_DIR > /dev/null pushd $DEPLOYMENT_DIR > /dev/null
@ -22,7 +22,7 @@ kubectl create namespace $NAMESPACE \
-o yaml | \ -o yaml | \
kubectl -f - apply kubectl -f - apply
kubectl create secret generic secrets \ kubectl create secret generic nutri-secrets \
--dry-run=client \ --dry-run=client \
-o yaml \ -o yaml \
--save-config \ --save-config \

View File

@ -4,6 +4,7 @@ from flask_oidc import OpenIDConnect
from werkzeug.middleware.proxy_fix import ProxyFix from werkzeug.middleware.proxy_fix import ProxyFix
import os import os
import json import json
import psycopg2
app = Flask(__name__) app = Flask(__name__)
app.config.update({ app.config.update({
@ -19,76 +20,35 @@ app.config.update({
oidc = OpenIDConnect(app) oidc = OpenIDConnect(app)
# Datenbankverbindung konfigurieren
def get_db_connection():
conn = sqlite3.connect('nutrition.db') # 'nutrition.db' ist der Name der Datenbankdatei
conn.row_factory = sqlite3.Row # Ermöglicht den Zugriff auf Daten durch Spaltennamen
return conn
#def init_db():
# conn = get_db_connection()
# cursor = conn.cursor()
#
# # Erstellen der Tabelle
# cursor.execute('''
# CREATE TABLE IF NOT EXISTS nutrition_table (
# id INTEGER PRIMARY KEY,
# name TEXT NOT NULL,
# kcal REAL,
# EW REAL,
# Fett REAL,
# KH REAL,
# BST REAL,
# CA REAL
# )
# ''')
#
# # Testdaten einfügen
# test_data = [
# ('Apfel', 52, 0.3, 0.2, 14, 0.2, 6),
# ('Banane', 89, 1.1, 0.3, 23, 0.3, 5),
# ('Karotte', 41, 0.9, 0.2, 10, 0.2, 3),
# ('Tomate', 18, 0.9, 0.2, 3.9, 0.2, 4),
# ('Brokkoli', 34, 2.8, 0.4, 6.6, 0.4, 2),
# ('Spinat', 23, 2.9, 0.4, 3.6, 0.4, 99),
# ('Kartoffel', 77, 2, 0.1, 17, 0.1, 12),
# ('Huhn', 239, 27, 14, 0, 0, 2),
# ('Lachs', 208, 20, 13, 0, 0, 1),
# ('Ei', 155, 13, 11, 1.1, 1, 1)
# ]
#
# cursor.executemany('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, CA) VALUES (?, ?, ?, ?, ?, ?, ?)', test_data)
#
# conn.commit()
# conn.close()
def calculate_nutrition(food, weight): def calculate_nutrition(food, weight):
conn = get_db_connection() try:
cursor = conn.cursor() conn = psycopg2.connect()
# Abfrage der Nährwertdaten aus der Datenbank with conn.cursor() as cursor:
cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = ?', (food,)) # Abfrage der Nährwertdaten aus der Datenbank
cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = ?', (food,))
result = cursor.fetchone() result = cursor.fetchone()
conn.close()
if result: if result:
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht # Runden und Berechnen der Nährwerte basierend auf dem Gewicht
kcal, ew, fett, kh, bst, ca = result kcal, ew, fett, kh, bst, ca = result
nutrition_values = [ nutrition_values = [
round(kcal * weight / 100), # kcal gerundet auf ganze Zahl round(kcal * weight / 100), # kcal gerundet auf ganze Zahl
round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
round(ca * weight / 100) # CA gerundet auf ganze Zahl round(ca * weight / 100) # CA gerundet auf ganze Zahl
] ]
return nutrition_values return nutrition_values
else: else:
return None return None
finally:
if conn:
conn.close()
# Index-Route # Index-Route
@ -102,16 +62,16 @@ def index():
@app.route('/get_products') @app.route('/get_products')
@oidc.require_login @oidc.require_login
def get_products(): def get_products():
conn = get_db_connection() try:
cursor = conn.cursor() conn = psycopg2.connect()
cursor.execute('SELECT name FROM nutrition_table') with conn.cursor() as cursor:
products = cursor.fetchall() cursor.execute('SELECT name FROM nutrition_table')
conn.close() products = cursor.fetchall()
print("ter") print("ter")
return {'products': [product[0] for product in products]} return {'products': [product[0] for product in products]}
finally:
if conn:
conn.close()
# Route zum Hinzufügen und Berechnen von Lebensmitteln # Route zum Hinzufügen und Berechnen von Lebensmitteln
@ -152,14 +112,16 @@ def add_nutrition():
print("test") print("test")
# Verbindung zur Datenbank herstellen und Daten einfügen # Verbindung zur Datenbank herstellen und Daten einfügen
conn = get_db_connection() try:
cursor = conn.cursor() conn = psycopg2.connect()
cursor.execute("INSERT INTO nutrition_table (name, kcal, ew, fett, kh, bst, ca) VALUES (?, ?, ?, ?, ?, ?, ?)", with conn.cursor() as cursor:
(food, kcal, ew, fett, kh, bst, ca)) cursor.execute("INSERT INTO nutrition_table (name, kcal, ew, fett, kh, bst, ca) VALUES (?, ?, ?, ?, ?, ?, ?)",
conn.commit() (food, kcal, ew, fett, kh, bst, ca))
conn.close()
return redirect(url_for('nutrition')) return redirect(url_for('nutrition'))
finally:
if conn:
conn.close()
@app.route('/nutrition') @app.route('/nutrition')

View File

@ -1,14 +1,13 @@
import csv import csv
import sqlite3 import psycopg2
# Pfad zur Ihrer CSV-Datei # Pfad zur Ihrer CSV-Datei
csv_file_path = 'nu.csv' csv_file_path = 'nu.csv'
# Pfad zur Ihrer SQLite-Datenbank # Pfad zur Ihrer SQLite-Datenbank
sqlite_db_path = 'nutrition.db'
# Verbindung zur SQLite-Datenbank herstellen # Verbindung zur SQLite-Datenbank herstellen
conn = sqlite3.connect(sqlite_db_path) conn = psycopg2.connect()
cursor = conn.cursor() cursor = conn.cursor()
# Erstellen der Tabelle (falls noch nicht vorhanden) # Erstellen der Tabelle (falls noch nicht vorhanden)
@ -29,8 +28,9 @@ with open(csv_file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile) reader = csv.reader(csvfile)
next(reader, None) # Überspringen der Kopfzeile next(reader, None) # Überspringen der Kopfzeile
for row in reader: for row in reader:
cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (?, ?, ?, ?, ?, ?, ?)', row) cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (%s, %s, %s, %s, %s, %s, %s)', row)
# Änderungen speichern und Verbindung schließen # Änderungen speichern und Verbindung schließen
conn.commit() conn.commit()
conn.close() conn.close()

View File

@ -172,15 +172,6 @@ function updateTotalNutrition() {
document.getElementById('total-ca').innerText = Math.round(totalCa); document.getElementById('total-ca').innerText = Math.round(totalCa);
} }
// Rufen Sie diese Funktion auf, wenn sich die Haupttabelle ändert
// Diese Funktion sollte aufgerufen werden, wenn ein Produkt hinzugefügt oder entfernt wird
</script> </script>
</head> </head>
<body> <body>
@ -196,7 +187,7 @@ function updateTotalNutrition() {
<div class="content"> <div class="content">
<form onsubmit="event.preventDefault(); addProduct();" id="product-form"> <form onsubmit="event.preventDefault(); addProduct();" id="product-form">
<label for="my_combobox">Wählen Sie ein Lebensmittel</label> <label for="my_combobox">Wählen Sie ein Lebensmittel</label>
<input list="products" name="my_combobox" id="my_combobox" oninput="updateButtonState()" autocomplete="off"> <input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
<datalist id="products"> <datalist id="products">
<!-- Produkte werden hier dynamisch eingefügt --> <!-- Produkte werden hier dynamisch eingefügt -->
</datalist> </datalist>

View File

@ -2,4 +2,3 @@
gunicorn 'Run:app' --bind 0.0.0.0:8080 --log-level=info --workers=4 gunicorn 'Run:app' --bind 0.0.0.0:8080 --log-level=info --workers=4