App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Finance/Yahoo/Exchanges.pm view on Meta::CPAN
# Copyright 2007, 2008, 2009, 2010, 2017 Kevin Ryde
# This file is part of Chart.
#
# Chart is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3, or (at your option) any later version.
#
# Chart is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
# Currently unused ...
package App::Chart::Finance::Yahoo::Exchanges;
use 5.006;
use strict;
use warnings;
use Locale::TextDomain ('App-Chart');
# This looks at the exchanges page
#
# use constant URL => 'http://finance.yahoo.com/exchanges';
use constant URL => 'https://help.yahoo.com/kb/SLN2310.html';
# Refetch the exchanges page after this many days
#
use constant UPDATE_DAYS => 7;
# return a hashref of exchange delay data like { '.AX' => 20, '.BI' => 15 }
sub exchanges_data {
require App::Chart::Pagebits;
return App::Chart::Pagebits::get
(name => __('Yahoo exchanges page'),
url => URL,
key => 'yahoo-quote-delays',
freq_days => UPDATE_DAYS,
parse => \&parse_html);
}
sub parse_html {
my ($content) = @_;
my @entries;
my $h = { entries => \@entries,
timestamp => timestamp_now(),
};
require HTML::TableExtract;
my $te = HTML::TableExtract->new
(headers => [ 'Country',
'Exchange',
'Suffix',
'Delay',
'Provider' ]);
$te->parse($content);
if (! $te->tables) {
warn "Yahoo exchanges page unrecognised, assuming 15 min quote delay";
return $h;
}
foreach my $row ($te->rows) {
my %entry;
@entry{'country','exchange','suffix','delay_minutes','provider'} = @$row;
# wash two spaces in "Chicago Mercantile ..." to one
foreach (values %entry) { s/\s+/ /g; }
# US suffix N/A means no suffix
if ($entry{'suffix'} eq 'N/A') { $entry{'suffix'} = ''; }
# Delay like "15 min", or "15 min**" with footnote for NS India
#
if ($entry{'delay_minutes'} =~ /^(\d+) min/) {
$entry{'delay_minutes'} = $1;
} else {
warn "Yahoo exchanges page unrecognised delay: \"$entry{delay_minutes}\"\n";
$entry{'delay_minutes'} = 20; # assumed default
}
push @entries, \%entry;
( run in 0.831 second using v1.01-cache-2.11-cpan-39bf76dae61 )