Created
May 4, 2010 02:53
-
-
Save LiosK/388885 to your computer and use it in GitHub Desktop.
a simple perl script to fetch fund quotes from yahoo finance japan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# fetch fund quotes from yahoo finance japan | |
use utf8; | |
use strict; | |
use warnings; | |
use XML::LibXML; | |
use Finance::Quote; | |
# extract fund symbols from gnucash xml file | |
die 'specify gnucash xml file as argument' unless $ARGV[0]; | |
my $xml = XML::LibXML->load_xml(location => $ARGV[0]); | |
my $xpath = '//gnc:commodity[cmdty:quote_source="yahoo_japan"]/cmdty:id'; | |
my @symbols = map { $_->textContent } $xml->findnodes($xpath); | |
# fetch and print quotes | |
my $q = Finance::Quote->new('-defaults', 'YahooJapan')->yahoo_japan(@symbols); | |
my @fields = qw/isodate time name price currency method/; | |
for my $sym (@symbols) { | |
if ($q->{$sym, 'success'}) { | |
print join("\t", $sym, map { $q->{$sym, $_} } @fields), "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment