Add deletion of old screenshots

This commit is contained in:
PAlexanderFranklin 2024-08-01 19:37:44 -07:00
parent 368cbeb9e2
commit b1dae6f71f

View File

@ -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: