]> projects.mako.cc - iron-blogger/commitdiff
show-week: use a mako template
authorNelson Elhage <nelhage@mit.edu>
Mon, 28 Dec 2009 23:41:20 +0000 (18:41 -0500)
committerNelson Elhage <nelhage@mit.edu>
Mon, 28 Dec 2009 23:41:20 +0000 (18:41 -0500)
Add a template for sending email, as well.

show-week.py
templates/email.txt [new file with mode: 0644]

index 79dc4bc955609326263efc351a4041f50785a609..3aecb57d289e339715a1c0d4d3f7515902ff6b80 100644 (file)
@@ -3,6 +3,7 @@ from dateutil.parser import parse
 import datetime
 import dateutil.tz as tz
 import sys
 import datetime
 import dateutil.tz as tz
 import sys
+from mako.template import Template
 
 START = datetime.datetime(2009, 12, 21, 6)
 
 
 START = datetime.datetime(2009, 12, 21, 6)
 
@@ -16,13 +17,21 @@ week = (parse(sys.argv[1], default=START) - START).days / 7
 week_start = START + (week * datetime.timedelta(7))
 week_end   = START + ((week + 1) * datetime.timedelta(7))
 
 week_start = START + (week * datetime.timedelta(7))
 week_end   = START + ((week + 1) * datetime.timedelta(7))
 
+good = []
+lame = []
+skip = []
+
 
 for (name, weeks) in report.items():
     user_start = parse(users[name]['start'], default=START)
     if user_start > week_start:
 
 for (name, weeks) in report.items():
     user_start = parse(users[name]['start'], default=START)
     if user_start > week_start:
-        print "SKIP %s" % (name,)
+        skip.append(name)
         continue
     elif len(weeks) <= week or not weeks[week]:
         continue
     elif len(weeks) <= week or not weeks[week]:
-        print "LAME %s" % (name,)
+        lame.append(name)
     else:
     else:
-        print "OK %s" % (name,)
+        good.append(name)
+
+print Template(filename=sys.argv[2], output_encoding='utf-8').render(
+    week=week, week_start=week_start,week_end=week_end,
+    good=good, lame=lame, skip=skip, users=users, report=report)
diff --git a/templates/email.txt b/templates/email.txt
new file mode 100644 (file)
index 0000000..106141c
--- /dev/null
@@ -0,0 +1,26 @@
+Subject: IRON BLOGGER results for the week of ${week_start.strftime("%F")}
+To: iron-blogger@mit.edu
+
+People who posted:
+% for u in sorted(good):
+<% posts = report[u][week] %>\
+ ${u}:
+ % for p in posts:
+ - ${p['url']}
+ % endfor
+% endfor
+
+People who failed to post:
+<% cash = 0 %>\
+% for u in sorted(lame):
+ ${u}
+% endfor
+
+People who have not yet started:
+% for u in sorted(skip):
+ ${u}
+% endfor
+
+Beer pool:
+This week: $${5 * len(lame)}.00
+Total:     $.00

Benjamin Mako Hill || Want to submit a patch?