Guest User

Untitled

a guest
May 24th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # fetch fund quotes from yahoo finance japan
  3.  
  4. use strict;
  5. use warnings;
  6. use XML::LibXML;
  7. use Finance::Quote;
  8.  
  9. # extract fund symbols from gnucash xml file
  10. die 'specify gnucash xml file as argument' unless $ARGV[0];
  11. my $xml = XML::LibXML->load_xml(location => $ARGV[0]);
  12.  
  13. my $xpath = '//gnc:commodity[cmdty:quote_source="yahoo_japan"]/cmdty:id';
  14. my @symbols = map { $_->textContent } $xml->findnodes($xpath);
  15.  
  16. # fetch and print quotes
  17. my $q = Finance::Quote->new()->yahoo_japan(@symbols);
  18.  
  19. my @fields = qw/date time name price currency method/;
  20. for my $sym (@symbols) {
  21. if ($q->{$sym, 'success'}) {
  22. print join("\t", $sym, map { $q->{$sym, $_} } @fields), "\n";
  23. }
  24. }
Add Comment
Please, Sign In to add comment