From 55c430606fe4281c2a3fc7bdc688b7d7a9056246 Mon Sep 17 00:00:00 2001 From: themrphantom Date: Mon, 15 Jul 2024 14:57:16 +0200 Subject: [PATCH] fixes --- backend/database/Queries.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/database/Queries.py b/backend/database/Queries.py index d98bea4..77818a2 100644 --- a/backend/database/Queries.py +++ b/backend/database/Queries.py @@ -57,16 +57,20 @@ def create_Links(self) -> None: for folder in folders: db_result: Lecture = self.session.query( Lecture).filter_by(name=folder).first() - folder_path = f"{self.base_folder}/{folder}" - link = self.nc.create_link(folder_path) - if db_result is None: - - new_Lecture = Lecture(name=folder, folder=folder_path, - link=link["link"], valid_until=link["valid_until"]) - self.session.add(new_Lecture) - else: - db_result.link = link["link"] - db_result.valid_until = link["valid_until"] + + # Check if the link is valid for less than 12 days + if db_result.valid_until - datetime.now() < timedelta(days=12): + + folder_path = f"{self.base_folder}/{folder}" + link = self.nc.create_link(folder_path) + if db_result is None: + + new_Lecture = Lecture(name=folder, folder=folder_path, + link=link["link"], valid_until=link["valid_until"]) + self.session.add(new_Lecture) + else: + db_result.link = link["link"] + db_result.valid_until = link["valid_until"] self.session.commit() all_Lectures: List[Lecture] = self.session.query(Lecture).all()