Created
October 2, 2022 21:50
-
-
Save eminetto/e9cc7f92a65386a342c3f1449852308b to your computer and use it in GitHub Desktop.
eleicao.go
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"net/http" | |
"time" | |
) | |
type resultado struct { | |
Dt string `json:"dt"` | |
HT string `json:"ht"` | |
Pst string `json:"pst"` | |
Cand []map[string]string `json:"cand"` | |
} | |
func main() { | |
for range time.Tick(time.Second * 15) { | |
fmt.Printf("\x1bc") | |
getResult() | |
} | |
} | |
func getResult() { | |
resp, err := http.Get("https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json") | |
if err != nil { | |
log.Fatalln(err) | |
} | |
var result resultado | |
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { | |
log.Fatal("erro lendo arquivo") | |
} | |
fmt.Printf("%s das seções totalizadas %s\n", result.Pst, result.HT) | |
for _, r := range result.Cand { | |
fmt.Printf("Candidato: %s Votos: %s Percentual: %s \n", r["nm"], r["vap"], r["pvap"]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment