containerized

This commit is contained in:
2024-01-30 11:54:51 +01:00
parent e72dbad617
commit 8fa433f543
18 changed files with 932 additions and 0 deletions

36
src/db.py Normal file
View File

@ -0,0 +1,36 @@
import csv
import sqlite3
# Pfad zur Ihrer CSV-Datei
csv_file_path = 'nu.csv'
# Pfad zur Ihrer SQLite-Datenbank
sqlite_db_path = 'nutrition.db'
# Verbindung zur SQLite-Datenbank herstellen
conn = sqlite3.connect(sqlite_db_path)
cursor = conn.cursor()
# Erstellen der Tabelle (falls noch nicht vorhanden)
cursor.execute('''
CREATE TABLE IF NOT EXISTS nutrition_table (
name TEXT,
kcal REAL,
EW REAL,
Fett REAL,
KH REAL,
BST REAL,
Ca REAL
)
''')
# Öffnen der CSV-Datei und Einfügen der Daten in die Datenbank
with open(csv_file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
next(reader, None) # Überspringen der Kopfzeile
for row in reader:
cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (?, ?, ?, ?, ?, ?, ?)', row)
# Änderungen speichern und Verbindung schließen
conn.commit()
conn.close()