more table

This commit is contained in:
2024-01-30 22:24:48 +01:00
parent 1e8ae0105a
commit 8f15a05a4e
3 changed files with 109 additions and 0 deletions

View File

@ -140,6 +140,34 @@ def get_token():
return jsonify(token=oidc.get_access_token())
@app.route('/get_database_entries')
def get_database_entries():
try:
# Ersetzen Sie diese Werte mit Ihren Datenbank-Verbindungsinformationen
conn = psycopg2.connect()
cursor = conn.cursor()
with conn.cursor() as cursor:
cursor.execute("SELECT name, kcal, ew, fett, kh, bst, ca FROM nutrition_table")
entries = cursor.fetchall()
# Umwandeln der Daten in ein JSON-freundliches Format
entries_list = []
for entry in entries:
entries_list.append({
"food": entry[0],
"kcal": entry[1],
"ew": entry[2],
"fett": entry[3],
"kh": entry[4],
"bst": entry[5],
"ca": entry[6]
})
return jsonify(entries_list)
except Exception as e:
return jsonify({"error": str(e)}), 500
finally:
if conn:
conn.close()
app = ProxyFix(app, x_for=1, x_host=1)