DB config

This commit is contained in:
Manuel Weiser 2024-05-11 08:24:57 +02:00
parent 80b6b7bbef
commit 12c0dec445

View File

@ -98,15 +98,30 @@ def doHealthFit(file, min_alt=0.0):
def writeDB(): def writeDB():
global fitData, db_file global fitData, db_file
db = sqlite3.connect(db_file) try:
cursor = db.cursor() db = sqlite3.connect(db_file)
cursor = db.cursor()
data = [fitData["date"], fitData["total_distance"], fitData["total_ascent"], fitData["max_altitude"], fitData["avg_speed"],
fitData["avg_heart_rate"], fitData["total_calories"]] sql = '''
INSERT INTO bike_drives
cursor.executemany('INSERT INTO bike_drives VALUES (?)', data) (d_date, d_total_distance, d_total_ascent, d_max_alt, d_avg_speed, d_avg_hr, d_calories)
db.commit() VALUES (?, ?, ?, ?, ?, ?, ?);
db.close() '''
data = (fitData["date"], fitData["total_distance"], fitData["total_ascent"], fitData["max_altitude"], fitData["avg_speed"],
fitData["avg_heart_rate"], fitData["total_calories"])
cursor.execute(sql, data)
db.commit()
print("Data inserted successfully into bike_drives table")
cursor.close()
except sqlite3.Error as error:
print("Failed to insert data into sqlite table", error)
finally:
if db:
db.close()
print("The SQLite connection is closed")
#row.extend(["Date", "Total Distance", "Total Ascent", "Max Alt.", "AVG Speed", "AVG HR", "Calories"]) #row.extend(["Date", "Total Distance", "Total Ascent", "Max Alt.", "AVG Speed", "AVG HR", "Calories"])