From f8040da85ba779c2a78f3bfb058ab8ac5d7e7690 Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Thu, 1 Aug 2024 18:35:07 -0700 Subject: [PATCH] Correct output directory, change timing algorithm --- src/screenmonitor.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/screenmonitor.py b/src/screenmonitor.py index d89113b..1955283 100644 --- a/src/screenmonitor.py +++ b/src/screenmonitor.py @@ -1,13 +1,18 @@ import os import random import time -from datetime import datetime +from datetime import datetime, timedelta from PIL import Image, ImageFilter import pyautogui -import schedule + +# Define the directory where screenshots will be saved +output_dir = os.path.expanduser("~/.screenmonitor/output") + +# Ensure the output directory exists +os.makedirs(output_dir, exist_ok=True) -def capture_screenshot(folder): +def capture_screenshot(): # Capture screenshot screenshot = pyautogui.screenshot() @@ -16,24 +21,30 @@ def capture_screenshot(folder): # Compress and save timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - filename = os.path.join(folder, f"screenshot_{timestamp}.jpeg") + filename = os.path.join(output_dir, f"screenshot_{timestamp}.jpeg") blurred_screenshot.save(filename, "JPEG", quality=20) print(f"Screenshot saved to {filename}") -def job(): - capture_screenshot("/path/to/folder") - - def main(): - # Schedule screenshots at random intervals - for _ in range(10): # Number of times to schedule - random_interval = random.randint(1, 60) # Random interval in minutes - schedule.every(random_interval).minutes.do(job) - while True: - schedule.run_pending() - time.sleep(1) + # Calculate the random time within the next 17-minute interval + next_interval_start = datetime.now() + timedelta(minutes=17) + random_seconds = random.randint(0, 17 * 60) + random_time = datetime.now() + timedelta(seconds=random_seconds) + + # Sleep until the random time within the interval + time_to_sleep = (random_time - datetime.now()).total_seconds() + if time_to_sleep > 0: + time.sleep(time_to_sleep) + + # Capture the screenshot + capture_screenshot() + + # Sleep for the remainder of the 17-minute interval + remaining_interval = (next_interval_start - datetime.now()).total_seconds() + if remaining_interval > 0: + time.sleep(remaining_interval) if __name__ == "__main__":