Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headup h:{days} syntax, usage and date error handling #14

Open
wants to merge 2 commits into
base: extensions
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions futureTasks
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,50 @@
"""
filter incoming lines based on date threshold

hides tasks marked with a date threshold ("t:YYYY-MM-DD") in the future
Threshold markers are of the form "t:YYYY-MM-DD".
A headup h:DD will start showing DD days ahead of the t: date.

this is intended to be used as TODOTXT_FINAL_FILTER
"""

import sys
import re

from datetime import datetime
import datetime


pattern = re.compile(r"t:(\d{4})-(\d{2})-(\d{2})")
hpattern = re.compile(r"h:(\d+)")


def main(args=None):
now = datetime.now()
def usage():
print('futureTasks threshold markers are of the form \
"t:YYYY-MM-DD [h:{days}]"')


def main(argv):
if len(argv) > 1 and argv[1] == "usage":
usage()
sys.exit(2)
now = datetime.datetime.now()
for line in sys.stdin:
match = pattern.search(line)
if match:
threshold = [int(i) for i in match.groups()]
if datetime(*threshold) < now:
print(line.strip())

# get pattern of the form h:{days} if present
hmatch = hpattern.search(line)
if hmatch:
headup = int(hmatch.groups()[0])
else:
headup = 0

try:
if datetime.datetime(*threshold) < now + \
datetime.timedelta(days=headup):
print(line.strip())
except ValueError:
print('ERROR: invalid date in line ' + line)
else:
print(line.strip())
return True
Expand Down