Skip to content

Instantly share code, notes, and snippets.

@RobertMyles
Created April 25, 2017 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertMyles/d734b5e8b201587ca4f1551d17cd4598 to your computer and use it in GitHub Desktop.
Save RobertMyles/d734b5e8b201587ca4f1551d17cd4598 to your computer and use it in GitHub Desktop.
Get all votes over a long time period from the Brazilian Federal Senate API, which only allows requests for 60 days.
library(congressbr)
Seq <- seq(as.Date("1991-02-01"), to = as.Date("2018-12-31"),
by = 60)
Seq2 <- seq(as.Date("1991-03-01"), to = as.Date("2019-01-31"),
by = 60)
seq_m <- data.frame(date = Seq, end_date = Seq2)
seq_m$date <- gsub("-", "", seq_m$date)
seq_m$end_date <- gsub("-", "", seq_m$end_date)
legis <- list()
for(k in 1:nrow(seq_m)){
x <- try(
sen_votes(date = seq_m$date[[k]],
end_date = seq_m$end_date[[k]]),
silent = FALSE)
if(class(x) == "try-error"){
next
} else{
legis[[k]] <- x
}
}
Legis <- do.call(rbind, legis)
Legis <- Legis %>%
dplyr::filter(!is.na(bill_number),
vote_secret == "No")
Legis <- Legis %>%
dplyr::mutate(
legislature = ifelse(
vote_date >= "1991-02-01" & vote_date <= "1995-01-31", "49",
ifelse(
vote_date >= "1995-02-01" & vote_date <= "1999-01-31", "50",
ifelse(
vote_date >= "1999-02-01" & vote_date <= "2003-01-31", "51",
ifelse(
vote_date >= "2003-02-01" & vote_date <= "2007-01-31", "52",
ifelse(
vote_date >= "2007-02-01" & vote_date <= "2011-01-31", "53",
ifelse(
vote_date >= "2011-02-01" & vote_date <= "2015-01-31", "54",
ifelse(
vote_date >= "2015-02-01" & vote_date <= "2019-01-31", "55",
NA
))))))))
Legis <- Legis %>%
dplyr::mutate(
senator_party = ifelse(senator_party %in% c("Sem registro", "S/Partido"),
"Independent", senator_party)
)
Legis <- Legis %>%
dplyr::mutate(
bill = paste(bill_type, bill_year, bill_number, sep = ":")
)
Legis <- Legis %>%
dplyr::select(
vote_date, bill_id, bill, legislature, bill_description, senator_id,
senator_name, senator_vote, senator_party, senator_state
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment