-
Notifications
You must be signed in to change notification settings - Fork 1
/
tp-due
executable file
·66 lines (63 loc) · 2.13 KB
/
tp-due
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
""" pull out @due times from supplied taskpaper files
"""
import fileinput
import os
import re
import sys
from datetime import date, datetime
from termcolor import colored
re_due = re.compile(r'@(due|followup)(\(([^\)]+)\))?')
re_done = re.compile(r'@(done|cancelled)(\(([^\)]+)\))?')
re_na = re.compile(r'@na\b')
re_today = re.compile(r'@today\b')
if __name__ == "__main__":
due_list = []
now = datetime.fromordinal(date.today().toordinal())
next_step = now.replace(second=1)
for line in fileinput.input():
#print "due %s" % re_due.search(line)
if re_done.search(line):
continue
match = re_due.search(line)
if match:
if match.group(3):
# there was a date supplied
try:
due_date = datetime.strptime(match.group(3), "%Y-%m-%d")
except ValueError:
print >> sys.stderr, "Can't parse '%s', using today" % \
(match.group(3),)
due_date = now
else:
due_date = now
elif re_today.search(line):
# today
due_date = now
elif re_na.search(line):
# next steps (actions) come right after due today
due_date = next_step
else:
# no @due or @na, unintersting
continue
# add to list
due_list.append((due_date, line, fileinput.filename()))
if len(due_list):
due_list.sort()
for due, item, fname in due_list:
if due < now:
clr = 'red'
elif due == now:
clr = 'magenta'
elif due > next_step:
clr = 'green'
else:
clr = 'yellow'
# print the name of the file, without path or extension
short_name = os.path.basename(fname)
short_name = os.path.splitext(short_name)[0]
base_name = "<%s>" % (os.path.basename(short_name),)
print colored(due.strftime('%Y-%m-%d'), clr), item.strip(), \
base_name
else:
print "nothing due"