-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvotesutils.py
More file actions
70 lines (46 loc) · 1.76 KB
/
votesutils.py
File metadata and controls
70 lines (46 loc) · 1.76 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python3
import unidecode
def update_group(group, result_vote):
unaccented_vote = unidecode.unidecode(result_vote)
if unaccented_vote.upper() == "SI":
group[0] = group[0] + 1
elif unaccented_vote.upper() == "NO":
group[1] = group[1] + 1
elif unaccented_vote.upper() == "ABSTENCION":
group[2] = group[2] + 1
else:
# No vota
group[3] = group[3] + 1
return group
def get_votos(json_data):
grupos = {}
group_list = set([x["grupo"] for x in json_data["votaciones"]])
group_list = list(filter(lambda x: x != "", group_list))
[grupos.setdefault(key, [0, 0, 0, 0]) for key in group_list]
for voto in json_data["votaciones"]:
group_name = voto["grupo"]
if not group_name:
continue
result_vote = voto["voto"]
group = grupos[group_name]
update_group(group, result_vote)
return grupos
def get_title(json_data):
return __get_json_attribute(json_data, "titulo")
def get_subtitle(json_data):
return __get_json_attribute(json_data, "textoSubGrupo")
def get_sesion(json_data):
return __get_json_attribute(json_data, "sesion")
def get_num_votacion(json_data):
return __get_json_attribute(json_data, "numeroVotacion")
def get_record_text(json_data):
return __get_json_attribute(json_data, "textoExpediente")
def get_subgroup(json_data):
return __get_json_attribute(json_data, "textoSubGrupo")
def get_detailed_vote(json_data):
return json_data["votaciones"]
def __get_json_attribute(json_data, attribute):
return json_data["informacion"][attribute]
def get_legislatura(filename: str):
# split './files_X\\sesion1votacion1.json' in files_X and then split in X
return filename.split("\\")[0].split("_")[-1]