-
Notifications
You must be signed in to change notification settings - Fork 3
/
processFiles.js
144 lines (109 loc) · 2.8 KB
/
processFiles.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
//
const fs = require('fs');
//
function accentsTidy (s) {
var r=s.toLowerCase();
r = r.replace(new RegExp(/\s/g),"");
r = r.replace(new RegExp(/[àáâãäå]/g),"a");
r = r.replace(new RegExp(/æ/g),"ae");
r = r.replace(new RegExp(/ç/g),"c");
r = r.replace(new RegExp(/[èéêë]/g),"e");
r = r.replace(new RegExp(/[ìíîï]/g),"i");
r = r.replace(new RegExp(/ñ/g),"n");
r = r.replace(new RegExp(/[òóôõö]/g),"o");
r = r.replace(new RegExp(/œ/g),"oe");
r = r.replace(new RegExp(/[ùúûü]/g),"u");
r = r.replace(new RegExp(/[ýÿ]/g),"y");
r = r.replace(new RegExp(/\W/g),"");
return r;
}
//
function generateMunicipios() {
let temp = {}
const municipiosOld = JSON.parse(fs.readFileSync('./site/data/municipios.json', 'utf8'))
//
for (let key in municipiosOld) {
//
temp[accentsTidy(municipiosOld[key].municipio)] = municipiosOld[key].estadoSingla
}
//
temp['cariri'] = 'CE'
temp['apicum'] = 'MA'
//
fs.writeFileSync('./municipios.json', JSON.stringify(temp, null, 2));
}
//
function processaInsercoes(){
let insercoes = JSON.parse(fs.readFileSync('./relatorio.json', 'utf8'))
//
let temp = {}
for (let key in insercoes) {
//
let radioName = accentsTidy( key )
//
if (!Array.isArray(temp[radioName])) {
temp[radioName] = {}
}
//
for (let i=0; i<insercoes[key].length; i++) {
if (temp[radioName][insercoes[key][i].campanha]==null) {
temp[radioName][insercoes[key][i].campanha]=0
}
temp[radioName][insercoes[key][i].campanha]++
}
}
fs.writeFileSync('./site/data/relatorio.json', JSON.stringify(temp, null, 2))
return temp
}
//
function processaRadios(insercoes=null) {
const municipios = JSON.parse(fs.readFileSync('./municipios.json', 'utf8'))
const radios = JSON.parse(fs.readFileSync('./radios.json', 'utf8'))
//
let temp = {}
for (let key in radios) {
//
let municipio = accentsTidy( key.substring(key.lastIndexOf('-') + 1) )
//
let uf = municipios[municipio]
//
if (uf == null) {
console.log(uf)
new Error('precisa de um municipio')
}
//
if (!Array.isArray(temp[uf])) {
temp[uf] = []
}
//
let radio = radios[key]
//
radio.cleanName = accentsTidy(radio.name)
//
if (insercoes!=null) {
radio.insercoes = insercoes[radio.cleanName]??null
if (radio.insercoes==null) {
continue;
}
radio.insercoes.Bolsonaro = radio.insercoes.Bolsonaro??0
radio.insercoes.Lula = radio.insercoes.Lula??0
}
//
temp[uf].push(radio)
}
//
fs.writeFileSync('./site/data/radios.json', JSON.stringify(temp, null, 2))
}
/**
*
*
*
*
*
*/
// generateMunicipios()
let insercoes = processaInsercoes()
processaRadios(insercoes)
//
//