Skip to content

Instantly share code, notes, and snippets.

@mrkatey
Created October 4, 2022 04:53
Show Gist options
  • Save mrkatey/3640d56fadf5396a82a8833e6a1c8674 to your computer and use it in GitHub Desktop.
Save mrkatey/3640d56fadf5396a82a8833e6a1c8674 to your computer and use it in GitHub Desktop.
Basic Desktop Alarm Clock
from sys import argv
from time import sleep
import winsound
import datetime
def minute_timer(time_in_min=1):
try:
alarm = [[2500,1000],[3200, 1000],[1300, 1000], [7000, 1000]]
sound_frequency = 2500
sound_duration = 4000
total_time = int(time_in_min*60)
elapsed = 0
for i in range(total_time):
sleep(1)
elapsed +=1
print(f"Time left: {total_time-elapsed} | Elapsed {elapsed}", end='\r')
for freq, ms in alarm:
winsound.Beep(freq, ms)
except Exception as ee:
print(ee)
with open('alarm.csv','a') as f:
f.write(f"Alarm: {datetime.datetime.now()}, Duration: {total_time}\n")
print("TIME IS UP!***************************")
return True
if __name__ == "__main__":
time_in_min = 30
if argv[1]:
time_in_min = float(argv[1])
minute_timer(time_in_min=time_in_min)
else:
minute_timer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment