[go: up one dir, main page]

0% found this document useful (0 votes)
3 views2 pages

Python Mini Project

Uploaded by

Utkarsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Mini Project

Uploaded by

Utkarsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

20201CSE0094

from datetime import datetime # To set date and time


from pytz import timezone # To get current Timezone
import time # Time(in sec) to alarm run
from pygame import mixer # To play alarm

def valid_date(alarm_date): # Check whether input date is right or not


if len(alarm_date) == 10:
if int(alarm_date[0:2]) > 31:
return "Invalid DATE format"
elif int(alarm_date[3:5]) > 12:
return "Invalid MONTH format"
elif int(alarm_date[6:10]) < 2021:
return "Invalid YEAR format"
elif ((alarm_date[2]) != '/' and (alarm_date[5]) != '/'):
return "Invalid date-year format"
elif alarm_date < datetime.now(timezone("Asia/Kolkata")).strftime('%d/%m/%Y'):
return "Invalid 'DD/MM/YYYY' format"
else:
return "Ok"
else:
return "Invalid 'DD/MM/YYYY' format"

def valid_time(alarm_time): # Check whether input time is right or not


if len(alarm_time) == 5:
if int(alarm_time[0:2]) > 23:
return "Invalid HOUR format"
elif (alarm_time[2]) != ':':
return "Invalid HH:MM format"
elif int(alarm_time[3:5]) > 59:
return "Invalid MINUTE format"
elif alarm_time < datetime.now(timezone("Asia/Kolkata")).strftime('%H:%M'):
return "Invalid 'HH:MM' format"
else:
return "Ok"
else:
return "Invalid HH:MM format"

def sound(): # To play alarm


mixer.init() # Initialize a mixer
mixer.music.load("carol_of_the_bells-alarm.mp3") # Loading the sound on mixer
mixer.music.set_volume(1.2) # Set volume
mixer.music.play() # Play alarm
time.sleep(12) # Play alarm for 12 sec

while 1: # Input as alarm date


alarm_date = input("Enter date,month and year in 'DD/MM/YYYY' format:-")
valid = valid_date(alarm_date)

if valid != "Ok":
print(valid)
else:
break

while 1: # Input as alarm time


alarm_time = input("Enter time in 'HH:MM' format:-")
valid = valid_time(alarm_time)

if valid != "Ok":
20201CSE0094

print(valid)
else:
print("Alarm set for {} on {}...".format(alarm_time, alarm_date))
break

while 1: # To get Current time zone


if alarm_time == datetime.now(timezone("Asia/Kolkata")).strftime('%H:%M') and alarm_date
== datetime.now(timezone("Asia/Kolkata")).strftime('%d/%m/%Y'):
print('Wake Up!')
sound()
break

You might also like