What I want to do in a python script is sleep a number of seconds until the required time is reached. IE: if runAt setting is 15:20 and current time is 10:20, how can I wor
Here is a solution. This is independent of date because the new date-time "end2" has same date as current date-time and at the same time the date-time format is not changed.
from datetime import datetime #this is the way to import a module named datetime...
import time #this module is used to sleep
import pause
a = (datetime.now()) #a = '2017-07-27 00:10:00.107000' #for example
print 'the time is'
print a
end2 = a.replace(hour = 15, minute = 20, second = 00)
delta = end2 - a
print delta # prints: 5:00:00
print delta.total_seconds() # prints: 114605.0
pause.seconds(delta.total_seconds())
You could instead use the pause
package [ https://pypi.python.org/pypi/pause/0.1.2 ]. Taking an example from their documentation -
import pause, datetime
dt = datetime.datetime(2013, 6, 2, 14, 36, 34, 383752)
pause.until(dt)