Skip to content

Instantly share code, notes, and snippets.

@rmporsch
Created August 29, 2015 09:13
Show Gist options
  • Save rmporsch/2d56047b1b68482715e5 to your computer and use it in GitHub Desktop.
Save rmporsch/2d56047b1b68482715e5 to your computer and use it in GitHub Desktop.
adds TODOs from script to taskwarrior
import taskw as tw
import argparse
parser = argparse.ArgumentParser(description='Import TODOs from a coding file and add them to taskwarrior')
parser.add_argument('--file', dest='f', help='input file')
parser.add_argument('--project', dest='project', help='project name')
args = parser.parse_args()
f = args.f
project = args.project
# ======================================================================================== #
file_name = f.split('/')[-1]
if f.split(".")[-1] == "tex":
tag = ','.join(['writing', file_name])
else:
tag = ','.join(['coding', file_name])
w = tw.TaskWarrior()
# get already existing tasks
tasks = w.load_tasks()
tasks = tasks['pending']
old_tasks = []
for item in tasks:
if 'tags' in item.keys():
if file_name in item['tags']:
old_tasks.append(item['description'])
with open(f, 'r') as cf:
for line in cf:
if '# TODO ' in line:
new_tasks = line.strip('# TODO').strip('\n')
if 'due:' in new_tasks and new_tasks not in old_tasks:
due = new_tasks.split("due:")[-1]
w.task_add(new_tasks, project=project, tag=tag, due=due)
else:
if new_tasks not in old_tasks:
w.task_add(new_tasks, project=project, tag=tag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment