blib/lib/Tribunais/TJES.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 71 CC 3 SCAR 15.5
CC
3
Cov
0%
sincroniza
12.0
new
2.0
BEGIN
2.0
CRAP 4.7
1 package Tribunais::TJES;
2  
3 use strict;
4 use warnings;
5  
6 use JSON;
7 use WWW::Mechanize;
8 use HTML::TreeBuilder::XPath;
9 use Path::Class;
10 use utf8;
11  
12  
13 sub new
14 {
15 my $class = shift;
16 my $self = {
17 _edNumProcesso => shift,
18 _seInstancia => shift,
19 _sePesquisar => shift,
20 };
21 bless $self, $class;
22 return $self;
23 }
24  
25 sub sincroniza
26 {
27 my($self) = @_;
28
29 my $URI = "http://www.tj.es.gov.br/consulta/cfmx/portal/Novo/cons_proces.cfm";
30  
31 my $mech = WWW::Mechanize->new;
32 $mech->agent_alias( 'Windows IE 6' );
33
34 $mech->post($URI);
35
36 my $html = $mech->content;
37
38 $html =~ s[action="lista_proces.cfm"][action="desc_proces.cfm"]isg;
39 $html =~ s[_blank][_self]isg;
40
41 $mech->update_html( $html );
42  
43  
44 $mech->submit_form(
45 form_name => "cons_proces",
46 fields => {
47 seInstancia => $self->{_seInstancia},
48 sePesquisar => $self->{_sePesquisar},
49 edNumProcesso => $self->{_edNumProcesso},
50 seJuizo => "1",
51 seComarca => "0",
52 edNumCDA => "",
53 edAnoCDA => "",
54 edNumPetic => "",
55 edNumOriginPrim => "",
56 CdPessoa => "",
57 edNome => "",
58 SeqAdvog => "",
59 edNumOab => "",
60 edNomeAdv => "",
61 rbTipoNome => "1",
62 seSituacao => "1",
63 seNatureza => "1",
64 seTipoParte => "",
65 }
66 );
67
68 my $titulo = $mech->title();
69 $html = $mech->content;
70
71 my $tree= HTML::TreeBuilder::XPath->new;
72 $tree->parse( $html );
73
74 my $table_rows = $tree->findnodes( '//div[@class=\'conteudo\']//table[1]//tr' );
75
76 my $count = 0;
77 my @items;
78
79 foreach my $row ( $table_rows->get_nodelist )
80 {
81 if ( $count > 1 )
82 {
83 my $tree_tr = HTML::TreeBuilder::XPath->new;
84 $tree_tr->parse( $row->as_HTML );
85 my $strdata=$tree_tr->findvalue( '//span[1]' );
86 if(length($strdata)>5)
87 {
88 my $row_data = {
89 data => $tree_tr->findvalue( '//span[1]' ),
90 andamento => $tree_tr->findvalue( '//span[2]' ),
91 statusandamento => $tree_tr->findvalue( '//span[3]' ),
92 };
93 push(@items, $row_data);
94 }
95 $tree_tr->delete;
96 }
97 $count++;
98 }
99
100 my $json = { fases => \@items }; # cria hash com nome de $json, insere no hash uma key com nome de andamentos tendo o array @registros no value dessa key
101
102 my $string_json = to_json($json); # encoda o hash com nome de $json em uma string no formato JSON, e atribui à var $string_json
103
104 return $string_json;
105 }
106  
107 1;
108  
109 __END__