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's a solution that uses the Arrow module:
def wait_until(specified_dt: arrow.Arrow) -> None:
"""Stay in a loop until the specified date and time."""
# Initially check every 10 seconds.
refresh = 10
current_dt = arrow.utcnow()
while current_dt < specified_dt:
# Check every millisecond if close to the specified time.
current_dt = arrow.utcnow()
if (specified_dt - current_dt).seconds < 11:
refresh = .001
time.sleep(refresh)