So I'm trying to connect to the Brazil Deputy Chamber database and get all bills informations and votes.
I STARTED CREATING THE BASE FOR THE API CALL
base_url <- "https://dadosabertos.camara.leg.br/api/v2/"
path <- "proposicoes?siglaTipo=PEC%2C%20PDC%2C%20PL%2C%20PLP&dataApresentacaoInicio=2019-02-01&dataApresentacaoFim=2023-01-31&itens=100&ordem=ASC&ordenarPor=ano"
page <- "&pagina="
i <- 1
api_url <- paste0(base_url, path, page, i)
dados <- NULL
AND THEN CREATED A LOOP BECAUSE THE API IS PAGINATED UNTIL 174 PAGES - THE 10 IS JUST A DEMOSTRATION
while (i <= 10) {
print("Próxima página encontrada, baixando...")
api_url <- paste0(base_url, path, page, i)
raw_data <- GET(api_url)
texto <- content(raw_data, "text", encoding = "UTF-8")
json <- fromJSON(texto, flatten = TRUE)
df <- as.data.frame(json)
i <- i + 1
dados <- rbind(dados, df)
}
tabela <- as.data.frame(dados)
View(tabela)
SO FAR SO GOOD, A GOT A NICE TABLE WITH ALL PROPOSITIONS FROM THE PERIOD I CHOSE
BUT I WANT TO INCLUDE IN EACH PROPOSITION THE DETAILS THAT ARE NOT PRESENT IN THE FIRST TABLE
FOR THAT YOU NEED TO REQUEST AGAIN USING EACH INDIVIDUAL ID, LIKE: https://dadosabertos.camara.leg.br/api/v2/proposicoes/2190549
SO I'M TRYING TO GENERATE A SECOND LOOP, TO INCLUDE IN EACH REQUEST THE ID NUMBER THAT IS PRESENT IN THE FIRST COLUMN OF THE DATA FRAME
path_unico <- "proposicoes/"
nrow(tabela)
k <- 1
while (k <= nrow(tabela)) {
print("Dados encontrados, baixando...")
api_url_proposicoes <- paste0(base_url, path_unico, id_proposicoes)
raw_data_proposicoes <- GET(api_url_proposicoes)
texto_proposicoes <- content(raw_data_proposicoes, "text", encoding = "UTF-8")
json_proposicoes <- fromJSON(texto_proposicoes, flatten = TRUE)
df_proposicoes <- as.data.frame(json_proposicoes)
id_proposicoes <- id_proposicoes[, k]
k <- k + 1
dados <- cbind(dados, df_proposicoes)
}
AND THIS IS WHERE I GET THE ERROR:
Error in parse_url(url) : length(url) == 1 is not TRUE
Does anyone have any ideia on how I can perform this task?