-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (42 loc) · 1.48 KB
/
main.py
File metadata and controls
66 lines (42 loc) · 1.48 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from PIL import Image, ImageDraw, ImageFont
from datetime import datetime
import pytz
import time
import matplotlib.pyplot as plt
def generate_time_image(time_zone):
tz = pytz.timezone(time_zone)
current_time = datetime.now(tz).strftime("%H:%M:%S")
width, height = 400, 200
image = Image.new("RGB", (width, height), color=(30, 30, 30))
draw = ImageDraw.Draw(image)
try:
font = ImageFont.truetype("arial.ttf", 40)
except IOError:
font = ImageFont.load_default()
text_bbox = draw.textbbox((0, 0), current_time, font=font)
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1]
text_x = (width - text_width) // 2
text_y = (height - text_height) // 2
draw.text((text_x, text_y), current_time, font=font, fill=(255, 255, 255))
return image
def main():
print("Enter a valid time zone ('America/New_York', 'Asia/Tokyo', 'UTC').")
while True:
try:
time_zone = input("Enter time zone: ").strip()
pytz.timezone(time_zone)
break
except pytz.UnknownTimeZoneError:
print("Invalid time zone. Please try again.")
print(f"Displaying time for time zone: {time_zone}")
plt.ion()
fig, ax = plt.subplots()
while True:
image = generate_time_image(time_zone)
ax.clear()
ax.axis("off")
ax.imshow(image)
plt.pause(1)
if __name__ == "__main__":
main()