-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlarm.py
More file actions
58 lines (41 loc) · 1.51 KB
/
Alarm.py
File metadata and controls
58 lines (41 loc) · 1.51 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
from datetime import datetime
from django.core.serializers import python
from playsound import playsound
alarmtime = input("Enter the time of Alarm: HH:MM:SS AM/PM \n")
alarmhour = alarmtime[0:2]
alarmminute = alarmtime[3:5]
alarmsecond = alarmtime[6:8]
alarmperiod = alarmtime[9:].upper()
while True:
def validate(alarmtime):
if len(alarmtime) != 11:
return "Invalid time format"
else:
if int(alarmsecond) > 59:
return "invalid second format"
elif int(alarmhour) > 12 :
return "invalid Hour format"
elif int(alarmminute) > 59 :
return "invalid Minute format"
else:
return "Perfectly Fine"
while True:
alarmtime = input("Enter the time of Alarm: HH:MM:SS AM/PM \n")
validate_check = validate(alarmtime.lower())
if validate_check != "Perfectly Fine":
print(validate_check)
else:
print(F"Setting the alarm for"+ alarmtime)
break
now = datetime.now()
currenthour = now.strftime("%I")
currentmin = now.strftime("%M")
currentsecond = now.strftime("%S")
currentperiod = now.strftime("%p")
if alarmperiod == currentperiod:
if alarmhour == currenthour:
if alarmminute == currentmin:
if alarmsecond == currentsecond:
print("WAKE UP")
playsound('C:\Users\hp\Desktop\Python projects 1\python alarm sound.wav')
break