Last active
June 4, 2020 14:44
-
-
Save phizaz/30c0a7974c7cfb2367a4928a7d29e4f4 to your computer and use it in GitHub Desktop.
Blocks until a given time (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
blocks until a specific time, | |
useful for planning to run a script at a specific time | |
usage: | |
python til.py 13:00 tomorrow && python script.py | |
""" | |
import dateparser | |
from datetime import datetime, timedelta | |
import time | |
import argparse | |
parser = argparse.ArgumentParser(description='Block until run time') | |
parser.add_argument('time', type=str, nargs='+') | |
args = parser.parse_args() | |
run_time = ' '.join(args.time) | |
tgt = dateparser.parse(run_time) | |
print('will run at:', tgt) | |
while True: | |
now = dateparser.parse('now') | |
if tgt < now: break | |
print('wait for:', tgt - now) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment