Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement