Skip to content

Instantly share code, notes, and snippets.

@MiguelMachado-dev
Created October 30, 2022 20:40
Show Gist options
  • Save MiguelMachado-dev/07e490a54ccf5572f7129725acaa1e4c to your computer and use it in GitHub Desktop.
Save MiguelMachado-dev/07e490a54ccf5572f7129725acaa1e4c to your computer and use it in GitHub Desktop.
Eleições 2022 Presidente
// 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();
});
@MiguelMachado-dev
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment