Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """I have a TaskPaper file I keep in Dropbox that contains some tasks for my
  4. daily routine.
  5.  
  6. This script runs once a day and resets every item on that list, removing
  7. the @done tag and replacing the file.
  8.  
  9. """
  10.  
  11. import os
  12. import re
  13.  
  14. # Path to the file containing my daily tasks
  15. ROUTINE_FILE = os.path.join(
  16. os.environ['HOME'], 'Dropbox', 'taskpaper', 'tasks_daily.taskpaper')
  17.  
  18. # Regex for matching a @done tag
  19. DONE_REGEX = re.compile(r' @done(?:\([^\)]+\))?')
  20.  
  21.  
  22. def remove_done_tag(line):
  23. """Given a line from a TaskPaper document, remove any @done tags."""
  24. return DONE_REGEX.sub('', line).rstrip()
  25.  
  26.  
  27. def main():
  28. new_lines = []
  29. with open(ROUTINE_FILE, 'r') as infile:
  30. for line in infile:
  31. new_lines.append(remove_done_tag(line))
  32. with open(ROUTINE_FILE, 'w') as outfile:
  33. outfile.write('\n'.join(new_lines))
  34.  
  35.  
  36. if __name__ == '__main__':
  37. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement