Created
February 24, 2016 20:42
-
-
Save leobarone/498883782afdf7420264 to your computer and use it in GitHub Desktop.
Votacoes CD de 2000 a 2014
This file contains 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
library(bRasilLegis) | |
obterVotacoes <- function(tipo, numero, ano) { | |
output <- data.frame() | |
for (i in 1:length(tipo)){ | |
if (tipo[i] == "REQ"){ | |
print("Requerimento - pular") | |
} | |
else{ | |
print(paste(i,"- Capturando votacao da proposicao", tipo[i], numero[i], "de", ano[i])) | |
erro <- try(obterVotacaoProposicao(tipo[i], numero[i], ano[i]), silent=TRUE) | |
if ('try-error' %in% class(erro)){ | |
print("Proposicao acima nao pode ser capturada por problemas na API") | |
} | |
else { | |
input <- obterVotacaoProposicao(tipo[i], numero[i], ano[i]) | |
if (!is.null(nrow(input))) { | |
output <- rbind(output, input) | |
} | |
} | |
} | |
} | |
return(output) | |
} | |
obterVotacoesAno <- function(anos){ | |
output <- data.frame() | |
for (ano in anos){ | |
proposicoes.ano <- listarProposicoesVotadasEmPlenario(ano)[,2] | |
proposicoes.ano[grep("=>", proposicoes.ano)] <- substr(proposicoes.ano[grep("=>", proposicoes.ano)], | |
regexpr("=>",proposicoes.ano[grep("=>", proposicoes.ano)]) + 3, | |
nchar(proposicoes.ano)[grep("=>", proposicoes.ano)]) | |
proposicoes.ano <- unique(proposicoes.ano) | |
print(paste("Total de proposicoes em", ano, "=", length(proposicoes.ano))) | |
if (substr(proposicoes.ano, 1, regexpr(" ",proposicoes.ano) - 1) == "REQ") { | |
proposicoes.ano <- substr(proposicoes.ano, regexpr(">",proposicoes.ano) + 2, nchar(proposicoes.ano)) | |
} | |
tipo <- substr(proposicoes.ano, 1, regexpr(" ",proposicoes.ano) - 1) | |
numero <- substr(proposicoes.ano, regexpr(" ",proposicoes.ano) + 1, regexpr("/", proposicoes.ano) - 1) | |
ano <- substr(proposicoes.ano, regexpr("/",proposicoes.ano) + 1, regexpr("/", proposicoes.ano) + 4) | |
output <- rbind(output, obterVotacoes(tipo, numero, ano)) | |
} | |
return(output) | |
} | |
obterVotacoesAno(2000:2014) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment