From c631489c69e4f820bd2469d44ab2b17295f6a341 Mon Sep 17 00:00:00 2001 From: Nelson Elhage Date: Tue, 29 Dec 2009 14:05:36 -0500 Subject: [PATCH] Generalize show-week slightly. --- show-week.py | 47 +++++++++++++++++++++++++++++++++++---------- templates/email.txt | 9 ++++----- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/show-week.py b/show-week.py index 0f8ab69..d5c9e51 100755 --- a/show-week.py +++ b/show-week.py @@ -4,35 +4,62 @@ from dateutil.parser import parse import datetime import dateutil.tz as tz import sys +import os from mako.template import Template +if len(sys.argv) < 2: + print >>sys.stderr, "Usage: %s TEMPLATE [WEEK]" + sys.exit(1) + +template = sys.argv[1] START = datetime.datetime(2009, 12, 21, 6) +if len(sys.argv) == 3: + week = parse(sys.argv[2], default=START) +else: + week = START + with open('out/report.yml') as r: report = yaml.safe_load(r) with open('bloggers.yml') as f: users = yaml.safe_load(f) -week = (parse(sys.argv[1], default=START) - START).days / 7 +week = (week - START).days / 7 week_start = START + (week * datetime.timedelta(7)) week_end = START + ((week + 1) * datetime.timedelta(7)) good = [] lame = [] skip = [] +userlist = [] +class User(object): + pass -for (name, weeks) in report.items(): - user_start = parse(users[name]['start'], default=START) +for (un, rec) in users.items(): + u = User() + u.username = un + u.links = rec['links'] + u.start = rec['start'] + u.weeks = report.get(un, []) + + userlist.append(u) + +def user_key(u): + return (u.start, u.username) + +userlist.sort(key=user_key) + +for u in userlist: + user_start = parse(u.start, default=START) if user_start > week_start: - skip.append(name) - continue - elif len(weeks) <= week or not weeks[week]: - lame.append(name) + skip.append(u) + elif len(u.weeks) <= week or not u.weeks[week]: + lame.append(u) else: - good.append(name) + good.append(u) -print Template(filename=sys.argv[2], output_encoding='utf-8').render( +print Template(filename=template, 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) + good=good, lame=lame, skip=skip, userlist=userlist) diff --git a/templates/email.txt b/templates/email.txt index 741e373..16d7a57 100644 --- a/templates/email.txt +++ b/templates/email.txt @@ -3,9 +3,8 @@ To: iron-blogger@mit.edu People who posted: % for u in sorted(good): -<% posts = report[u][week] %>\ - ${u}: - % for p in posts: + ${u.username}: + % for p in u.weeks[week]: - ${p['url']} % endfor % endfor @@ -13,12 +12,12 @@ People who posted: People who failed to post: <% cash = 0 %>\ % for u in sorted(lame): - ${u} + ${u.username} % endfor People who have not yet started: % for u in sorted(skip): - ${u} + ${u.username} % endfor Beer pool: