From 60517b922a302aa2d2eb6f7474fc215101098f5f Mon Sep 17 00:00:00 2001 From: ManuelW Date: Sat, 11 May 2024 10:15:07 +0200 Subject: [PATCH] DB config --- insertLoading.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/insertLoading.py b/insertLoading.py index 15b40c8..c8a442d 100644 --- a/insertLoading.py +++ b/insertLoading.py @@ -17,15 +17,18 @@ except: exit(0) +try: + db = sqlite3.connect(db_file) + cursor = db.cursor() + print("Connected to SQLite") +except: + print("Failed to connect to DB") + ## ### auf neue Files überwachen def main(): - global cursor + global db, cursor try: - db = sqlite3.connect(db_file) - cursor = db.cursor() - print("Connected to SQLite") - updateLast() db.commit() print("Data updated successfully into bike_loading table") @@ -44,7 +47,7 @@ def main(): def updateLast(): - global cursor, watt + global db, cursor, watt ## hole letztes Ladungs-Datum sql = ''' @@ -90,7 +93,7 @@ def updateLast(): def insertNew(): - global cursor, loading + global db, cursor, loading date = datetime.today().strftime('%Y-%m-%d %H:%M:%S') data = (date, loading)