Try to loop until your check evaluates True:
import time
interval = 0.2 # nr of seconds
while True:
stop_looping = myAlertCheck()
if stop_looping:
break
time.sleep(interval)
The sleep gives you CPU time for other tasks.
EDIT
Ok, I’m not sure what exactly your question is. First I thought you wanted to know how to let python ‘wait’ for an event. Now it seems you want to know how to compare event dates with the current date.
I think the following is a more complete approach. I think you can fill in the details yourself??
import time
from datetime import datetime
interval = 3 # nr of seconds
events = {
'Game Night': '14:00 2013-06-23',
'3CB vs ST3 Match': '18:45 2013-07-02',
'Website Maintainance': '13:00 2013-07-16',
}
def myAlertCheck(events):
for title, event_date in events.iteritems():
ed = datetime.strptime(event_date, '%H:%M %Y-%m-%d')
delta_s = (datetime.now() - ed).seconds
if delta_s < (15 * 60):
print 'within 15 minutes %s starts' % title
return True
while True:
stop_looping = myAlertCheck(events)
if stop_looping:
break
time.sleep(interval)
4
solved Python – Do (something) when event is near [closed]