Created
October 26, 2021 06:16
-
-
Save sukhbinder/a0c8a83ee9231bda90b21f4ca9637174 to your computer and use it in GitHub Desktop.
Make your computer chime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sched | |
import time | |
import datetime | |
import subprocess | |
event_schedule = sched.scheduler(time.time, time.sleep) | |
def subprocess_say(msg): | |
startinfo = subprocess.STARTUPINFO() | |
startinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW | |
iret=subprocess.run(["say", msg], | |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, | |
startupinfo=startinfo) | |
return iret | |
def chime_now(): | |
""" | |
Simple program that chimes or tells the time when | |
author:Sukhbinder | |
""" | |
now = datetime.datetime.now() | |
minute = now.minute | |
if minute in [0, 30, 55]: | |
hour = now.hour if now.hour <= 12 else now.hour - 12 | |
if minute == 0: | |
msg = "Its {} O clock".format(hour) | |
if minute == 30: | |
msg = "Its half past {}".format(hour) | |
if minute == 55: | |
msg = "It is {0} {1} ".format(hour, minute) | |
iret = subprocess_say(msg) | |
event_schedule.enter(60, 1, chime_now, ()) | |
if __name__ == "__main__": | |
event_schedule.enter(10, 1, chime_now, ()) | |
event_schedule.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment