App-Chart
view release on metacpan or search on metacpan
devel/weblinks-samples.pl view on Meta::CPAN
#!/usr/bin/perl -w
# Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2016 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/>.
# Usage: ./weblinks-samples.pl
#
# Check weblink URLs for various symbols. The URLs are checked by making a
# "HEAD" request, so there's no great amount downloaded, except for a couple
# of data sources which may do extra downloading to find the link
# (eg. .BEN).
#
# Because this program does online interaction it's not run by "make
# check".
#
# Misfeatures:
#
# finance.yahoo.com gives a page with a message for an unknown symbol, so a
# HEAD is not much good there.
#
use strict;
use warnings;
use App::Chart::Weblink;
my %attempted_urls;
print <<'HERE';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>
HERE
my $errors = '';
sub attempt {
my @symbol_list = @_;
my $langs = [ undef ];
if (ref $symbol_list[0]) {
$langs = shift @symbol_list;
}
foreach my $lang (@$langs) {
local $ENV{'LANGUAGE'} = $lang;
foreach my $symbol (@symbol_list) {
my @weblinks = App::Chart::Weblink->links_for_symbol ($symbol);
if (! @weblinks) {
$errors .= "No weblinks for $symbol\n";
next;
}
foreach my $weblink (@weblinks) {
my $name = $weblink->name;
my $url = $weblink->url ($symbol);
if (! defined $url) { next; }
# finance.yahoo.com gives a page with a message for an unknown
# symbol, so no point checking it
if ($url =~ /finance\.yahoo\.com/) { next; }
if ($attempted_urls{$url}) { next; }
$attempted_urls{$url} = 1;
print "<br> <a href=\"$url\">$symbol $name</a>\n";
}
}
}
}
# london
attempt ('TSCO.L', 'BLT.L', 'TPSD.IL');
# nybot-info
# (let ((nybot-specs-list (@@ (chart nybot) nybot-specs-list)))
# (for-each (lambda (elem)
# (attempt (string-append (first (car elem)) '.NYBOT')))
# nybot-specs-list))
# nybot
attempt ('CC.NYB');
# cbot-info
# (let ((cbot-specs-list (@@ (chart cbot) cbot-specs-list)))
# (for-each (lambda (elem)
# (attempt (string-append (first (car elem)) '.CBOT')))
# cbot-specs-list))
# hamburg
( run in 0.592 second using v1.01-cache-2.11-cpan-39bf76dae61 )