import toml # handle toml files
import sqlite3
from datetime import datetime
import time
settings = toml.load('settings.toml')
dbfilename = settings['dbfilename']
conn = sqlite3.connect(":memory:")
c = conn.cursor()
with conn:
c.execute(
"""
create table if not exists
contacts (id integer primary key,
personid integer,
validfrom text,
validto text,
firstname text,
lastname text,
phonenumber text);
"""
)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
c.execute(f"INSERT INTO contacts (personid, validfrom, validto, firstname, lastname, phonenumber) values (1,'{now}','9999-12-31 23:59:59','Mickey','Mouse','0123-456')")
c.execute(f"INSERT INTO contacts (personid, validfrom, validto, firstname, lastname, phonenumber) values (2,'{now}','9999-12-31 23:59:59','Donald','Duck','0123-123')")
time.sleep(6)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
c.execute(f"UPDATE contacts set validto = '{now}' where id = 1")
time.sleep(6)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
c.execute(f"INSERT INTO contacts (personid, validfrom,validto, firstname, lastname, phonenumber) values (1, '{now}','9999-12-31 23:59:59','Mickey','Mouse','0123-789')")
result = c.execute(f"select * from contacts where validto > '2023-12-31';").fetchall()
for row in result:
print(row) |