-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
44 lines (36 loc) · 1.66 KB
/
run.py
File metadata and controls
44 lines (36 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from datetime import datetime
import subprocess
from llm import analyze_screenshot_with_gemini
from notify import show_notification
def take_screenshot_and_analyze():
"""Takes a screenshot, analyzes it, and displays the result in a notification."""
try:
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# Save screenshot to a temporary directory to keep your home clean
filename = f"/tmp/screenshot_{timestamp}.png"
# Take the screenshot using grim
subprocess.run(["grim", filename], check=True, capture_output=True)
print(f"Screenshot saved as {filename}")
# Get the response back from the llm module
response_text = analyze_screenshot_with_gemini(filename)
if response_text:
print("Displaying response in notification...")
show_notification(response_text)
else:
print("Analysis failed or returned no text. No notification will be shown.")
except FileNotFoundError:
# It's better to send an error notification if something goes wrong
error_msg = "Error: 'grim' command not found. Please install it."
print(error_msg)
show_notification(error_msg)
except subprocess.CalledProcessError as e:
error_msg = f"An error occurred while running grim: {e.stderr.decode()}"
print(error_msg)
show_notification(error_msg)
except Exception as e:
error_msg = f"An unexpected error occurred: {e}"
print(error_msg)
show_notification(error_msg)
if __name__ == "__main__":
# The script is now executed directly, so it just runs the main function.
take_screenshot_and_analyze()