Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import taskw as tw
  2. import argparse
  3.  
  4. parser = argparse.ArgumentParser(description='Import TODOs from a coding file and add them to taskwarrior')
  5. parser.add_argument('--file', dest='f', help='input file')
  6. parser.add_argument('--project', dest='project', help='project name')
  7. args = parser.parse_args()
  8.  
  9. f = args.f
  10. project = args.project
  11. # ======================================================================================== #
  12.  
  13. file_name = f.split('/')[-1]
  14.  
  15. if f.split(".")[-1] == "tex":
  16. tag = ','.join(['writing', file_name])
  17. else:
  18. tag = ','.join(['coding', file_name])
  19.  
  20. w = tw.TaskWarrior()
  21.  
  22. # get already existing tasks
  23. tasks = w.load_tasks()
  24. tasks = tasks['pending']
  25. old_tasks = []
  26. for item in tasks:
  27. if 'tags' in item.keys():
  28. if file_name in item['tags']:
  29. old_tasks.append(item['description'])
  30.  
  31. with open(f, 'r') as cf:
  32. for line in cf:
  33. if '# TODO ' in line:
  34. new_tasks = line.strip('# TODO').strip('\n')
  35. if 'due:' in new_tasks and new_tasks not in old_tasks:
  36. due = new_tasks.split("due:")[-1]
  37. w.task_add(new_tasks, project=project, tag=tag, due=due)
  38. else:
  39. if new_tasks not in old_tasks:
  40. w.task_add(new_tasks, project=project, tag=tag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement