Python Forum

Full Version: want command program: sleep to a specific time
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i would like to find a command program that sleeps, but instead of (or in addition to) sleeping a specified duration, sleep to a specified time or a specified date and time or a specified repeating interval (for example: sleep to next hour) or a specified repeating interval with an offset (for example: sleep to the next 20 minutes into the hour, which at 9:10 would sleep to 9:20) with support for negative offsets (for example: sleep to the next 5 minutes before end of day). i am open to ideas for the command syntax. making this also be a function would be a plus.
import time
import datetime


def calc_duration(s, m=0, h=0, d=0):
    return s + (m * 60) + (h * 3600) + (d * 3600 * 24)


def duration_until(target_datetime):
    """
    Here you need to add tzinfo, otherwise it would e wrong
    Maybe use another better module
    # look for http://arrow.readthedocs.io/en/latest/
    # or just read the documantation of datetime: https://docs.python.org/3/library/datetime.html
    """
    return (target_datetime - datetime.datetime.now()).seconds


duration = calc_duration(s=5, m=1)
time.sleep(duration)
Linux at command?
(Jul-10-2017, 08:34 PM)wavic Wrote: [ -> ]Linux at command?

this is not really a sleep type of command.  it is more of an interactive cronjob type of thing.  but has a nice time-forward text interpreter that could be a plus as a python function (given a datetime value and the text to interpret, return an updated datetime value).