1 |
#!/usr/bin/env python |
2 |
|
3 |
# $Id: todoBodyMake.py,v 1.4 2005/01/24 07:11:15 paultcochrane Exp $ |
4 |
|
5 |
import xml.dom.minidom |
6 |
import re |
7 |
import time |
8 |
|
9 |
# the head string for the .part page |
10 |
headString = '<!-- $' |
11 |
headString += 'Id' |
12 |
headString += '$ -->\n' |
13 |
headString += ' <h1>Todo list</h1>\n' |
14 |
headString += ' <hr class="top" />\n' |
15 |
|
16 |
# open the todo file |
17 |
f = open('../../.todo','r') |
18 |
|
19 |
# parse the document |
20 |
doc = xml.dom.minidom.parse(f) |
21 |
|
22 |
# close the todo file (like a good little boy) |
23 |
f.close() |
24 |
|
25 |
# grab all of the <note> elements |
26 |
notes = doc.getElementsByTagName('note') |
27 |
|
28 |
# regular expression objects for the whitespace at the start and end |
29 |
# of strings respectively |
30 |
r1 = re.compile(r'^\s+') |
31 |
r2 = re.compile(r'\s+$') |
32 |
|
33 |
# the html string object for the 'done' items |
34 |
doneHtml = ''' |
35 |
<h2>Completed todo items</h2> |
36 |
<table class="todo"> |
37 |
<tr> |
38 |
<th class="description">Task description</th> |
39 |
<th class="dateAdded">Date added</th> |
40 |
<th class="dateCompleted">Date completed</th> |
41 |
<th class="comment">Comment</th> |
42 |
</tr> |
43 |
''' |
44 |
|
45 |
# the html string for the 'todo' items |
46 |
todoHtml = ''' |
47 |
<h2>Todo items</h2> |
48 |
<table class="todo"> |
49 |
<tr> |
50 |
<th class="description">Task description</th> |
51 |
<th class="dateAdded">Date added</th> |
52 |
<th class="priority">Priority</th> |
53 |
</tr> |
54 |
''' |
55 |
|
56 |
for note in notes: |
57 |
# if the thing is done, store what it was, when it was finished, |
58 |
# and the comment |
59 |
if note.hasAttribute('done'): |
60 |
# grab the attributes |
61 |
startTime = note.getAttribute('time') |
62 |
startTime = time.strftime('%Y-%m-%d',time.localtime(float(startTime))) |
63 |
doneTime = note.getAttribute('done') |
64 |
doneTime = time.strftime('%Y-%m-%d',time.localtime(float(doneTime))) |
65 |
priority = note.getAttribute('priority') |
66 |
# grab the note text |
67 |
noteText = note.firstChild.nodeValue |
68 |
noteText = r1.sub('',noteText) |
69 |
noteText = r2.sub('',noteText) |
70 |
# grab the comment text |
71 |
comments = note.getElementsByTagName('comment') |
72 |
commentNode = comments[0] |
73 |
commentText = commentNode.firstChild.nodeValue |
74 |
commentText = r1.sub('',commentText) |
75 |
commentText = r2.sub('',commentText) |
76 |
|
77 |
# now generate the html for 'done' items |
78 |
doneHtml += "<tr class=\"done\">\n" |
79 |
doneHtml += " <td class=\"description\">%s</td>\n" % noteText |
80 |
doneHtml += " <td class=\"dateAdded\">%s</td>\n" % startTime |
81 |
doneHtml += " <td class=\"dateCompleted\">%s</td>\n" % doneTime |
82 |
doneHtml += " <td class=\"comment\">%s</td>\n" % commentText |
83 |
doneHtml += "</tr>\n" |
84 |
|
85 |
else: |
86 |
# grab the attributes |
87 |
startTime = note.getAttribute('time') |
88 |
startTime = time.strftime('%Y-%m-%d',time.localtime(float(startTime))) |
89 |
priority = note.getAttribute('priority') |
90 |
# grab the note text |
91 |
noteText = note.firstChild.nodeValue |
92 |
noteText = r1.sub('',noteText) |
93 |
noteText = r2.sub('',noteText) |
94 |
|
95 |
# now generate the html for the 'todo' items |
96 |
todoHtml += "<tr class=\"%s\">\n" % priority |
97 |
todoHtml += " <td class=\"description\">%s</td>\n" % noteText |
98 |
todoHtml += " <td class=\"dateAdded\">%s</td>\n" % startTime |
99 |
todoHtml += " <td class=\"priority\">%s</td>\n" % priority |
100 |
todoHtml += "</tr>\n" |
101 |
|
102 |
# finish off the html elements |
103 |
doneHtml += "</table>\n" |
104 |
todoHtml += "</table>\n" |
105 |
|
106 |
# generate the html string to print |
107 |
todoBodyPartHtml = headString + todoHtml + doneHtml |
108 |
|
109 |
# write the html to file |
110 |
f = open("todo_body.part","w") |
111 |
f.write(todoBodyPartHtml) |
112 |
f.close() |
113 |
|
114 |
|