Created
June 7, 2014 22:13
-
-
Save thiagorondon/58ecd728aa4e20c4c3e4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Text::CSV; | |
use LWP::Simple; | |
our $csv = Text::CSV->new( { binary => 1, sep_char => '#' } ); | |
our $url_base = 'http://www2.camara.sp.gov.br/Dados_abertos/projetos'; | |
our $url_autor = "$url_base/autor.txt"; | |
our $url_encerra = "$url_base/encerra.txt"; | |
# apenas autor que contém EXECUTIVO. | |
sub processar_arquivos { | |
my $arquivo = shift; | |
my $DB = {}; | |
my $conteudo = get($arquivo); | |
my @linhas = split( /\r\n/, $conteudo ); | |
while ( my ($linha) = splice( @linhas, 0, 1 ) ) { | |
my $status = $csv->parse($linha); | |
my @campos = $csv->fields(); | |
# Linhas inúteis. | |
next unless @campos > 2; | |
next if $campos[0] eq 'TipoProj'; | |
# Bases diferentes, necessário normalizar. | |
$campos[0] = uc( $campos[0] ); | |
# Disclaimer: Armazenando em memória | |
if ( exists( $campos[4] ) ) { | |
# encerrar - TipoProj#NoProj#DataProj#Enc.. -> TipoProj;NoProj;Status | |
$DB->{ $campos[0] }->{ $campos[1] }->{ $campos[4] } = 1; | |
} | |
else { | |
# autor - TipoProj#NoProj#DataProj#Autor -> TipoProj;NoProj;Autor | |
$DB->{ $campos[0] }->{ $campos[1] }->{ $campos[3] } = 1; | |
} | |
} | |
return $DB; | |
} | |
my $db = &processar_arquivos($url_autor); | |
my $db_encerrados = &processar_arquivos($url_encerra); | |
my $promulgado = 0; | |
my $promulgado_executivo = 0; | |
my $apresentadas = 0; | |
my @napres = keys( $db->{'PL'} ); | |
my @nproj = keys( $db_encerrados->{'PL'} ); | |
my $apresentadas_total = scalar(@napres); | |
while ( my ($linha) = splice( @napres, 0, 1 ) ) { | |
$apresentadas++ if $db->{'PL'}->{$linha}->{EXECUTIVO}; | |
} | |
while ( my ($linha) = splice( @nproj, 0, 1 ) ) { | |
if ( $db_encerrados->{'PL'}->{$linha}->{PROMULGADO} ) { | |
$promulgado_executivo++ if $db->{'PL'}->{$linha}->{EXECUTIVO}; | |
$promulgado++; | |
} | |
} | |
print "PLs total apresentadas: $apresentadas_total\n"; | |
print "PLs apresentadas pelo executivo: $apresentadas\n"; | |
print "PLs promulgadas: $promulgado\n"; | |
print "PLs promulgadas pelo executivo: $promulgado_executivo\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment