3 from dateutil.parser import parse
5 import dateutil.tz as tz
8 from mako.template import Template
11 print >>sys.stderr, "Usage: %s TEMPLATE [WEEK]"
14 template = sys.argv[1]
15 START = datetime.datetime(2009, 12, 21, 6)
17 if len(sys.argv) == 3:
18 week = parse(sys.argv[2], default=START)
22 with open('out/report.yml') as r:
23 report = yaml.safe_load(r)
25 with open('bloggers.yml') as f:
26 users = yaml.safe_load(f)
28 week = (week - START).days / 7
29 week_start = START + (week * datetime.timedelta(7))
30 week_end = START + ((week + 1) * datetime.timedelta(7))
40 for (un, rec) in users.items():
43 u.links = rec['links']
44 u.start = rec['start']
45 u.weeks = report.get(un, [])
50 return (u.start, u.username)
52 userlist.sort(key=user_key)
55 user_start = parse(u.start, default=START)
56 if user_start > week_start:
58 elif len(u.weeks) <= week or not u.weeks[week]:
63 print Template(filename=template, output_encoding='utf-8').render(
64 week=week, week_start=week_start,week_end=week_end,
65 good=good, lame=lame, skip=skip, userlist=userlist)