53 lines
1.4 KiB
Python
Executable File
53 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
TAGS = ['t', 'due']
|
|
|
|
def getTag(item):
|
|
if ":" not in item:
|
|
return None
|
|
try:
|
|
sub = re.findall("[^ ]+:\\d\\d\\d\\d-\\d\\d-\\d\\d", item)[0].strip()
|
|
except IndexError:
|
|
return None
|
|
return sub.split(":")
|
|
|
|
def getDate(date):
|
|
return datetime.strptime(date, "%Y-%m-%d")
|
|
|
|
def highlightDate(item):
|
|
full_tag = item[1] + ":" + item[0]
|
|
if getDate(item[0]) < datetime.today():
|
|
#if the date has already passed, wrap with bold/unbold escapes
|
|
item[2] = item[2].replace(full_tag, '\033[1m' + full_tag + '\033[22m')
|
|
return item
|
|
|
|
def relativeDate(item):
|
|
full_tag = item[1] + ":" + item[0]
|
|
difference = getDate(item[0]) - datetime.today()
|
|
item[2] = item[2].replace(full_tag, item[1] + ":" + str(difference.days) + "days")
|
|
return item
|
|
|
|
def main(argv):
|
|
lines = subprocess.check_output(["todo.sh", "list"]).decode(encoding='UTF-8').split('\n')
|
|
items = []
|
|
for line in lines:
|
|
tag = getTag(line)
|
|
if tag is not None:
|
|
items.append([tag[1], tag[0], line])
|
|
|
|
items.sort()
|
|
for i in items:
|
|
if len(argv) > 2 and argv[2] == "rel":
|
|
print(relativeDate(highlightDate(i))[2])
|
|
else:
|
|
print(highlightDate(i)[2])
|
|
|
|
#if __name__ == '__main__':
|
|
main(sys.argv)
|