Last active
          March 23, 2019 02:21 
        
      - 
      
 - 
        
Save jjesusfilho/2e9ec01eb85141a213610f24c800f4fa to your computer and use it in GitHub Desktop.  
    Baixar BOs do Espírito Santo
  
        
  
    
      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
    
  
  
    
  | ## Acesso a todos os BOs: | |
| # https://boletins.sesp.es.gov.br/ | |
| ## Exemplo | |
| library(httr) | |
| library(textreadr) | |
| library(stringi) | |
| set_config(config(ssl_verifypeer = FALSE)) | |
| GET("https://boletins.sesp.es.gov.br/2017/2017-01_31218036a31335002.zip",write_disk=("arq1.zip")) | |
| system("unzip arq1.zip") | |
| BOs<-read_dir(pasta) | |
| b<-stri_replace_all_regex(BOs$content,"\\s{5,}","@") ## Gambiarra: substitui longos espaços por @ para facilitar as buscas. | |
| b<-stri_replace_all_regex(b,"\n","") | |
| data.fato<-stri_extract_first_regex(b,"(?<=Evento.{0,100}@).*?(?=Incidente)") | |
| data.fato<-stri_extract_first_regex(data.fato,".{10}") | |
| local<-stri_extract_first_regex(b,"(?<=Municipio).*?(?=@)") | |
| bairro<-stri_extract_first_regex(b,"(?<=Municipio.{0,100}@).*?(?=@)") | |
| municipio<-stri_extract_first_regex(b,"[^@]*.(?=Complemento)") | |
| tipo.local<-stri_extract_first_regex(b,"(?<=Evento).*?(?=@)") | |
| unidade.registro<-stri_extract_first_regex(b,"(?<=Lavradura).*?(?=@)") | |
| incidente<-stri_extract_first_regex(b,"(?<=inicial).*?(?=Local\\s\\()") | |
| crime<-ifs(x=incidente,y=list(c("^A01","homicidio"), | |
| c("^A02","homicidio tentado"), | |
| c("^A13@","ameaça"), | |
| c("^B02H","Roubo de veículo"), | |
| c("^B02","Roubo"), | |
| c("^B01H","Furto de veículo"), | |
| c("^B01","Furto"), | |
| c("^B10","Furto tentado"), | |
| c("^B04","Apropriação indébita"), | |
| c("^A07","Lesão corporal"), | |
| c("^E01","Tráfico de drogas"), | |
| c("^E02","Posse de drogas"), | |
| c("^I0[1|2|3|4]","Acidente de trânsito"), | |
| c("^F0[1|2|4]","Porte,posse ilegal ou disparo de armas"), | |
| c("^C[0|1]","Estupro"), | |
| c("^A11","Crimes contra a Honra"), | |
| c("^B06","Estelionato e fraudes"), | |
| c("^G14","Lei Maria da Penha"), | |
| c("^B05","Danos"), | |
| c("^H01","Vias de fato"), | |
| c("^Z","Ocorrências diversas"), | |
| c("(CRIMES DIVERSOS|^A|^B|^D|^E|^F|@|\\w\\d.*)","Outros crimes e atividades") | |
| )) | |
| df<-data.frame(data.fato,local,bairro,municipio,tipo.local,unidade.registro,crime) | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment