From 7d4e518a242a82021d2418f7ef85f59e0008697d Mon Sep 17 00:00:00 2001 From: Bernhard Brunner Date: Fri, 15 Jun 2018 14:51:46 +0200 Subject: [PATCH 1/2] Headup time in days added tag: "h:" --- futureTasks | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/futureTasks b/futureTasks index 3d34d32d..b371c283 100755 --- a/futureTasks +++ b/futureTasks @@ -1,35 +1,53 @@ #!/usr/bin/env python - """ 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 +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 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()] + # get pattern of the form h:{days} if present + hmatch = hpattern.search(line) + if hmatch: + headup = int(hmatch.groups()[0]) + else: + headup = 0 -def main(args=None): - now = 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()) - else: - print(line.strip()) - return True + if datetime.datetime(*threshold) < now + \ + datetime.timedelta(days=headup): + print(line.strip()) + else: + print(line.strip()) + return True if __name__ == "__main__": - status = not main(sys.argv) - sys.exit(status) + status = not main(sys.argv) + sys.exit(status) From 826ecdfde519a009c4a37709586f678daf0b4826 Mon Sep 17 00:00:00 2001 From: Bernhard Brunner Date: Wed, 27 May 2020 14:38:20 +0200 Subject: [PATCH 2/2] Added h:{days} headup syntax Added Usage Added Error handling for invalid date syntax in t:{date} field --- futureTasks | 56 ++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/futureTasks b/futureTasks index b371c283..0043753f 100755 --- a/futureTasks +++ b/futureTasks @@ -1,11 +1,12 @@ #!/usr/bin/env python + """ filter incoming lines based on date threshold 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. +this is intended to be used as TODOTXT_FINAL_FILTER """ import sys @@ -19,35 +20,38 @@ hpattern = re.compile(r"h:(\d+)") def usage(): - print('futureTasks threshold markers are of the form \ + 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()] - - # get pattern of the form h:{days} if present - hmatch = hpattern.search(line) - if hmatch: - headup = int(hmatch.groups()[0]) - else: - headup = 0 - - if datetime.datetime(*threshold) < now + \ - datetime.timedelta(days=headup): - print(line.strip()) - else: - print(line.strip()) - return True + 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()] + + # 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 if __name__ == "__main__": - status = not main(sys.argv) - sys.exit(status) + status = not main(sys.argv) + sys.exit(status)