line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::SEC::EdgarData; |
2
|
1
|
|
|
1
|
|
68398
|
use XML::Bare; |
|
1
|
|
|
|
|
15696
|
|
|
1
|
|
|
|
|
52
|
|
3
|
1
|
|
|
1
|
|
718
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
54860
|
|
|
1
|
|
|
|
|
52
|
|
4
|
1
|
|
|
1
|
|
11
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
75
|
|
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.10; |
|
1
|
|
|
|
|
3
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
11
|
|
|
|
|
|
|
set_user_agent |
12
|
|
|
|
|
|
|
get_filing_url |
13
|
|
|
|
|
|
|
get_xbrl_url |
14
|
|
|
|
|
|
|
get_filing_dates |
15
|
|
|
|
|
|
|
get_filing |
16
|
|
|
|
|
|
|
get_rss_url |
17
|
|
|
|
|
|
|
get_rss |
18
|
|
|
|
|
|
|
/; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.01002'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $BASE_URL = 'https://www.sec.gov'; |
23
|
|
|
|
|
|
|
my $RSS_URL = "$BASE_URL/cgi-bin/browse-edgar?action=getcompany&CIK=%s&type=%s&dateb=&owner=exclude&count=500&output=atom"; |
24
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
25
|
|
|
|
|
|
|
my $agent = "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0"; |
26
|
|
|
|
|
|
|
$ua->agent($ENV{EDGAR_USER_AGENT} || $agent); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub set_user_agent { |
29
|
0
|
|
|
0
|
0
|
|
my $g = shift; |
30
|
0
|
|
|
|
|
|
$ua->agent($g); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_rss_url { |
34
|
0
|
|
|
0
|
0
|
|
my ($sym, $t) = @_; |
35
|
0
|
|
|
|
|
|
my $url = sprintf($RSS_URL, $sym, $t); |
36
|
0
|
|
|
|
|
|
return $url; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub parse_rss { |
40
|
0
|
|
|
0
|
0
|
|
my $xml = shift; |
41
|
0
|
|
|
|
|
|
my $m = XML::Bare->new(text => $xml); |
42
|
0
|
|
|
|
|
|
my $root = $m->parse(); |
43
|
0
|
|
|
|
|
|
return $root; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_rss { |
47
|
0
|
|
|
0
|
0
|
|
my $url = get_rss_url(@_); |
48
|
0
|
|
|
|
|
|
my $res = $ua->get($url); |
49
|
0
|
0
|
|
|
|
|
if (!($res->is_success)) { |
50
|
0
|
|
|
|
|
|
say STDERR $res->content; |
51
|
0
|
|
|
|
|
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
my $d = $res->content; |
54
|
0
|
|
|
|
|
|
my $rss = parse_rss($d); |
55
|
0
|
|
|
|
|
|
return $rss; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub get_filing_dates { |
59
|
0
|
|
|
0
|
0
|
|
my $rss = get_rss(@_); |
60
|
0
|
|
|
|
|
|
my @dates = (); |
61
|
0
|
|
|
|
|
|
for my $n (@{$rss->{feed}->{entry}}) { |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
push @dates, $n->{content}->{'filing-date'}->{value}; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
return @dates; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_filing_url { |
68
|
0
|
|
|
0
|
0
|
|
my ($sym, $t, $date) = @_; |
69
|
0
|
|
|
|
|
|
my $rss = get_rss($sym, $t); |
70
|
0
|
|
|
|
|
|
for my $n (@{$rss->{feed}->{entry}}) { |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $c = $n->{content}; |
72
|
0
|
0
|
|
|
|
|
if ($c->{'filing-date'}->{value} eq $date) { |
73
|
0
|
|
|
|
|
|
return $c->{'filing-href'}->{value}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub get_xbrl_url { |
80
|
0
|
|
|
0
|
0
|
|
my $link = shift; |
81
|
0
|
|
|
|
|
|
my $res = $ua->get($link); |
82
|
0
|
0
|
|
|
|
|
return 0 unless $res->is_success; |
83
|
0
|
|
|
|
|
|
my $d = $res->content; |
84
|
0
|
|
|
|
|
|
my $found = 0; |
85
|
0
|
|
|
|
|
|
while ($d =~ /(.*?)<\/table>/isg) { |
86
|
0
|
0
|
|
|
|
|
if ($1) { |
87
|
0
|
|
|
|
|
|
my $n = "$1"; |
88
|
0
|
|
|
|
|
|
my $m = XML::Bare->new(text => $n); |
89
|
0
|
|
|
|
|
|
my $root = $m->parse(); |
90
|
0
|
|
|
|
|
|
for my $t (@{$root->{root}->{tr}}) { |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
for (@{$t->{td}}) { |
|
0
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if ($found) { |
93
|
0
|
|
|
|
|
|
return $BASE_URL . $_->{a}->{href}->{value}; |
94
|
|
|
|
|
|
|
} |
95
|
0
|
0
|
|
|
|
|
next unless $_->{value}; |
96
|
0
|
0
|
|
|
|
|
if ($_->{value} =~ /XBRL INSTANCE DOCUMENT/) { |
97
|
0
|
|
|
|
|
|
$found = 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
return 0; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_filing { |
107
|
0
|
|
|
0
|
0
|
|
my ($sym, $t, $date) = @_; |
108
|
0
|
|
|
|
|
|
my $filing_url = get_filing_url($sym, $t, $date); |
109
|
0
|
|
|
|
|
|
my $xbrl_url = get_xbrl_url($filing_url); |
110
|
0
|
|
|
|
|
|
my $res = $ua->get($xbrl_url); |
111
|
0
|
0
|
|
|
|
|
return 0 unless $res->is_success; |
112
|
0
|
|
|
|
|
|
my $d = $res->content; |
113
|
0
|
|
|
|
|
|
my $m = XML::Bare->new(text => $d); |
114
|
0
|
|
|
|
|
|
my $root = $m->parse(); |
115
|
0
|
|
|
|
|
|
return $root; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |