some late comments :)
[gostyle.git] / load_questionare.py
blob47504195e22e3f80b9ba7d983f46a8fcfc76b6bd
1 import sys
2 import os
3 import json
4 import logging
6 """Utility module loading questionare answers from the json questionare results
7 listed in (see config) QUESTIONARE (by def) subdir."""
9 def load_file(filename):
10 with open(filename) as fin:
11 dump = json.load(fin)
13 d = {}
15 for group_list in dump['group_lists']:
16 for player in group_list['list']:
17 if player['skip'] != 'yes':
18 style = player['style']
19 vec = [ style['te'], style['or'], style['ag'], style['th'] ]
20 try:
21 vec = map(int, vec)
22 except:
23 continue
25 d[player['name']] = tuple(vec)
27 return d
29 def scan_d(directory):
30 ds = []
31 for dirname, dirnames, filenames in os.walk(directory):
32 # print path to all filenames.
33 for filename in filenames:
34 fn = os.path.join(dirname, filename)
35 try:
36 ds.append(load_file(fn))
37 except:
38 logging.warn("Scanning of questionare file '%s' failed, skipping."%fn)
39 continue
41 return ds
43 if __name__ == '__main__':
44 #fn = sys.argv[1]
45 #print load_file(fn)
47 print scan_d('./QUESTIONARE')