forked from benjaminrose/TaskPaper-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpp.py
More file actions
109 lines (89 loc) · 3 KB
/
tpp.py
File metadata and controls
109 lines (89 loc) · 3 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
#
# TaskPaper Parser
# K. Marchand 2014
#
from datetime import datetime, timedelta
from collections import namedtuple
from dateutil import parser
import sys
import re
tpfile = sys.argv[1]
with open(tpfile, encoding='utf-8') as f:
tplines = f.readlines()
Flagged = namedtuple('Flagged', ['type', 'taskdate', 'project', 'task'])
flaglist = []
errlist = []
done_count = 0
na_count = 0
total_count = 0
project = ''
for line in tplines:
try:
if ':\n' in line:
project = line.strip()[:-1]
elif '@done' in line:
done_count = done_count + 1
elif '@due' in line:
na_count = na_count + 1
duetag = re.search(r'\@due\((.*?)\)', line).group(1)
taskdate = datetime.date(parser.parse(duetag))
flaglist.append(
Flagged('due', taskdate, project, line.strip()[2:]))
elif '@start' in line:
na_count = na_count + 1
starttag = re.search(r'\@start\((.*?)\)', line).group(1)
taskdate = datetime.date(parser.parse(starttag))
flaglist.append(
Flagged('start', taskdate, project, line.strip()[2:]))
elif '@today' in line:
na_count = na_count + 1
flaglist.append(
Flagged('today', datetime.now(), project, line.strip()[2:]))
elif '☐' in line:
na_count = na_count + 1
except Exception as e:
errlist.append((line, e))
today = overdue = duethisweek = startthisweek = None
today_date = datetime.date(datetime.now())
print('SUMMARY for {0} [{1}]'.format(tpfile, str(datetime.now())[:16]))
total_count = na_count + done_count
print('\n{0} of {1} tasks done, {2} tasks open'.format(done_count, total_count, na_count))
print('\nTODAY\n')
for task in flaglist:
if task.type == 'today':
today = True
print('\t[%s] %s' % (task.project, task.task))
elif task.type == 'due' and today_date == task.taskdate:
today = True
print('\t[%s] %s' % (task.project, task.task))
if not today:
print('\t (none)')
print('\nOVERDUE\n')
for task in flaglist:
if task.type == 'due' and today_date > task.taskdate:
overdue = True
print('\t[%s] %s' % (task.project, task.task))
if not overdue:
print('\t (none)')
print('\nDUE THIS WEEK\n')
for task in flaglist:
weeklater = today_date + timedelta(days=7)
if task.type == 'due' and today_date < task.taskdate < weeklater:
duethisweek = True
print('\t[%s] %s' % (task.project, task.task))
if not duethisweek:
print('\t (none)')
print('\nSTARTING THIS WEEK\n')
for task in flaglist:
weeklater = today_date + timedelta(days=7)
if task.type == 'start' and today_date < task.taskdate < weeklater:
startthisweek = True
print('\t[%s] %s' % (task.project, task.task))
if not startthisweek:
print('\t (none)')
if len(errlist) != 0:
print('\nERROR PARSING THESE LINES\n')
for errtask in errlist:
print('\t%s' % str(errtask))
print('\n')