Created
February 28, 2017 09:48
-
-
Save alexwlchan/d458f14433520d695eacb9364186f2d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- encoding: utf-8 -*- | |
"""I have a TaskPaper file I keep in Dropbox that contains some tasks for my | |
daily routine. | |
This script runs once a day and resets every item on that list, removing | |
the @done tag and replacing the file. | |
""" | |
import os | |
import re | |
# Path to the file containing my daily tasks | |
ROUTINE_FILE = os.path.join( | |
os.environ['HOME'], 'Dropbox', 'taskpaper', 'tasks_daily.taskpaper') | |
# Regex for matching a @done tag | |
DONE_REGEX = re.compile(r' @done(?:\([^\)]+\))?') | |
def remove_done_tag(line): | |
"""Given a line from a TaskPaper document, remove any @done tags.""" | |
return DONE_REGEX.sub('', line).rstrip() | |
def main(): | |
new_lines = [] | |
with open(ROUTINE_FILE, 'r') as infile: | |
for line in infile: | |
new_lines.append(remove_done_tag(line)) | |
with open(ROUTINE_FILE, 'w') as outfile: | |
outfile.write('\n'.join(new_lines)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment