3 from dateutil.parser import parse
5 import dateutil.tz as tz
10 from mako.template import Template
12 START = datetime.datetime(2009, 12, 21, 6)
13 HERE = os.path.dirname(__file__)
15 def render_template(path, week=None):
16 with open('out/report.yml') as r:
17 report = yaml.safe_load(r)
19 with open('bloggers.yml') as f:
20 users = yaml.safe_load(f)
22 week = parse(week, default=START)
26 week = (week - START).days / 7
27 week_start = START + (week * datetime.timedelta(7))
28 week_end = START + ((week + 1) * datetime.timedelta(7))
38 for (un, rec) in users.items():
41 u.links = rec['links']
42 u.start = rec['start']
43 u.end = rec.get('end')
44 u.weeks = report.get(un, [])
49 return (u.start, u.username)
51 userlist.sort(key=user_key)
54 user_start = parse(u.start, default=START)
55 if u.end and parse(u.end, default=START) <= week_start:
58 if user_start > week_start:
60 elif len(u.weeks) <= week or not u.weeks[week]:
65 p = subprocess.Popen(['ledger', '-f', os.path.join(HERE,'ledger'),
66 '-n', 'balance', 'Pool'],
67 stdout=subprocess.PIPE)
68 (out, _) = p.communicate()
69 pool = int(out.split()[0][1:])
71 return Template(filename=path, output_encoding='utf-8').render(
72 week=week, week_start=week_start,week_end=week_end,
73 good=good, lame=lame, skip=skip, userlist=userlist,
76 if __name__ == '__main__':
78 print >>sys.stderr, "Usage: %s TEMPLATE [WEEK]"
81 template = sys.argv[1]
83 if len(sys.argv) > 2: week = sys.argv[2]
84 print render_template(template, week)