-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaurudu_nakath
More file actions
115 lines (82 loc) · 2.42 KB
/
aurudu_nakath
File metadata and controls
115 lines (82 loc) · 2.42 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import tkinter as tk
import requests
from datetime import datetime
import threading
import time
# 🔗 YOUR GOOGLE SHEET JSON URL
SHEET_URL = "https://opensheet.elk.sh/1Wl3PkGUB85FQAiFCr2pvcuV3kYKU19qlb0tX-eqLji4/aurudu_countdown"
events = []
def fetch_data():
global events
try:
res = requests.get(SHEET_URL)
data = res.json()
# print("Data fetched:", data)
temp = []
for row in data:
event = row.get("Event")
time_str = row.get("Time")
dt = datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S")
temp.append((event, dt))
# sort by time
print(temp)
events[:] = sorted(temp, key=lambda x: x[1])
except Exception as e:
print("Error:", e)
def get_countdown(target):
now = datetime.now()
diff = target - now
if diff.total_seconds() <= 0:
return "Started ✅"
days = diff.days
hours, remainder = divmod(diff.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return f"{days:02d}d {hours:02d}h {minutes:02d}m {seconds:02d}s"
def update_ui():
while True:
now = datetime.now()
display_text = ""
next_event_index = None
# find next event
for i, (event, t) in enumerate(events):
if t > now:
next_event_index = i
break
for i, (event, t) in enumerate(events):
countdown = get_countdown(t)
if i == next_event_index:
display_text += f"🔥 NEXT: {event}\n{countdown}\n\n"
else:
display_text += f"{event}\n{countdown}\n\n"
label.config(text=display_text)
time.sleep(1)
def auto_refresh_data():
while True:
fetch_data()
time.sleep(60) # refresh from sheet every 1 min
def exit_fullscreen(event=None):
root.attributes("-fullscreen", False)
def start():
fetch_data()
threading.Thread(target=update_ui, daemon=True).start()
threading.Thread(target=auto_refresh_data, daemon=True).start()
# UI Setup
root = tk.Tk()
root.title("🎉 Aurudu Nakath Countdown")
# Fullscreen
root.attributes("-fullscreen", True)
# Exit on ESC
root.bind("<Escape>", exit_fullscreen)
# Big font label
label = tk.Label(
root,
text="Loading...",
font=("Arial", 40, "bold"),
fg="white",
bg="black",
justify="center"
)
label.pack(expand=True)
# Start app
start()
root.mainloop()