3 from dateutil.parser import parse
5 import dateutil.tz as tz
8 from mako.template import Template
10 START = datetime.datetime(2009, 12, 21, 6)
12 def render_template(path, week=None):
13 with open('out/report.yml') as r:
14 report = yaml.safe_load(r)
16 with open('bloggers.yml') as f:
17 users = yaml.safe_load(f)
19 week = parse(week, default=START)
23 week = (week - START).days / 7
24 week_start = START + (week * datetime.timedelta(7))
25 week_end = START + ((week + 1) * datetime.timedelta(7))
35 for (un, rec) in users.items():
38 u.links = rec['links']
39 u.start = rec['start']
40 u.weeks = report.get(un, [])
45 return (u.start, u.username)
47 userlist.sort(key=user_key)
50 user_start = parse(u.start, default=START)
51 if user_start > week_start:
53 elif len(u.weeks) <= week or not u.weeks[week]:
58 return Template(filename=path, output_encoding='utf-8').render(
59 week=week, week_start=week_start,week_end=week_end,
60 good=good, lame=lame, skip=skip, userlist=userlist)
62 if __name__ == '__main__':
64 print >>sys.stderr, "Usage: %s TEMPLATE [WEEK]"
67 template = sys.argv[1]
69 if len(sys.argv) > 2: week = sys.argv[2]
70 print render_template(template, week)