-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (41 loc) · 967 Bytes
/
main.go
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
package main
import (
"acompanhalegis-analytics-api/src/dadosabertos"
"acompanhalegis-analytics-api/src/elastic"
"fmt"
"time"
)
func main() {
var pageNumber int = 1
var counter int = 0
var ids []int
var proposicoesChan = make(chan dadosabertos.Proposicao, 1000)
go ingester(proposicoesChan)
for {
page, next := dadosabertos.GetProposicoes(pageNumber)
if next == "" {
break
}
for _, proposicao := range page {
ids = append(ids, proposicao.Id)
counter++
}
pageNumber++
time.Sleep(3 * time.Second)
}
fmt.Println(fmt.Sprintf("Total de ids: %d", len(ids)))
time.Sleep(2 * time.Second)
for i, id := range ids {
go dadosabertos.GetProposicaoIngest(id, proposicoesChan)
if i%20 == 0 {
time.Sleep(10 * time.Second)
}
}
fmt.Println(fmt.Sprintf("Total de proposicoes: %d", counter))
}
func ingester(proposicoes chan dadosabertos.Proposicao) {
for {
proposicao := <-proposicoes
go elastic.IngestProposicao(proposicao)
}
}