QuoteDB.pm

filter: Statementstmt 14.4% 37 / 256 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 45.8% 11 / 24 Podpod 100% 13 / 13 totaltotal 16.8% 61 / 363 CC 51 SCAR 44.7
CC
51
Cov
11%
add_yahoo_stocks
277.1
backpopulate
72.0
addstock
72.0
CRAP 87.5
« QuoteDB/Geniustrader.pm ↑ Summary QuoteDB/Schema.pm »
1 package Finance::QuoteDB;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use vars qw/@EXPORT @EXPORT_OK @EXPORT_TAGS $VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Finance::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Bug correction in Finance::QuoteHist
11 # reported on RT #64365
12 # This block can safely be removed once Finance::QuoteHist is corrected
13 BEGIN {
14 2 ▶$Date::Manip::Backend = 'DM5';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 }
16  
17 2 ▶use Finance::QuoteHist;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use HTML::TableExtract;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 require Finance::QuoteDB::Geniustrader;
22  
23 2 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 =head1 NAME
26  
27 Finance::QuoteDB - User database tools based on Finance::Quote
28  
29 =cut
30  
31 2 @EXPORT = ();
32 2 @EXPORT_OK = qw /createdb updatedb addstock/ ;
33 2 @EXPORT_TAGS = ( all => [@EXPORT_OK] );
34  
35 2 our $VERSION = '0.17'; # VERSION
36  
37 =head1 SYNOPSIS
38  
39 Please take a look at script/fqdb which is the command-line frontend
40 to Finance::QuoteDB. Type following command at your command prompt for
41 more information:
42  
43 fqdb --help
44  
45 =head1 METHODS
46  
47 =head2 new
48  
49 new({dsn=>$dsn})
50  
51 =cut
52  
53 sub new {
54 0 ▶ my $self = shift;
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
55 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
56  
57 0 my $this = {} ;
58 0 bless $this, $class;
59  
60 0 my $config = shift ;
61  
62 0 foreach (keys %$config) {
63 0 $this->{$_} = $$config{$_};
64 }
65 0 $this->{logger} = Log::Log4perl::get_logger();
66 0 ▶ if ($ENV{"FQDBDEBUG"}) { # enable debug logging if FQDBDEBUG is set
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'FQDBDEBUG'}) { } 0 0 0
67 0 $this->{logger}->level($DEBUG)
68 } else {
69 0 $this->{logger}->level($INFO)
70 } ;
71 0 ▶ if (my $dsn = $this->{dsn}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dsn = $this->{'dsn'}) { } 0 0 0
72 0 INFO ("CREATED FQDB object based on $dsn\n");
73 } else {
74 0 ERROR ("No dsn specified\n") ;
75 0 die;
76 }
77  
78 0 return $this;
79 }
80  
81 =head2 createdb
82  
83 createdb()
84  
85 =cut
86  
87 sub createdb {
88 0 ▶ my $self = shift;
Subroutine createdb: not called CC=1 SCAR=6.9
Pod documented
89  
90 0 my $dsn = $self->{dsn};
91 0 my $dsnuser = $self->{dsnuser};
92 0 my $dsnpasswd = $self->{dsnpasswd};
93  
94 0 INFO ("COMMAND: Create database $dsn with user $dsnuser\n");
95 0 my $schema = Finance::QuoteDB::Schema->connect_and_deploy($dsn,$dsnuser,$dsnpasswd); # creates the database
96 0 return $schema;
97 }
98  
99 =head2 updatedb
100  
101 updatedb()
102  
103 =cut
104  
105 sub updatedb {
106 0 ▶ my $self = shift ;
Subroutine updatedb: not called CC=3 SCAR=24.8
Pod documented
107  
108 0 my $dsn = $self->{dsn};
109 0 INFO ("COMMAND: Update database $dsn\n");
110  
111 0 my $schema = $self->schema();
112 0 my @stocks = $schema -> resultset('Symbol')->
113 search(undef, { order_by => "fqmarket,fqsymbol",
114 columns => [qw / symbolID fqmarket fqsymbol /] });
115 0 my %symbolIDs ;
116 my %fqsymbols ;
117 0 foreach my $stock (@stocks) {
118 0 my $fqmarket = $stock->fqmarket()->name() ;
119 0 my $symbolID = $stock->symbolID() ;
120 0 my $fqsymbol = $stock->fqsymbol() ;
121 0 ${$symbolIDs{$fqmarket}}{ $fqsymbol } = $symbolID ;
122 0 print ("SCANNING : $fqmarket - $fqsymbol -> $symbolID\n");
123 };
124 0 foreach my $market (keys %symbolIDs) {
125 0 DEBUG "$market -->" .join( "," , keys(%{$symbolIDs{$market}}) ) ."\n" ;
126 0 $self->updatedbMarketStock ( $market , \%{$symbolIDs{$market}} ) ;
127 }
128 }
129  
130 =head2 updatedbMarketStock
131  
132 updatedbMarketStock($market,\%symbolIDs)
133  
134 =cut
135  
136 sub updatedbMarketStock {
137 0 ▶ my ($self,$market,$stockHash) = @_ ;
Subroutine updatedbMarketStock: not called CC=3 SCAR=24.8
Pod documented
138 0 my $schema = $self->schema();
139 0 my @fqsymbols = keys(%{$stockHash}) ;
140 0 DEBUG "UPDATEDBMARKETSTOCK: $market -->" .join(",",@fqsymbols)."\n" ;
141 0 my $q = Finance::Quote->new();
142 0 my %quotes = $q->fetch($market,@fqsymbols);
143 0 foreach my $stock (@fqsymbols) {
144 0 ▶ if ($quotes{$stock,"success"}) { # This quote was retrieved
Branch: 1 branch
BranchTrueFalseTotal
if ($quotes{join $;, $stock, 'success'}) { } 0 0 0
145 0 my $symbolID = ${$stockHash}{$stock} ;
146 0 print ("Updating stock $stock ($symbolID) --> $quotes{$stock,'last'}\n");
147 my $quoters = $schema->resultset('Quote')->update_or_create(
148 { symbolID => $symbolID,
149 date => $quotes{$stock,'isodate'},
150 previous_close => $quotes{$stock,'close'},
151 day_open => $quotes{$stock,'open'},
152 day_high => $quotes{$stock,'high'},
153 day_low => $quotes{$stock,'low'},
154 day_close => $quotes{$stock,'last'},
155 bid => $quotes{$stock,'bid'},
156 ask => $quotes{$stock,'ask'},
157 0 volume => $quotes{$stock,'volume'}
158 });
159 } else {
160 0 print ("Could not retrieve $stock\n");
161 }
162 }
163 };
164  
165 =head2 backpopulate
166  
167 backpopulate($start_date, $end_date, $overwrite, $stocks)
168  
169 =cut
170  
171 sub backpopulate {
172 0 ▶ my ($self, $start_date, $end_date, $overwrite, $stocks) = @_;
Subroutine backpopulate: not called CC=8 SCAR=42.8
Pod documented
173 0 ▶ $end_date = $self->today() if (!$end_date);
Branch: 1 branch
BranchTrueFalseTotal
unless $end_date 0 0 0
174 0 ▶ if (my @symbolIDs = split(",",$stocks)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my @symbolIDs = split(/,/, $stocks, 0)) 0 0 0
175 0 print ("Retrieving data...\n");
176 0 my $schema = $self->schema();
177 0 my %symbolID ;
178 0 foreach my $symbolID (@symbolIDs) {
179 0 my $fqsymbol = $schema -> resultset('Symbol')->single({symbolID => $symbolID})->fqsymbol() ;
180 0 $symbolID{$fqsymbol} = $symbolID ;
181 }
182 0 my @fqsymbols = keys (%symbolID);
183  
184 0 my $q = Finance::QuoteHist->new( symbols => \@fqsymbols,
185 start_date => $start_date,
186 end_date => $end_date );
187 0 my $line = "" ;
188 0 my %symbols ;
189 0 foreach my $row ($q->quotes()) {
190 0 my ($fqsymbol, $date, $open, $high, $low, $close, $volume) = @$row;
191 0 $date =~ tr|/|-|;
192 0 my $tline = substr($date,0,7) ;
193 0 ▶ if ($line ne $tline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne $tline) 0 0 0
194 0 INFO ("$tline") ;
195 0 %symbols = () ;
196 };
197 0 $line = $tline ;
198 0 ▶ if (!$symbols{$fqsymbol}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($symbols{$fqsymbol}) 0 0 0
199 0 $symbols{$fqsymbol}=1;
200 0 INFO (" -> $fqsymbol") ;
201 }
202 0 my %data = ( symbolID => $symbolID{$fqsymbol},
203 date => $date,
204 day_open => $open,
205 day_high => $high,
206 day_low => $low,
207 day_close => $close,
208 volume => $volume
209 ) ;
210 0 ▶ if ($overwrite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overwrite) { } 0 0 0
211 0 $schema->resultset('Quote')->update_or_create( \%data ) ;
212 } else {
213 0 $schema->resultset('Quote')->find_or_create( \%data ) ;
214 }
215 }
216 }
217 }
218  
219 =head2 delstock
220  
221 delstock($stocks)
222  
223 =cut
224  
225 sub delstock {
226 0 ▶ my ($self,$stocks) = @_ ;
Subroutine delstock: not called CC=3 SCAR=24.8
Pod documented
227  
228 0 ▶ if (my @stocks = split(",",$stocks)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my @stocks = split(/,/, $stocks, 0)) { } 0 0 0
229 0 my $schema = $self->schema();
230 0 foreach my $stock (@stocks) {
231 0 print ("Deleting stock $stock\n");
232 0 my $rs = $schema -> resultset('Symbol')->
233 search({'symbolID' => $stock});
234 0 $rs->delete_all();
235 }
236 } else {
237 0 print ("No stocks specified\n") ;
238 }
239 };
240  
241 =head2 addstock
242  
243 addstock($market,$stocks)
244  
245 $stocks is in the format FQsymbol[USERsymbol],...
246 If USERsymbol is ommitted then USERsymbol will be set to FQsymbol
247  
248 =cut
249  
250 sub addstock {
251 0 ▶ my ($self,$market,$stocks) = @_ ;
Subroutine addstock: not called CC=8 SCAR=42.8
Pod documented
252  
253 0 ▶ if (!$market) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $market) { } 0 0 0
254 0 print ("No market specified\n") ;
255 return
256 0 } else {
257 0 print ("Getting stocks from $market\n") ;
258 }
259 0 ▶ if (my @stocks = split(",",$stocks)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my @stocks = split(/,/, $stocks, 0)) { } 0 0 0
260 0 my %symbolIDs ;
261 0 foreach my $stockItem (@stocks) {
262 0 ▶ if ( $stockItem =~ m/([^\[]+)(\[(.+)\])?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stockItem =~ /([^\[]+)(\[(.+)\])?/) 0 0 0
263 0 my ($fqsymbol,$symbolID) = ($1,$3) ;
264 0 ▶ $symbolID = $fqsymbol if (!$symbolID) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $symbolID 0 0 0
265 0 INFO (" Stock $fqsymbol <- $symbolID") ;
266 0 $symbolIDs{$fqsymbol}=$symbolID ;
267 }
268 }
269 0 my @fqsymbols = keys %symbolIDs ;
270 0 my $q = Finance::Quote->new();
271 0 my %quotes = $q->fetch($market,@fqsymbols);
272 0 foreach my $stock (@fqsymbols) {
273 0 print ("Checking stock $stock\n");
274 0 ▶ if ($quotes{$stock,"success"}) { # This quote was retrieved
Branch: 1 branch
BranchTrueFalseTotal
if ($quotes{join $;, $stock, 'success'}) { } 0 0 0
275 0 print (" --> $quotes{$stock,'name'}\n") ;
276 0 my $schema = $self->schema();
277 0 my $marketID = $schema->resultset('FQMarket')->find_or_create({name=>$market})->marketID();
278 $schema->populate('Symbol',
279 [[qw /symbolID name fqmarket fqsymbol isin currency/],
280 0 [$symbolIDs{$stock}, $quotes{$stock,'name'}, $marketID, $stock, '', $quotes{$stock,'currency'} ]]);
281 } else {
282 0 print ("Could not retrieve $stock\n");
283 }
284 }
285 } else {
286 0 print ("No stocks specified\n") ;
287 }
288 };
289  
290 =head2 getquotes
291  
292 getquotes( $USERsymbols, $date_start [,$date_end] )
293  
294 This function returns quotes between $date_start and $date_end for the specified
295 user symbols (comma separated list). Range will be one day if $date_end is
296 omitted.
297  
298 =cut
299  
300 sub getquotes {
301 0 ▶ my ($self,$USERsymbol,$date_start,$date_end) = @_ ;
Subroutine getquotes: not called CC=3 SCAR=24.8
Pod documented
302 0 ▶ $date_end = $date_start if !($date_end) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $date_end 0 0 0
303 0 my $schema = $self->schema();
304  
305 0 my @q = $schema->resultset('Quote')
306 ->search( { symbolID=>$USERsymbol,
307 date=>{'BETWEEN',[$date_start, $date_end]} },
308 { columns=> [qw/ date day_open day_high day_low day_close volume /],
309 order_by=> [qw/ date /] });
310 0 ▶ @q ? return \@q : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
@q ? : 0 0 0
311 }
312  
313 =head2 dumpquotes
314  
315 dumpquotes ( $USERsymbols, $date_start [,$date_end] )
316  
317 This function dumps quotes between $date_start and $date_end for the specified
318 user symbols (comma separated list). Range will be one day if $date_end is
319 omitted.
320  
321 =cut
322  
323 sub dumpquotes {
324 0 ▶ my ($self,$USERsymbols,$date_start,$date_end) = @_ ;
Subroutine dumpquotes: not called CC=6 SCAR=37.4
Pod documented
325 0 ▶ $date_end = $date_start if !($date_end) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $date_end 0 0 0
326 0 my $schema = $self->schema();
327  
328 0 ▶ if (my @stocks = split(",",$USERsymbols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my @stocks = split(/,/, $USERsymbols, 0)) 0 0 0
329 0 foreach my $USERsymbol (@stocks) {
330 0 ▶ if ( my $quotesArray = $self->getquotes ( $USERsymbol, $date_start, $date_end ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $quotesArray = $self->getquotes($USERsymbol, $date_start, $date_end)) { } 0 0 0
331 0 print "STOCK : $USERsymbol\n";
332 0 print "DATE OPEN HIGH LOW CLOSE VOLUME\n" ;
333 0 foreach my $q (@$quotesArray) {
334 0 printf "%10s %8.2f %8.2f %8.2f %8.2f %12d\n",
335 $q->date(), $q->day_open(), $q->day_high(), $q->day_low(), $q->day_close(), $q->volume() ;
336 }
337 } else {
338 0 print "NO DATA for stock $USERsymbol\n";
339 }
340 }
341 }
342 }
343  
344 =head2 dumpstocks
345  
346 dumpstocks ()
347  
348 This function dumps the symbols of the stocks in the database.
349  
350 =cut
351  
352 sub dumpstocks {
353 0 ▶ my $self = shift ;
Subroutine dumpstocks: not called CC=2 SCAR=17.9
Pod documented
354  
355 0 my $dsn = $self->{dsn};
356 0 INFO ("COMMAND: Dump stocks in database $dsn\n");
357  
358 0 my $schema = $self->schema();
359 0 my @stocks = $schema -> resultset('Symbol')->
360 search(undef, { order_by => "symbolID,fqmarket,fqsymbol",
361 columns => [qw / symbolID fqmarket fqsymbol /] });
362 0 print " USERSYMBOL FQMARKET FQSYMBOL\n";
363 0 foreach my $stock (@stocks) {
364 0 my $fqmarket = $stock->fqmarket()->name() ;
365 0 my $symbolID = $stock->symbolID() ;
366 0 my $fqsymbol = $stock->fqsymbol() ;
367 0 printf "%15s %15s %15s\n",$symbolID,$fqmarket,$fqsymbol;
368 };
369 }
370  
371 =head2 add_yahoo_stocks
372  
373 add_yahoo_stocks( $exchanges , [ $refsearchlist ] )
374  
375 retrieves yahoo tickers for specified exchanges and stores them in your database
376 NOTE: $exchanges being the ID as coming from yahoo.
377 NYQ for Nyse, PAR for Paris
378 $refsearchlist is an optional reference to a list of search patterns. defaults to [**AA .. **ZZ]
379  
380 =cut
381  
382 sub add_yahoo_stocks {
383 # http://uk.biz.yahoo.com/p/uk/cpi/index.html -> list of european stocks
384 0 ▶ my ($self,$exchanges,$refsearchlist) = @_ ;
Subroutine add_yahoo_stocks: not called CC=17 SCAR=56.2
Pod documented
385 0 my $popquantity = 30 ; # number of stocks to add in 1 call of addstock
386  
387 0 ▶ if (!defined($exchanges)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $exchanges) { } 0 0 0
388 0 ERROR ("No exchanges specified");
389 } else {
390 0 my %exchanges ;
391 0 foreach (split(',',$exchanges)) {
392 0 $exchanges{$_}=1 ;
393 } ;
394  
395 2 ▶ no strict 'subs' ;
Subroutine BEGIN: called CC=1 SCAR=0.0
396 0 ▶ if (!@$refsearchlist) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$refsearchlist) 0 0 0
397 0 $refsearchlist = [AA .. ZZ] ;
398 0 $$refsearchlist[$_] = "**".$$refsearchlist[$_] foreach (0 .. $#{@$refsearchlist}) ; # add ** in front of each list item
399 }
400 0 DEBUG ("$_") foreach (@$refsearchlist);
401  
402 0 my $ua = LWP::UserAgent->new;
403 0 $ua->env_proxy;
404 0 INFO("Adding symbols from $exchanges.") ;
405  
406 0 my %symbols ;
407  
408 0 foreach my $letter (@$refsearchlist) {
409 0 my $yahoo_url = "http://finance.yahoo.com/lookup?s=$letter&t=S" ; # t=S means ONLY stocks
410  
411 0 my $b = 0 ; # counter in url
412 0 my $cont ;
413 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$cont and do { do { $cont = 1; my $url = $yahoo_url . '&b=' . $b; DEBUG("URL: $url"); my $req = "HTTP::Request"->new("GET", $url); my $reply = $ua->request($req); if ($reply->is_success) { () = (0, 0, 0); if ($reply->content =~ /Showing\s+(\d)+ - (\d+) of\s+(\d+)/) { () = ($1, $2, $3); INFO("For ${letter}: " . int($to * 100 / $total) . ' % completed'); $b = $to; $cont = $to < $total; } ; my $te = "HTML::TableExtract"->new("headers", ["Symbol", "Exchange"]); $te->parse($reply->content); foreach my $ts ($te->tables) { my $countrows = 0; foreach my $tr ($ts->rows) { ++$countrows; my $trsymb = @$tr[0]; $trsymb =~ s/ //g; my $exchsym = @$tr[1]; $exchsym =~ s/ //g; if (defined $exchanges{$exchsym}) { INFO(" Symbol: $trsymb - Exchange $exchsym"); $symbols{$trsymb} += 1; } ; } ; DEBUG("--> $countrows rows"); if ($countrows and $total == 0) { INFO("For ${letter}: 100 % completed"); $cont = 0; } ; } ; } ; if ($cont) { my $sleeptime = int 15 + rand(5); INFO("Sleeping $sleeptime"); sleep $sleeptime; } } } 0 0 0
414 0 $cont = 1; # continue increasing b
415 0 my $url = $yahoo_url."&b=".$b ;
416 0 DEBUG("URL: $url");
417 0 my $req = HTTP::Request->new(GET => $url);
418 0 my $reply = $ua->request($req);
419 0 ▶ if ($reply->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reply->is_success) 0 0 0
420 0 my ($from,$to,$total)=(0,0,0) ;
421 0 ▶ if ($reply->content=~ m|Showing\s+(\d)+ - (\d+) of\s+(\d+)|) { # check if this is last page for this market
Branch: 1 branch
BranchTrueFalseTotal
if ($reply->content =~ /Showing\s+(\d)+ - (\d+) of\s+(\d+)/) 0 0 0
422 0 ($from,$to,$total)=($1,$2,$3);
423 0 INFO ("For $letter: ".int($to*100/$total)." % completed");
424 0 $b=$to; # next page should start at this symbol. actually starts at symbol+1
425 0 $cont = ($to < $total);
426 }
427 # scrape the symbols from this page
428 0 my $te = HTML::TableExtract->new( headers=>[qw /Symbol Exchange/ ] );
429 0 $te->parse($reply->content);
430 0 foreach my $ts ($te->tables) {
431 0 my $countrows = 0;
432 0 foreach my $tr ($ts->rows) {
433 0 $countrows++;
434 0 my $trsymb = @$tr[0] ;
435 0 $trsymb =~ s/ //g ;
436 0 my $exchsym = @$tr[1] ;
437 0 $exchsym =~ s/ //g ;
438 0 ▶ if (defined($exchanges{$exchsym})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $exchanges{$exchsym}) 0 0 0
439 0 INFO (" Symbol: $trsymb - Exchange $exchsym");
440 0 $symbols{$trsymb}+=1 ; # add the symbol as a key in the hash removes duplicates automatically
441 }
442 }
443 0 DEBUG ("--> $countrows rows");
444 0 ▶ if ($countrows && ($total==0)) { # there are rows on this page and we are on the last page (no total)
Branch: 1 branch
BranchTrueFalseTotal
if ($countrows and $total == 0) 0 0 0
Condition0%0/3
$countrows and $total == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$countrows and $total == 0
$countrows $total == 0
Truth table0%0/3
A and B
A= $countrowsB= $total == 0
ABresult
0X0
100
111
445 0 INFO ("For $letter: 100 % completed");
446 0 $cont=0 ;
447 }
448 }
449 }
450 0 ▶ if ($cont) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cont) 0 0 0
451 0 my $sleeptime = int(15+rand(5)) ;
452 0 INFO("Sleeping $sleeptime");
453 0 sleep $sleeptime; # needed otherwise we might overload yahoo server
454 }
455 } while ($cont);
456 }
457  
458 0 my @symbols = sort keys %symbols ;
459 0 ▶ while ($#symbols>0) { # still elements in the array
Branch: 1 branch
BranchTrueFalseTotal
if ($#symbols > 0) 0 0 0
460 0 my $sleeptime = int(10+rand(10)) ;
461 0 INFO("Sleeping $sleeptime");
462 0 sleep $sleeptime; # needed otherwise we might overload yahoo server
463 0 my $stocks = join (",",splice(@symbols,0,$popquantity)); # take $popquantity number of elements out
464 # my $stocks = join (",",@symbols[0..$popquantity-1]);
465 # @symbols = @symbols[$popquantity+1..$#symbols-1];
466 0 INFO (" Adding stocks: $stocks");
467 0 $self->addstock('yahoo',$stocks); # add stocks in database
468 }
469 }
470 0 INFO("Finished adding stocks from yahoo");
471 }
472  
473 =head2 schema
474  
475 schema()
476  
477 If necessary, creates a DBIx::Class::Schema and returns a reference to that DBIx::Class::Schema.
478  
479 =cut
480  
481 sub schema {
482 0 ▶ my $self = shift ;
Subroutine schema: not called CC=3 SCAR=24.8
Pod documented
483 0 my $dsn = $self->{dsn};
484 0 my $dsnuser = $self->{dsnuser};
485 0 my $dsnpasswd = $self->{dsnpasswd};
486 0 ▶ if (!$self->{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"schema"}) 0 0 0
487 0 ▶ if (my $schema = Finance::QuoteDB::Schema->connect($dsn,$dsnuser,$dsnpasswd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = 'Finance::QuoteDB::Schema'->connect($dsn, $dsnuser, $dsnpasswd)) { } 0 0 0
488 0 INFO ("Connected to database $dsn\n");
489 0 $self->{schema} = $schema ;
490 } else {
491 0 ERROR ("Could not connect to database $dsn\n") ;
492 0 die ;
493 }
494 }
495 return $self->{schema}
496 0 }
497  
498 =head2 today
499  
500 today()
501  
502 returns current date in isodate format
503  
504 =cut
505  
506 sub today {
507 0 ▶ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
Subroutine today: not called CC=1 SCAR=6.9
Pod documented
508 0 return ($year+1900)."-".sprintf('%02d',$mon+1)."-".sprintf('%02d',$mday) ;
509 }
510  
511 =head1 AUTHOR
512  
513 Erik Colson, C<< <eco at ecocode.net> >>
514  
515 =head1 BUGS
516  
517 Please report any bugs or feature requests to C<bug-finance-quotedb at
518 rt.cpan.org>, or through the web interface at
519 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Finance-QuoteDB>. I will be
520 notified, and you'll automatically be notified of progress on your bug as I make
521 changes.
522  
523 =head1 SUPPORT
524  
525 You can find documentation for this module with the perldoc command.
526  
527 perldoc Finance::QuoteDB
528  
529  
530 You can also look for information at:
531  
532 =over 4
533  
534 =item * RT: CPAN's request tracker
535  
536 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Finance-QuoteDB>
537  
538 =item * AnnoCPAN: Annotated CPAN documentation
539  
540 L<http://annocpan.org/dist/Finance-QuoteDB>
541  
542 =item * CPAN Ratings
543  
544 L<http://cpanratings.perl.org/d/Finance-QuoteDB>
545  
546 =item * Search CPAN
547  
548 L<http://search.cpan.org/dist/Finance-QuoteDB>
549  
550 =item * Mailing list
551  
552 You can subscribe to the mailing list by sending an email to
553 fqdb-dev@lists.tuxfamily.org with subject : subscribe
554  
555 =back
556  
557  
558 =head1 ACKNOWLEDGEMENTS
559  
560  
561 =head1 COPYRIGHT & LICENSE
562  
563 Copyright 2008-2015 Erik Colson, all rights reserved.
564  
565 This file is part of Finance::QuoteDB.
566  
567 Finance::QuoteDB is free software: you can redistribute it and/or
568 modify it under the terms of the GNU General Public License as
569 published by the Free Software Foundation, either version 3 of the
570 License, or (at your option) any later version.
571  
572 Finance::QuoteDB is distributed in the hope that it will be useful,
573 but WITHOUT ANY WARRANTY; without even the implied warranty of
574 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
575 General Public License for more details.
576  
577 You should have received a copy of the GNU General Public License
578 along with Finance::QuoteDB. If not, see
579 <http://www.gnu.org/licenses/>.
580  
581 =cut
582  
583 2 1; # End of Finance::QuoteDB
« QuoteDB/Geniustrader.pm ↑ Summary QuoteDB/Schema.pm »