added ics support. and some thread safety

This commit is contained in:
Valentijn
2026-03-19 16:20:48 +01:00
parent 48b5ff9bbc
commit 79f9e99e74
3 changed files with 101 additions and 10 deletions

24
DB.py
View File

@@ -3,14 +3,17 @@ import sqlite3
class Database:
def __init__(self):
self._con = sqlite3.connect("shifts.db")
self.db_path = "shifts.db"
self._setup_tables()
pass
def _get_connection(self):
return sqlite3.connect(self.db_path)
def _setup_tables(self):
# create the shifts table.
cur = self._con.cursor()
con = self._get_connection()
cur = con.cursor()
cur.execute('''
CREATE TABLE IF NOT EXISTS shifts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -24,12 +27,14 @@ class Database:
UNIQUE(shift_start, department) -- No duplicates
);
''')
self._con.commit()
con.commit()
con.close()
def insert_shifts(self, shifts):
# start db connection
cur = self._con.cursor()
con = self._get_connection()
cur = con.cursor()
inserted = 0
for shift in shifts:
@@ -51,11 +56,14 @@ class Database:
if cur.rowcount > 0:
inserted += 1
self._con.commit()
con.commit()
con.close()
print(f"✅ Inserted {inserted}/{len(shifts)} new shifts")
def delete_future_shifts(self):
cur = self._con.cursor()
con = self._get_connection()
cur = con.cursor()
cur.execute("DELETE FROM shifts WHERE shift_start > current_timestamp")
self._con.commit()
con.commit()
con.close()
print(f"✅ Deleted all future shifts")