DB config

This commit is contained in:
Manuel Weiser 2024-05-11 10:16:57 +02:00
parent 60517b922a
commit a9785cc64c

View File

@ -17,26 +17,16 @@ except:
exit(0) exit(0)
##
### auf neue Files überwachen
def main():
try: try:
db = sqlite3.connect(db_file) db = sqlite3.connect(db_file)
cursor = db.cursor() cursor = db.cursor()
print("Connected to SQLite") print("Connected to SQLite")
except:
print("Failed to connect to DB")
## updateLast(db, cursor)
### auf neue Files überwachen insertNew(db, cursor)
def main():
global db, cursor
try:
updateLast()
db.commit()
print("Data updated successfully into bike_loading table")
insertNew()
db.commit()
print("Data inserted successfully into bike_drives table")
cursor.close()
except sqlite3.Error as error: except sqlite3.Error as error:
print("Failed to insert data into sqlite table", error) print("Failed to insert data into sqlite table", error)
@ -46,8 +36,8 @@ def main():
print("The SQLite connection is closed") print("The SQLite connection is closed")
def updateLast(): def updateLast(db, cursor):
global db, cursor, watt global watt
## hole letztes Ladungs-Datum ## hole letztes Ladungs-Datum
sql = ''' sql = '''
@ -90,10 +80,12 @@ def updateLast():
WHERE id = ? WHERE id = ?
''' '''
cursor.execute(sql, data) cursor.execute(sql, data)
db.commit()
print("Data updated successfully into bike_loading table")
def insertNew(): def insertNew(db, cursor):
global db, cursor, loading global loading
date = datetime.today().strftime('%Y-%m-%d %H:%M:%S') date = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
data = (date, loading) data = (date, loading)
@ -105,6 +97,9 @@ def insertNew():
''' '''
cursor.execute(sql, data) cursor.execute(sql, data)
db.commit()
print("Data inserted successfully into bike_drives table")
cursor.close()
if __name__ == '__main__': if __name__ == '__main__':