/usr/share/perl5/Finance/Quote/MorningstarJP.pm is in libfinance-quote-perl 1.38-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | #
# Copyright (C) 2012, Christopher Hill
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# $Id: $
#
package Finance::Quote::MorningstarJP;
require 5.006;
use strict;
use warnings;
use base 'Exporter';
use DateTime;
use vars qw( $MORNINGSTAR_JP_URL);
our @EXPORT_OK = qw(morningstarjp methods labels);
our $VERSION = '1.38'; # VERSION
# NAV information (basis price)
$MORNINGSTAR_JP_URL =
('http://www.morningstar.co.jp/FundData/DownloadStdYmd.do?fnc=');
sub methods { return ( morningstarjp => \&morningstarjp ); }
sub labels { return ( morningstarjp => [qw/symbol date nav/] ); }
sub morningstarjp
{
my @symbols = @_;
my $quoter = shift;
my (
$ua, $response, %info, $date, $nav, $year,
$month, $day, $fmyear, $fmmonth, $fmday, @data
);
$ua = $quoter->user_agent;
# calculate beginning and end date
# Starting from 10 days prior (to cover any recent holiday gaps)
my $calcDay = DateTime->now();
$year = $calcDay->year();
$month = $calcDay->month();
$day = $calcDay->day();
$calcDay->subtract( days => 10 );
$fmyear = $calcDay->year();
$fmmonth = $calcDay->month();
$fmday = $calcDay->day();
# Iterate over each symbol as site only permits query by single security
foreach my $symbol (@symbols)
{
# Query the server via a POST request
$response = $ua->post(
$MORNINGSTAR_JP_URL . $symbol,
[
selectStdYearFrom => $fmyear,
selectStdMonthFrom => $fmmonth,
selectStdDayFrom => $fmday,
selectStdYearTo => $year,
selectStdMonthTo => $month,
selectStdDayTo => $day,
base => '0' # 0 is daily, 1 is week ends (Friday), 2 is month ends only
],
);
# Check response, CSV data is in an octet-stream
if ( $response->is_success
&& $response->content_type eq 'application/octet-stream' )
{
# Parse...
# First row (in Shift-JIS) is fixed. It means "date","basis price"
# 日付,基準価額
# Subsequent rows are in ascending chronological order
# date(yyyymmdd),nav
#
# Split the data on CRLF or LF boundaries
@data = split( '\015?\012', $response->content );
# We only care about the final row as that has the most recent data
( $date, $nav ) = $quoter->parse_csv( $data[-1] );
# Store the retrieved data into the hash
( $year, $month, $day ) = ( $date =~ m/(\d{4})(\d{2})(\d{2})/ );
$quoter->store_date( \%info, $symbol,
{ year => $year, month => $month, day => $day } );
$info{ $symbol, 'currency' } = 'JPY';
$info{ $symbol, 'method' } = 'MorningstarJP';
$info{ $symbol, 'name' } = $symbol;
$info{ $symbol, 'nav' } = $nav;
$info{ $symbol, 'success' } = 1;
$info{ $symbol, 'symbol' } = $symbol;
} elsif ( $response->is_success
&& $response->content_type eq 'text/html' )
{
# HTML response that means POST was invalid and/or rejected.
$info{ $symbol, 'errormsg' } = 'Invalid search criteria';
$info{ $symbol, 'success' } = 0;
} else
{
# Unknown error encountered.
$info{ $symbol, 'errormsg' } = 'Search unavailable';
$info{ $symbol, 'success' } = 0;
}
}
return wantarray() ? %info : \%info;
}
1;
__END__
=head1 NAME
Finance::Quote::MorningstarJP - Obtain price data from Morningstar (Japan).
=head1 VERSION
This documentation describes version 1.00 of MorningstarJP.pm, October 13, 2012.
=head1 SYNOPSIS
use Finance::Quote;
$q = Finance::Quote->new;
%info = $q->fetch("morningstarjp", "2009100101");
=head1 DESCRIPTION
This module obtains information from Morningstar (Japan),
L<http://www.morningstar.co.jp/>.
Information returned by this module is governed by Morningstar
(Japan)'s terms and conditions.
=head1 FUND SYMBOLS
Use the numeric symbol shown in the URL on the "SnapShot" page
of the security of interest.
e.g. For L<http://www.morningstar.co.jp/FundData/SnapShot.do?fnc=2009100101>,
one would supply 2009100101 as the symbol argument on the fetch API call.
=head1 LABELS RETURNED
The following labels may be returned by Finance::Quote::MorningstarJP:
symbol, date, nav.
=head1 REQUIREMENTS
Perl 5.006
Date/Calc.pm
Exporter.pm (included with Perl)
=head1 ACKNOWLEDGEMENTS
Inspired by other modules already present with Finance::Quote
=head1 AUTHOR
Christopher Hill
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2012, Christopher Hill.
This program 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 of the License, or
(at your option) any later version.
=head1 DISCLAIMER
This program 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.
=head1 SEE ALSO
Morningstar (Japan), L<http://www.morningstar.co.jp/>
=cut
|