MASS24 commited on
Commit
eca58c7
·
verified ·
1 Parent(s): e51ae1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -0
app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+ import pytz
4
+ from datetime import datetime, timedelta
5
+
6
+ # Helper Functions
7
+ def get_timezones():
8
+ return ['UTC', 'US/Eastern', 'Europe/London', 'Asia/Kolkata', 'Asia/Tokyo', 'Australia/Sydney']
9
+
10
+ def format_time(seconds):
11
+ mins, secs = divmod(seconds, 60)
12
+ hours, mins = divmod(mins, 60)
13
+ return f"{int(hours):02d}:{int(mins):02d}:{int(secs):02d}"
14
+
15
+ # Streamlit App
16
+ st.set_page_config(page_title="Clock App", page_icon="🕰️", layout="centered")
17
+ st.title("🕰️ Clock Application")
18
+
19
+ menu = st.sidebar.radio("Select Function", ("World Clock", "Alarm Clock", "Stopwatch", "Timer"))
20
+
21
+ # --- World Clock --- #
22
+ if menu == "World Clock":
23
+ st.header("🌎 World Clock")
24
+ selected_timezones = st.multiselect("Choose timezones", get_timezones(), default=['UTC'])
25
+
26
+ placeholder = st.empty()
27
+ while True:
28
+ with placeholder.container():
29
+ for tz in selected_timezones:
30
+ timezone = pytz.timezone(tz)
31
+ time_now = datetime.now(timezone).strftime("%Y-%m-%d %H:%M:%S")
32
+ st.write(f"**{tz}**: {time_now}")
33
+ time.sleep(1)
34
+ placeholder.empty()
35
+
36
+ # --- Alarm Clock --- #
37
+ elif menu == "Alarm Clock":
38
+ st.header("⏰ Alarm Clock")
39
+ alarm_time = st.time_input("Set Alarm Time")
40
+ alarm_set = st.button("Set Alarm")
41
+
42
+ if alarm_set:
43
+ st.success(f"Alarm is set for {alarm_time}!")
44
+ while True:
45
+ now = datetime.now().time()
46
+ if (now.hour, now.minute) == (alarm_time.hour, alarm_time.minute):
47
+ st.balloons()
48
+ st.success("⏰ It's Time!")
49
+ break
50
+ time.sleep(20)
51
+
52
+ # --- Stopwatch --- #
53
+ elif menu == "Stopwatch":
54
+ st.header("⏱️ Stopwatch")
55
+
56
+ if "stopwatch_running" not in st.session_state:
57
+ st.session_state.stopwatch_running = False
58
+ st.session_state.start_time = None
59
+ st.session_state.elapsed = 0
60
+
61
+ col1, col2, col3 = st.columns(3)
62
+
63
+ with col1:
64
+ if st.button("Start"):
65
+ if not st.session_state.stopwatch_running:
66
+ st.session_state.start_time = time.time() - st.session_state.elapsed
67
+ st.session_state.stopwatch_running = True
68
+
69
+ with col2:
70
+ if st.button("Pause"):
71
+ if st.session_state.stopwatch_running:
72
+ st.session_state.elapsed = time.time() - st.session_state.start_time
73
+ st.session_state.stopwatch_running = False
74
+
75
+ with col3:
76
+ if st.button("Reset"):
77
+ st.session_state.start_time = None
78
+ st.session_state.elapsed = 0
79
+ st.session_state.stopwatch_running = False
80
+
81
+ st.subheader("Elapsed Time")
82
+ placeholder = st.empty()
83
+
84
+ while st.session_state.stopwatch_running:
85
+ elapsed = time.time() - st.session_state.start_time
86
+ placeholder.subheader(format_time(elapsed))
87
+ time.sleep(0.1)
88
+ else:
89
+ placeholder.subheader(format_time(st.session_state.elapsed))
90
+
91
+ # --- Timer --- #
92
+ elif menu == "Timer":
93
+ st.header("⏲️ Timer")
94
+
95
+ minutes = st.number_input("Set Timer (minutes)", min_value=0, max_value=120, value=1)
96
+ start_timer = st.button("Start Timer")
97
+
98
+ if start_timer:
99
+ total_seconds = minutes * 60
100
+ placeholder = st.empty()
101
+
102
+ for remaining in range(total_seconds, -1, -1):
103
+ placeholder.subheader(format_time(remaining))
104
+ time.sleep(1)
105
+ st.balloons()
106
+ st.success("⏳ Time's up!")