line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
390
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
3
|
|
|
|
|
|
|
package App::bovespa; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
579
|
use HTML::TreeBuilder; |
|
1
|
|
|
|
|
31805
|
|
|
1
|
|
|
|
|
12
|
|
6
|
1
|
|
|
1
|
|
908
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
302897
|
|
|
1
|
|
|
|
|
276
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# TODO = multiple providers |
9
|
|
|
|
|
|
|
#my $url = "https://br.financas.yahoo.com/q?s=PETR4.SA"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $agent_string = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
0
|
466
|
my ( $class ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
4
|
bless { |
17
|
|
|
|
|
|
|
}, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub stock { |
21
|
2
|
|
|
2
|
1
|
372
|
my ( $self, $stock ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
7
|
return $self->yahoo( $stock ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub yahoo { |
28
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $stock ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
4
|
my $url = "https://br.financas.yahoo.com/q?s="; |
31
|
2
|
|
|
|
|
6
|
$stock = uc $stock . ".sa"; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
13
|
my $ua = LWP::UserAgent->new(); |
34
|
2
|
|
|
|
|
366330
|
$ua->ssl_opts( verify_hostname => 0 ); |
35
|
2
|
|
|
|
|
45
|
$ua->timeout( 10 ); |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
32
|
my $response = $ua->get( $url . $stock ); |
38
|
2
|
|
|
|
|
1737103
|
my $raw_html; |
39
|
2
|
50
|
|
|
|
12
|
if ( $response->is_success ){ |
40
|
2
|
|
|
|
|
46
|
$raw_html = $response->decoded_content; |
41
|
|
|
|
|
|
|
}else{ |
42
|
0
|
|
|
|
|
0
|
die $response->status_line; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
15543
|
my $tree = HTML::TreeBuilder->new(); |
46
|
2
|
|
|
|
|
621
|
$tree->parse( $raw_html ); |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
232205
|
for ( $tree->find_by_attribute('id', "yfs_l84_". lc $stock )){ |
49
|
2
|
|
|
|
|
19342
|
return join "", grep { ref $_ ne "SCALAR" } $_->content_list; |
|
2
|
|
|
|
|
1492
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
App::bovespa - Simple tool to follow up your stocks at Bovespa Stock Exchange |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Version 0.002 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This module is a crawler to get the cotation of the Bovespa Stock Exchange. Now |
64
|
|
|
|
|
|
|
it gets information one of the main portals. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This module is just for follow up, really, nothing realtime, nothing too serious. |
67
|
|
|
|
|
|
|
I wrote it to keep my eyes on my own stocks. It is easier run a script that login |
68
|
|
|
|
|
|
|
on my homebroker agent, with tokens and etc just to see the cotation. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
To get a stock cotation is plain simple: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use App::bovespa; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $exchange = App::bovespa->new(); |
75
|
|
|
|
|
|
|
my $cotation = $exchange->stock( "PETR4" ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Also inside this distribution, comes a small tool called bovespa_report, it has |
78
|
|
|
|
|
|
|
a wrapper for cotation and a parser for a file with a list of cotations and prices to |
79
|
|
|
|
|
|
|
compare. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
bovespa_report --help |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Will display all options related with the tool |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 stock |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Receives a stock name and returns it cotation. The name must be four letters and the type digit. |
90
|
|
|
|
|
|
|
Like "PETR4" or "PETR3" |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
RECSKY, C<< recsky at cpan.org >> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 BUGS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
In case of one of providers change it page or something like that, the lib may broke. In this case |
99
|
|
|
|
|
|
|
contact me at recsky@cpan.org |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Or at irc at irc.perl.org |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#sao-paulo.pm |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright 2015 RECSKY |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
110
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
111
|
|
|
|
|
|
|
copy of the full license at: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L |
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |