- attachment:remind-tracker.py of TodoTemplate
Attachment 'remind-tracker.py'
Download 1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # INSERT YOUR ADDRESS HERE
5 recipient = ["Nikolaus@rath.org"]
6
7 # Roundup boto uses several deprecated modules
8 import warnings
9 warnings.filterwarnings("ignore", "", DeprecationWarning, "roundup")
10
11 import sys
12 from roundup import instance
13 from roundup.date import Date,Interval
14 from roundup.mailer import Mailer
15 import quopri
16 from StringIO import StringIO
17
18 # open the instance
19 if len(sys.argv) != 2:
20 print 'You need to specify an instance home dir'
21 instance_home = sys.argv[1]
22 instance = instance.open(instance_home)
23 db = instance.open('admin')
24
25 done_id = db.status.lookup("done")
26 waiting_id = db.status.lookup("waiting")
27 other_id = [x for x in db.status.list() if x != done_id]
28
29 # Determine current date, but with time 0:00:00
30 now = Date(Date(".").pretty('%Y-%m-%d'))
31
32 # Collect the Issues
33 issues = []
34 for kid in db.keyword.list():
35 for sid in db.issue.filter(None, { "due_date": "-1m;6d",
36 "keyword": kid,
37 "status": other_id},
38 [ ("+", "due_date") ]):
39 # Exclude issues which are still waiting for their
40 # revival date
41 if db.issue.get(sid, "status") == waiting_id and \
42 not db.issue.get(sid, "superseder"):
43 None # Do nothing
44 else:
45 issues.append( (sid,
46 db.keyword.get(kid, "name"),
47 db.issue.get(sid, "title"),
48 db.issue.get(sid, "due_date") - now ))
49
50 # Send Mail
51 if issues:
52 body = StringIO()
53
54 print >>body, "The following issues are due within the next 5 days.\n"
55 print >>body, "%4s %-49s %-13s" % ("ID", "Title", "Due")
56 print >>body, "-" * 68
57
58 old = ""
59 for issue in issues:
60 id,keyword,title,date = issue
61 if keyword != old:
62 print >>body, "\n *** " + keyword + " ***"
63 old = keyword
64
65 print >>body, "%4s %-49s %-13s" % (id,title,date.pretty())
66
67
68 mailer = Mailer(db.config)
69
70 # To work around a Python bug, we had to change
71 #self.smtp_send(to, str(message))
72 # to
73 #self.smtp_send(to, message.as_string(unixfrom=False))
74 # in roundup/mailer.py, line 120 (in standard_message())
75 mailer.standard_message(recipient, "Issues due within the next 5 days",
76 body.getvalue())
77
78 db.commit()
79 db.close()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.