The time
module has a function called asctime
, which might be useful for you:
>>> from time import asctime
>>> asctime()
'Tue Sep 21 17:49:42 2010'
So, you could incorporate something like the following into your code:
sysTime = asctime()
timestamp = systime.split()[3]
separator = timestamp[2]
hour = timestamp.split(separator)[0]
while hour < 8:
# just wait
sysTime = asctime()
timestamp = systime.split()[3]
separator = timestamp[2]
hour = timestamp.split(separator)[0]
# now, it's just become 8:00 AM
while hour < 17: # until 5:00 PM
sysTime = asctime()
timestamp = systime.split()[3]
separator = timestamp[2]
hour = timestamp.split(separator)[0]
# start your thread to do whatever needs to be done
Start this script off once and let it keep running forever.
This is in response to @user428862's question asking if this can be run with "hour > 8 and hour <17". This is how the code would need to be adapted for that purpose:
while 1:
sysTime = asctime()
timestamp = systime.split()[3]
separator = timestamp[2]
hour = timestamp.split(separator)[0]
minute = timestamp.split(separator)[1]
if (hour > 8) and (hour<17 and minute<1):
# start your thread to do whatever needs to be done
Also , it just occurs to me that I have been imploying string splitting and that returns strings, so hour
should be int(timestamp.split(separator)[0])
and so forth