line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::TickerSymbols; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
90534
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
127
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
2818
|
use bytes ; |
|
2
|
|
|
|
|
25
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
53
|
use Carp ; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
838
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw'symbols_list |
14
|
|
|
|
|
|
|
industries_list |
15
|
|
|
|
|
|
|
industry_list |
16
|
|
|
|
|
|
|
' ; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '2.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $long; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my %inds ; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
0
|
|
0
|
sub _carp(@) { carp "@_\n" ; ()} |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _http2name($){ |
27
|
215
|
|
|
215
|
|
276
|
my $n = shift ; |
28
|
215
|
|
|
|
|
600
|
for($n) { |
29
|
215
|
|
|
|
|
507
|
s/^\s+//s ; |
30
|
215
|
|
|
|
|
448
|
s/\s+$//s ; |
31
|
215
|
|
|
|
|
1007
|
s/\s+/ /sg ; |
32
|
215
|
|
|
|
|
586
|
s/\&\;/&/g ; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
$n |
35
|
215
|
|
|
|
|
2387
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $_ua ; |
38
|
|
|
|
|
|
|
sub _ua() { |
39
|
2
|
|
|
2
|
|
7963
|
use LWP ; |
|
2
|
|
|
|
|
196695
|
|
|
2
|
|
|
|
|
2825
|
|
40
|
|
|
|
|
|
|
# use HTTP::Cookies; |
41
|
|
|
|
|
|
|
# use File::Temp 'tempfile' ; |
42
|
|
|
|
|
|
|
# my $ua = new LWP::UserAgent(Accept => "text/html, */*;q=0.1", referer => 'http://google.com') ; |
43
|
2
|
|
|
2
|
|
23
|
my $ua = new LWP::UserAgent() ; |
44
|
2
|
|
|
|
|
12254
|
$ua -> env_proxy() ; |
45
|
|
|
|
|
|
|
# $ua -> cookie_jar( new HTTP::Cookies (file => tempfile())); |
46
|
2
|
|
|
|
|
39911
|
$ua -> agent(""); |
47
|
2
|
|
|
|
|
150
|
$ua |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _brws(@) { |
51
|
7
|
|
66
|
7
|
|
79
|
$_ua ||= _ua() ; |
52
|
7
|
|
|
|
|
97
|
my $res = $_ua->get(@_) ; |
53
|
7
|
50
|
|
|
|
7832761
|
return $res -> content() if $res -> is_success() ; |
54
|
0
|
|
|
|
|
0
|
$res = $_ua->get(@_) ; |
55
|
0
|
0
|
|
|
|
0
|
return $res -> content() if $res -> is_success() ; |
56
|
0
|
|
|
|
|
0
|
return _carp "download (@_):", $res->status_line() ; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _gimi($$;@) { |
60
|
7
|
|
|
7
|
|
20
|
my $prs = shift ; |
61
|
|
|
|
|
|
|
|
62
|
7
|
50
|
|
|
|
29
|
local $_ = _brws(@_) or return ; |
63
|
|
|
|
|
|
|
|
64
|
7
|
50
|
66
|
|
|
3718
|
if ($prs eq 'nas' and $long) { |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
my @ret ; |
66
|
0
|
|
|
|
|
0
|
while ( m/^ |
67
|
|
|
|
|
|
|
\s* \" ([\w+\.]+) \" \s* \, |
68
|
|
|
|
|
|
|
\s* \" (.*? (?:[^\\] | \\ \\ )) \" |
69
|
0
|
|
|
|
|
0
|
/xgm ) { push @ret, "$1:$2" } |
70
|
0
|
0
|
0
|
|
|
0
|
shift @ret if @ret and $ret[0] eq 'Symbol:Name' ; |
71
|
|
|
|
|
|
|
return @ret |
72
|
0
|
|
|
|
|
0
|
} |
73
|
|
|
|
|
|
|
elsif ($prs eq 'nas') { |
74
|
3
|
|
|
|
|
10
|
my @ret ; |
75
|
3
|
|
|
|
|
163
|
while (m/^ \s* \" ([\w+\.]+) \" |
76
|
6043
|
|
|
|
|
38354
|
/xgm ) { push @ret, $1 } |
77
|
3
|
50
|
33
|
|
|
41
|
shift @ret if @ret and $ret[0] eq 'Symbol' ; |
78
|
3
|
|
|
|
|
2633
|
return @ret ; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ($prs eq 'ind' and $long) { |
81
|
0
|
|
|
|
|
0
|
my @ret ; |
82
|
0
|
|
|
|
|
0
|
while ( m{ |
|
0
|
|
|
|
|
0
|
|
83
|
|
|
|
|
|
|
http\://biz\.yahoo\.com/ic/\d+/\d+\.html\"\>([^\<]+).*? |
84
|
|
|
|
|
|
|
http\://finance\.yahoo\.com/q\?s\=([\w\.]+) |
85
|
|
|
|
|
|
|
}xgs ) {push @ret, $2 . ':'. _http2name $1 } |
86
|
|
|
|
|
|
|
return @ret |
87
|
0
|
|
|
|
|
0
|
} |
88
|
|
|
|
|
|
|
elsif ($prs eq 'ind') { |
89
|
|
|
|
|
|
|
return |
90
|
3
|
|
|
|
|
99
|
m{http\://finance\.yahoo\.com/q\?s\=([\w\.]+)\s*\"}g |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif ($prs eq 'inds') { |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
62
|
while ( m{http\://biz\.yahoo\.com/ic/(\d+)\.html\s*\"\s*\>\s*([^\<]+)}sg ) { |
95
|
215
|
|
|
|
|
472
|
my ($d, $n) = ($1, $2) ; |
96
|
215
|
|
|
|
|
382
|
$inds{ _http2name $n } = $d ; |
97
|
|
|
|
|
|
|
} |
98
|
1
|
|
|
|
|
88
|
return keys %inds; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _gimi_nasdaq($) { |
103
|
3
|
|
|
3
|
|
12
|
my $url = 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=' . shift ; |
104
|
|
|
|
|
|
|
# my $dummy = _brws($url); |
105
|
3
|
|
|
|
|
117
|
_gimi nas => $url . '&render=download'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub symbols_list($) { |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
50
|
3
|
1
|
1032
|
my $wt = shift || '?'; |
111
|
3
|
|
|
|
|
10
|
my @all = qw/nasdaq amex nyse/ ; |
112
|
3
|
50
|
|
|
|
8
|
return _gimi_nasdaq uc $wt if grep {$_ eq $wt } @all ; |
|
9
|
|
|
|
|
41
|
|
113
|
0
|
0
|
|
|
|
0
|
return map {_gimi_nasdaq uc $_ } @all if $wt eq 'all'; |
|
0
|
|
|
|
|
0
|
|
114
|
0
|
|
|
|
|
0
|
return _carp "bad parameter: should be " . join '|', @all, 'all' ; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
1
|
1
|
12
|
sub industries_list { _gimi inds => 'http://biz.yahoo.com/ic/ind_index.html' } |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub industry_list($) { |
120
|
3
|
50
|
|
3
|
1
|
2771
|
%inds or industries_list() ; |
121
|
3
|
|
|
|
|
7
|
my $name = shift ; |
122
|
3
|
50
|
|
|
|
14
|
my $n = $inds{$name} or return _carp "'$name' is not recognized" ; |
123
|
|
|
|
|
|
|
|
124
|
3
|
|
|
|
|
7
|
my $p = 'pub' ; # shift || ''; $p = 'pub' unless $p eq 'prv' or $p eq 'all' ; |
125
|
|
|
|
|
|
|
# ?? TODO ?? |
126
|
|
|
|
|
|
|
# support Private/Foreign ? what for? |
127
|
3
|
|
|
|
|
19
|
_gimi ind => "http://biz.yahoo.com/ic/${n}_cl_${p}.html" |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |