Skip to content

Instantly share code, notes, and snippets.

@tsprates
Created October 26, 2022 22:37
Show Gist options
  • Save tsprates/165f47efc5b7d1c1c9ab1aae0d0c9535 to your computer and use it in GitHub Desktop.
Save tsprates/165f47efc5b7d1c1c9ab1aae0d0c9535 to your computer and use it in GitHub Desktop.
// Brazil's election for president 2022
// Author: Thiago Prates
import fetch from "node-fetch";
const url = "https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json";
const response = await fetch(url);
const json = await response.json();
const results = json["cand"].reduce((acc, { /* candidato */ nm, /* porcentagem */ pvap }) => {
const pct = parseFloat(pvap.replace(/,/g, "."));
const cand =
acc[nm] = {
"Porcentagem (%)": pct,
};
return acc;
}, {});
console.table(results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment