forked from PyCon/pc-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
45 lines (36 loc) · 1.19 KB
/
Copy pathreport.py
File metadata and controls
45 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Report on a meeting's decisions::
python report.py talks.json [first]
Prints a summarized report of the votes on each talk starting at the talk with
ID ``first``. If not given, sumarize all talks.
Originally written by Luciano Ramalho and Steve Holden (see
https://gist.github.com/1354185).
"""
import sys
import json
from textwrap import TextWrapper
wrapper = TextWrapper(width=55)
LINE_FORMAT = '{id:>3} {mark:>8} {yay:>3} {nay:>3} {abstain:>3} {name}'
with open(sys.argv[1]) as json_in:
talks = json.load(json_in)
index = 0
try:
first = int(sys.argv[2])
except (IndexError, ValueError):
pass
else:
while talks[index]['id'] != first:
index += 1
print LINE_FORMAT.format(id='ID', mark='DECISION', yay='YAY', nay='NAY', abstain='ABS', name='TITLE')
for talk in talks[index:]:
if 'decision' not in talk:
break
else:
mark = talk['decision'][0:6]
votes = talk['votes'] if 'votes' in talk else dict(yay=0, nay=0, abstain=0)
talk.update(votes)
namelist = wrapper.wrap(talk['name'])
talk['name'] = namelist[0]
print LINE_FORMAT.format(mark=mark, **talk)
for name in namelist[1:]:
print " "*25, name