diff --git a/app/init.py b/app/init.py index 7ee455c..47d7470 100644 --- a/app/init.py +++ b/app/init.py @@ -8,7 +8,7 @@ import os import json import mariadb import logging - +from pathlib import Path import schedule import time import pytz @@ -24,7 +24,8 @@ CATEGORIES = [ ] SUBCAT_CATEGORIES = ["Klausuren", "Übungen", "Labore"] unizeug_path = os.environ.get("UNIZEUG_PATH", "./unizeug") - +APP_ROOT_PATH = Path(os.environ.get("APP_ROOT_PATH", "./app")) +FILES_IN_PROGRESS = APP_ROOT_PATH / "files/" log = logging.getLogger(__name__) logging.basicConfig( filename="init.log", @@ -78,6 +79,18 @@ except mariadb.OperationalError: pass db.commit() +def remove_old_FIP_entrys(): + cur=db.cursor(dictionary=True) + cur.execute( + "SELECT id,filename FROM FIP WHERE HOUR(TIMEDIFF(NOW(),initTimeStamp)) > 24 " + ) + files=cur.fetchall() + info(f"Remove Files: {files}") + for file in files: + c.execute("DELETE FROM FIP WHERE id=?", (file["id"])) + os.remove(FILES_IN_PROGRESS / file["filename"]) + db.commit() + def get_dirstruct(): # with open("app/pwfile.json", "r") as f: @@ -149,6 +162,7 @@ def get_dirstruct(): (lid, pid, idx, subcat.name), ) db.commit() + remove_old_FIP_entrys() def link_prof(firstname, lastname, lid):