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
try:
db = sqlite3.connect(db_file) db = sqlite3.connect(db_file)
cursor = db.cursor() cursor = db.cursor()
data = [fitData["date"], fitData["total_distance"], fitData["total_ascent"], fitData["max_altitude"], fitData["avg_speed"], sql = '''
fitData["avg_heart_rate"], fitData["total_calories"]] INSERT INTO bike_drives
(d_date, d_total_distance, d_total_ascent, d_max_alt, d_avg_speed, d_avg_hr, d_calories)
VALUES (?, ?, ?, ?, ?, ?, ?);
'''
cursor.executemany('INSERT INTO bike_drives VALUES (?)', data) 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() 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() 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"])