From b1dae6f71fd4d245611d14727c35f2ca13e50de7 Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Thu, 1 Aug 2024 19:37:44 -0700 Subject: [PATCH] Add deletion of old screenshots --- src/screenmonitor.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/screenmonitor.py b/src/screenmonitor.py index 1955283..feaba23 100644 --- a/src/screenmonitor.py +++ b/src/screenmonitor.py @@ -26,6 +26,20 @@ def capture_screenshot(): print(f"Screenshot saved to {filename}") +def delete_old_screenshots(): + # Define the time threshold (72 hours ago) + time_threshold = datetime.now() - timedelta(hours=72) + + for filename in os.listdir(output_dir): + if filename.startswith("screenshot"): + file_path = os.path.join(output_dir, filename) + file_mtime = datetime.fromtimestamp(os.path.getmtime(file_path)) + + if file_mtime < time_threshold: + os.remove(file_path) + print(f"Deleted old screenshot: {file_path}") + + def main(): while True: # Calculate the random time within the next 17-minute interval @@ -41,6 +55,9 @@ def main(): # Capture the screenshot capture_screenshot() + # Delete old screenshots + delete_old_screenshots() + # Sleep for the remainder of the 17-minute interval remaining_interval = (next_interval_start - datetime.now()).total_seconds() if remaining_interval > 0: