alarm.py(檔案已創建)
@@ -0,0 +1,21 @@ | |||
1 | + | from datetime import datetime | |
2 | + | from playsound import playsound | |
3 | + | alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n") | |
4 | + | alarm_hour=alarm_time[0:2] | |
5 | + | alarm_minute=alarm_time[3:5] | |
6 | + | alarm_seconds=alarm_time[6:8] | |
7 | + | alarm_period = alarm_time[9:11].upper() | |
8 | + | print("Setting up alarm..") | |
9 | + | while True: | |
10 | + | now = datetime.now() | |
11 | + | current_hour = now.strftime("%I") | |
12 | + | current_minute = now.strftime("%M") | |
13 | + | current_seconds = now.strftime("%S") | |
14 | + | current_period = now.strftime("%p") | |
15 | + | if(alarm_period==current_period): | |
16 | + | if(alarm_hour==current_hour): | |
17 | + | if(alarm_minute==current_minute): | |
18 | + | if(alarm_seconds==current_seconds): | |
19 | + | print("Wake Up!") | |
20 | + | playsound('audio.mp3') | |
21 | + | break |
上一頁
下一頁