46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
import sqlite3
|
|
from datetime import datetime, timedelta
|
|
import os
|
|
|
|
|
|
|
|
def displayDB(cursor):
|
|
cursor.execute("SELECT * FROM doses")
|
|
|
|
for line in cursor:
|
|
print(line)
|
|
|
|
def update(uid, timestamp, stim, mg, cursor):
|
|
cursor.execute("UPDATE doses SET timestamp = ?, type = ?, amount = ? WHERE id = ?", (timestamp, stim, mg, uid))
|
|
|
|
def insert(timestamp, stim, mg, cursor):
|
|
cursor.execute("INSERT INTO doses (timestamp, type, amount) VALUES (?,?,?)", (timestamp, stim, mg))
|
|
|
|
def delete(uid,cursor):
|
|
cursor.execute("DELETE FROM doses WHERE id = ?", (uid,))
|
|
|
|
|
|
def main():
|
|
conn = sqlite3.connect('stimulants.db')
|
|
c = conn.cursor()
|
|
|
|
timestamp = "2025-10-10 05:45:00"
|
|
stim = "amphetamine"
|
|
#stim = "caffeine"
|
|
mg = 20
|
|
|
|
#update(1,timestamp,stim,mg,c)
|
|
delete(6,c)
|
|
#delete(2,c)
|
|
insert("2025-10-09 13:00:00", stim, 20, c)
|
|
insert("2025-10-09 13:00:00", "caffeine", 50, c)
|
|
insert("2025-10-09 16:30:00", stim, 10, c)
|
|
|
|
displayDB(c)
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|