Skip to content

Instantly share code, notes, and snippets.

@LiosK
Created May 4, 2010 02:53
Show Gist options
  • Save LiosK/388885 to your computer and use it in GitHub Desktop.
Save LiosK/388885 to your computer and use it in GitHub Desktop.
a simple perl script to fetch fund quotes from yahoo finance japan
#!/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