DB config
This commit is contained in:
parent
60517b922a
commit
a9785cc64c
@ -17,26 +17,16 @@ except:
|
|||||||
exit(0)
|
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
|
### auf neue Files überwachen
|
||||||
def main():
|
def main():
|
||||||
global db, cursor
|
|
||||||
try:
|
try:
|
||||||
updateLast()
|
db = sqlite3.connect(db_file)
|
||||||
db.commit()
|
cursor = db.cursor()
|
||||||
print("Data updated successfully into bike_loading table")
|
print("Connected to SQLite")
|
||||||
|
|
||||||
insertNew()
|
updateLast(db, cursor)
|
||||||
db.commit()
|
insertNew(db, cursor)
|
||||||
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__':
|
||||||
|
Loading…
Reference in New Issue
Block a user