diff --git a/DB.py b/DB.py index c463752..2f50a7a 100644 --- a/DB.py +++ b/DB.py @@ -54,3 +54,8 @@ class Database: self._con.commit() print(f"✅ Inserted {inserted}/{len(shifts)} new shifts") + def delete_future_shifts(self): + cur = self._con.cursor() + cur.execute("DELETE FROM shifts WHERE shift_start > current_timestamp") + self._con.commit() + print(f"✅ Deleted all future shifts") diff --git a/__pycache__/DB.cpython-313.pyc b/__pycache__/DB.cpython-313.pyc index 6d84096..57015c2 100644 Binary files a/__pycache__/DB.cpython-313.pyc and b/__pycache__/DB.cpython-313.pyc differ diff --git a/__pycache__/PMT.cpython-313.pyc b/__pycache__/PMT.cpython-313.pyc index ce3c65e..59538e8 100644 Binary files a/__pycache__/PMT.cpython-313.pyc and b/__pycache__/PMT.cpython-313.pyc differ diff --git a/main.py b/main.py index 3ebe55d..3c52fb4 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ from PMT import PMT from DB import Database from dotenv import load_dotenv +from time import sleep import os def main(): @@ -18,10 +19,11 @@ def main(): days_ahead = int(os.environ.get("DAYS_TO_FETCH")) shifts = pmt.get_shifts(days_ahead) - PMT.print_shifts(shifts) + + db.delete_future_shifts() # delete all future shifts before importing, to make sure if a shift is removed, it actually gets removed here too. - # Insert those shifts into the database + # Insert the new shifts into the database db.insert_shifts(shifts)