Created
October 30, 2022 20:40
-
-
Save MiguelMachado-dev/07e490a54ccf5572f7129725acaa1e4c to your computer and use it in GitHub Desktop.
Eleições 2022 Presidente
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// move this to a file and install axios and node-cron to package.json | |
const axios = require("axios"); | |
const cron = require("node-cron"); | |
const BASE_URL = | |
"https://resultados.tse.jus.br/oficial/ele2022/545/dados-simplificados/br/br-c0001-e000545-r.json"; | |
const main = async () => { | |
try { | |
const response = await axios.get(BASE_URL).catch((error) => { | |
throw new Error(error.message); | |
}); | |
const resultado = []; | |
for (const candidato of response.data.cand) { | |
resultado.push({ | |
candidato: candidato.nm, | |
votos: candidato.vap, | |
porcentagem: candidato.pvap, | |
}); | |
} | |
console.info({ | |
Data: response.data.dg, | |
Horario: response.data.hg, | |
Apuradas: response.data.psi, | |
}); | |
console.table(resultado); | |
} catch (exception) { | |
console.error({ exception }); | |
} | |
}; | |
cron.schedule("* * * * *", () => { | |
main(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crie um arquivo index.js com o codigo
rode
npm init -y
npm install axios node-cron
e depois rode o arquivo com
node index.js