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: