From: Nelson Elhage Date: Mon, 28 Dec 2009 23:41:20 +0000 (-0500) Subject: show-week: use a mako template X-Git-Url: https://projects.mako.cc/source/iron-blogger/commitdiff_plain/364ecc7623bd4a3940ca1876d639777471df0de4?hp=32e6bed76a40a5464923cd78ce0ff8be5146f98e show-week: use a mako template Add a template for sending email, as well. --- diff --git a/show-week.py b/show-week.py index 79dc4bc..3aecb57 100644 --- a/show-week.py +++ b/show-week.py @@ -3,6 +3,7 @@ from dateutil.parser import parse import datetime import dateutil.tz as tz import sys +from mako.template import Template 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)) +good = [] +lame = [] +skip = [] + 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]: - print "LAME %s" % (name,) + lame.append(name) 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 index 0000000..106141c --- /dev/null +++ b/templates/email.txt @@ -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