Skip to content

Commit 000e25d

Browse files
author
Karan Goel
committed
Add feature to play sound after X minutes
1 parent 922d1d7 commit 000e25d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Numbers/alarm.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import winsound
1212
import pyglet
1313

14-
if __name__ == '__main__':
15-
hh = input('What hour do you want to wake up (0-23)? ')
16-
mm = input('What minute do you want to wake up (0-59)? ')
17-
14+
def play(hh, mm):
1815
not_alarmed = 1
1916

2017
while(not_alarmed):
@@ -27,3 +24,26 @@
2724
pyglet.app.run()
2825
not_alarmed = 0 # stop the loop
2926

27+
if __name__ == '__main__':
28+
29+
print """
30+
1. Play sound after X minutes
31+
2. Play sound at an exact time
32+
"""
33+
choice = input('What do you want to do? ')
34+
35+
if choice == 1:
36+
mins = input('How many minutes from now? ')
37+
hh_from_now = mins / 60 # if minutes > 60, this will adjust the hours
38+
mm_from_now = mins % 60 # and then the minutes
39+
cur_time = list(time.localtime()) # get the time right now
40+
hour = cur_time[3] # find the current hour
41+
minute = cur_time[4] # and the current minute
42+
hh = (hour + hh_from_now) % 24 # cycle through the clock if hh > 24
43+
mm = (minute + mm_from_now) % 60 # cycle through the clock if mm > 60
44+
play(hh, mm)
45+
elif choice == 2:
46+
hh = input('What hour do you want to wake up (0-23)? ')
47+
mm = input('What minute do you want to wake up (0-59)? ')
48+
play(hh, mm)
49+

0 commit comments

Comments
 (0)