DB config
This commit is contained in:
parent
60517b922a
commit
a9785cc64c
@ -17,26 +17,16 @@ except:
|
||||
exit(0)
|
||||
|
||||
|
||||
##
|
||||
### auf neue Files überwachen
|
||||
def main():
|
||||
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 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()
|
||||
updateLast(db, cursor)
|
||||
insertNew(db, cursor)
|
||||
|
||||
except sqlite3.Error as error:
|
||||
print("Failed to insert data into sqlite table", error)
|
||||
@ -46,8 +36,8 @@ def main():
|
||||
print("The SQLite connection is closed")
|
||||
|
||||
|
||||
def updateLast():
|
||||
global db, cursor, watt
|
||||
def updateLast(db, cursor):
|
||||
global watt
|
||||
|
||||
## hole letztes Ladungs-Datum
|
||||
sql = '''
|
||||
@ -90,10 +80,12 @@ def updateLast():
|
||||
WHERE id = ?
|
||||
'''
|
||||
cursor.execute(sql, data)
|
||||
db.commit()
|
||||
print("Data updated successfully into bike_loading table")
|
||||
|
||||
|
||||
def insertNew():
|
||||
global db, cursor, loading
|
||||
def insertNew(db, cursor):
|
||||
global loading
|
||||
|
||||
date = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
|
||||
data = (date, loading)
|
||||
@ -105,6 +97,9 @@ def insertNew():
|
||||
'''
|
||||
|
||||
cursor.execute(sql, data)
|
||||
db.commit()
|
||||
print("Data inserted successfully into bike_drives table")
|
||||
cursor.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user