Correct output directory, change timing algorithm

This commit is contained in:
PAlexanderFranklin 2024-08-01 18:35:07 -07:00
parent 2af2a33522
commit f8040da85b

View File

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