-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (40 loc) · 1.44 KB
/
index.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
const { default: axios } = require('axios');
/**
*
* @param {number} number
* @returns {string}
*/
const formatNumber = (number) => {
`${number > 0 ? `+`: ''}${number.toLocaleString("pt-BR")}`
}
const oldData = {}
const logData = async () => {
const data = await axios("https://resultados.tse.jus.br/oficial/ele2022/545/dados-simplificados/br/br-c0001-e000545-r.json")
.then(res => res.data);
const apuracoes = data.cand.map((cand, i) => {
const votos = Number(cand.vap);
const votos_ganhos = votos - (oldData[cand.n]?.votos || 0);
const porcentagem = Number(cand.pvap.replace(",", "."));
const porcentagem_ganha = porcentagem - (oldData[cand.n]?.porcentagem || 0);
const diferenca_de_votos = i === 0 ? 0 : votos - Number(data.cand[i - 1].vap);
return ({
numero: cand.n,
candidato: cand.nm.replace(''', "'"),
votos: votos.toLocaleString("pt-BR"),
votos_ganhos: formatNumber(votos_ganhos),
porcentagem: `${porcentagem}%`,
porcentagem_ganha: `${porcentagem_ganha > 0 ? `+` : ''}${porcentagem_ganha.toFixed(2)}%`,
diferenca_de_votos: `${diferenca_de_votos > 0 ? `+`: ''}${diferenca_de_votos.toLocaleString("pt-BR")}`
})
});
apuracoes.forEach((cand) => {
oldData[cand.numero] = {
porcentagem: Number(cand.porcentagem.replace("%", "")),
votos: Number(cand.votos.replaceAll(".", ""))
}
});
console.log(`Urnas Apuradas: ${data.pst}%`)
console.table(apuracoes);
setTimeout(logData, 60000);
}
logData();