-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontrol.py
59 lines (43 loc) · 1.59 KB
/
control.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging
import sys
import time
from ai import get_image_dalle, get_image_recraft, get_image_prompt
from epaper import EPaperDisplay
logging.basicConfig(level=logging.INFO)
def main():
if len(sys.argv) < 2 or sys.argv[1] not in ("show", "clear"):
print("Usage: python control.py <command> [location]")
print("Available commands:")
print(" show <location> - Display the weather for the specified location.")
print(" clear - Clear the e-paper display.")
sys.exit(1)
command = sys.argv[1]
if command == "show" and len(sys.argv) < 3:
print("Usage: python control.py show <location>")
sys.exit(1)
if command == "clear" and len(sys.argv) > 2:
print("Usage: python control.py clear")
sys.exit(1)
epd = EPaperDisplay()
try:
logging.info("Initializing the display")
epd.initialize()
if command == "show":
location = sys.argv[2]
logging.info(f"Getting the image prompt for {location}")
prompt = get_image_prompt(location)
logging.info(f"Prompt: {prompt}")
logging.info("Generating the image")
image = get_image_dalle(prompt)
logging.info("Displaying the image")
epd.display(image)
elif command == "clear":
logging.info("Clearing the display")
epd.clear()
except KeyboardInterrupt:
logging.info("Interrupted by user")
finally:
logging.info("Putting the display to sleep")
epd.sleep()
if __name__ == "__main__":
main()