diff --git a/do_tasks.py b/do_tasks.py new file mode 100644 index 0000000..2867e9f --- /dev/null +++ b/do_tasks.py @@ -0,0 +1,32 @@ +''' +Execute the contents of all .task files forever. +''' +import os +import sys +import time + +def main(args=None): + if args: + task_files = args + do_loop = False + else: + do_loop = True + + while True: + if do_loop: + task_files = [f for f in os.listdir() if (os.path.isfile(f) and f.endswith('.task'))] + for task_file in task_files: + with open(task_file, 'r', encoding='utf-8') as handle: + task_content = handle.read() + task_content = task_content.strip() + print('TASK:', task_content) + status = os.system(task_content) + if status == 0: + os.remove(task_file) + if not do_loop: + break + time.sleep(10) + + +if __name__ == '__main__': + raise SystemExit(main(sys.argv[1:])) diff --git a/taskme.py b/taskme.py new file mode 100644 index 0000000..3605d33 --- /dev/null +++ b/taskme.py @@ -0,0 +1,22 @@ +''' +Create a task file to be executed by do_tasks. + +Usage: +taskme command arg1 arg2 +''' +import sys +import time +import random +import os + +if len(sys.argv) < 2: + raise ValueError() + +task_command = ' '.join('"%s"' % arg for arg in sys.argv[1:]) +task_command = f'cd /d {os.getcwd()} & {task_command}' + +timestamp = f'{time.time()}'.replace('.', '').ljust(18, '0') +filename = f'C:\\tasks\\{timestamp}-{random.randint(1, 1000000)}.task' + +with open(filename, 'w', encoding='utf-8') as handle: + handle.write(task_command)