Esempio n. 1
0
def launch(t):
    lt = time.localtime(t)
    hour, min, sec = ('{:02}'.format(i) for i in [lt.tm_hour, lt.tm_min, lt.tm_sec])
    # os.environ['DISPLAY'] = ':0.0' # have to set this explicitly if
    # invoked by cron.
    util.playsound()
    pingpath = os.path.join(settings.path, 'ping.py')
    cmd = settings.get_xt_cmd(
        'TagTime {hour}:{min}:{sec}'.format(hour=hour, min=min, sec=sec),
        pingpath, str(t))
    util.callcmd(cmd)
Esempio n. 2
0
print("TagTime is watching you! Last ping would've been", tdelta, "ago.", file=sys.stderr)

start = time.time()
i = 1

while True:
    # sleep till next ping but check again in at most a few seconds in
    # case computer was off (should be event-based and check upon wake).
    # Use the pause library to get better precision
    pause.until(nextping)
    # time.sleep(util.clip(nextping - time.time(), 0, 2))
    now = time.time()

    if nextping <= now:
        if settings.catchup or nextping > now - settings.retrothresh:
            util.playsound()

        # invokes popup for this ping plus additional popups if there were more
        #   pings while answering this one:
        cmd = [os.path.join(settings.path, "launch.py"), "quiet", "&"]
        util.callcmd(cmd)
        s = "{i: 4}: PING! gap {gap} avg {avg} tot {tot}".format(
            i=i,
            gap=datetime.timedelta(seconds=nextping - lastping),
            avg=datetime.timedelta(seconds=(0.0 + time.time() - start) / i),
            tot=datetime.timedelta(seconds=(0.0 + time.time() - start)),
        )
        print(util.annotime(s, nextping, 72), file=sys.stderr)

        lastping = nextping
        nextping = rand.nextping(nextping)