diff --git a/spacer.py b/spacer.py new file mode 100644 index 0000000..067f398 --- /dev/null +++ b/spacer.py @@ -0,0 +1,35 @@ +import os +from PIL import Image +import glob + +def get_latest_screenshot(directory): + """ Get the latest screenshot file from the given directory. """ + list_of_files = glob.glob(os.path.join(directory, '*.jpg')) # You can change the file extension if needed + latest_file = max(list_of_files, key=os.path.getctime) + return latest_file + +def process_image(image_path): + """ Process the image to decide if it's dark or light. """ + with Image.open(image_path) as img: + # Resize image to 2x2 + img = img.resize((2, 2)) + + # Get average color of the pixels + average_color = sum(img.getdata(), (0, 0, 0)) + average_color = [color / 4 for color in average_color] # Since the image is 2x2 + + # Determine if the image is dark or light + if sum(average_color) / 3 < 128: # Average RGB values less than 128 is considered dark + return 'closed' + else: + return 'open' + +# Directory where the screenshots are stored +screenshot_directory = '/var/lib/motion/' + +# Get the latest screenshot +latest_screenshot = get_latest_screenshot(screenshot_directory) + +# Process the image and determine hackspace status +hackspace_status = process_image(latest_screenshot) +print(f"The hackspace is {hackspace_status}.") \ No newline at end of file