My code is designed to simply trigger alarms; it is not supposed to be used by anyone but me.
import subprocess,time,threading, winsound, sys, basepipe
commands = ''
def alarm_checker(alarms):
"""This will be the main threaded process, and will be the meat of the program."""
global commands
hours = [int(a.split(":")[0]) for a in alarms]
mins = [int(a.split(":")[1]) for a in alarms]
while True:
localtime = time.localtime()
for hour,minute in zip(hours,mins):
if localtime.tm_hour == hour and localtime.tm_min == minute:
guiserver,guiclient = basepipe.create_double()
process = subprocess.Popen(r"c:\python34\pythonw.exe c:\python34\guibutton.py",stdout=guiclient)
while guiserver.read() == '':
winsound.Beep(1000,2000)
hours.remove(hour)
mins.remove(minute)
if commands != '':
for y in commands.split("
"):
try:
exec(y)
except BaseException as e:
sys.stderr.write(str(e))
commands = ''
time.sleep(2)
if __name__ == "__main__":
today = time.localtime().tm_wday
everyday = ['6:55','7:15','8:12']
advising = ['13:25','13:55']
tuethur = ['10:55']
monday = everyday + advising + ['15:00']
tuesday = everyday + tuethur
wednesday = everyday + ['3:50']
thursday = everyday + advising + tuethur
friday = everyday
week = [monday,tuesday,wednesday,thursday,friday,['25:00'],['25:00']]
thread = threading.Thread(target=alarm_checker,args=(week[today],))
thread.start()
The basepipe program is a wrapper around windows named pipes in Python. All it does is attempt to implement them in the same way as any other type of IO. One of the peculiarities of windows named pipes is that client read operations are always blocking, while server read operations always raise an error when there is no data in the buffer. I changed this error to simply return ''. create_double() creates a pair of server/client objects. The guibutton.py program does nothing other than open a tcl/tk window. Winsound provides direct access to the sound card, and 1000,2000 means 1000 hertz for 2 seconds, which is annoying as hell.