Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # fetch fund quotes from yahoo finance japan
- 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()->yahoo_japan(@symbols);
- my @fields = qw/date time name price currency method/;
- for my $sym (@symbols) {
- if ($q->{$sym, 'success'}) {
- print join("\t", $sym, map { $q->{$sym, $_} } @fields), "\n";
- }
- }
Add Comment
Please, Sign In to add comment