sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #02682
Re: [Question #156488]: Sleep function for certain time of day
Question #156488 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/156488
Status: Open => Answered
RaiMan proposed the following answer:
since the modul time is already imported by Sikuli initialization, her a solution, that uses only features from that modul.
see details here: http://docs.python.org/library/time.html#module-time
I packed it in a def(), so it is reusable. If you don't want it verbose, just delete/comment out the print statements.
If you want to wait for a time on another day in the future, it should be easy to adapt this accordingly.
This waits until the given time today, when started.
def sleepUntil(h, m, s=0):
a = time.localtime()
at = time.mktime(a)
print "now: ", a
b = time.struct_time((a[0], a[1], a[2], h, m, s, 0, 0, a[-1]));
bt = time.mktime(b)
print "until: ", b
diff = bt-at
print "seconds to wait: ", diff
wait(diff)
I use wait() instead of sleep(), since sleep() is deprecated.
usage examples: (the parameters have to be numbers!)
sleepUntil(14, 30) # waits until 14:30:00
sleepUntil(14, 30, 30) # waits until 14:30:30
hope it helps.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.