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)