alarm.py
· 762 B · Python
Eredeti
from datetime import datetime
from playsound import playsound
alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n")
alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()
print("Setting up alarm..")
while True:
now = datetime.now()
current_hour = now.strftime("%I")
current_minute = now.strftime("%M")
current_seconds = now.strftime("%S")
current_period = now.strftime("%p")
if(alarm_period==current_period):
if(alarm_hour==current_hour):
if(alarm_minute==current_minute):
if(alarm_seconds==current_seconds):
print("Wake Up!")
playsound('audio.mp3')
break
| 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 |