Subject: | Currency conversion issue |
It seems to that Finance::Quote is unable to convert currencies via
yahoo since at least today. I use Finance::Quote 1.17 in GnuCash to
retrieve currency exchange rates. Last successful retrieval was on
2012-01-31, my first failed attempt was today (2012-02-03). GnuCash
prints the error message that it was unable to retrieve the quotes.
Using the following code snippet from http://finance-
quote.sourceforge.net/tpj/finance-quote.txt (I'm not Perl-savvy at all)
I could reproduce the problem:
#!/usr/bin/perl -w
use strict;
use Finance::Quote;
# Command-line currency conversion.
die "Usage: $0 FROM TO\n" unless defined($ARGV[1]);
my $quoter = Finance::Quote->new();
my $exchange_rate = $quoter->currency($ARGV[0],$ARGV[1]);
die "Don't know how to convert $ARGV[0] to $ARGV[1]\n" unless
$exchange_rate;
print "$ARGV[0] -> $ARGV[1] = $exchange_rate\n";
__END__
This script output for all currency combinations I tried "Don't know how
to convert <arg0> to <arg1>".
Skimming through the currency sub routine I discovered the following
code (Quote.pm line 256):
my $data = $ua->request(GET "${YAHOO_CURRENCY_URL}$from$to%3DX")-
Show quoted text
>content;
# The web page returns utf8 content which gives a warning when parsing
$data
# in HTML::Parser
my $tb = HTML::TreeBuilder->new_from_content(decode_utf8($data));
# Find the <div> with the data
my $div = $tb->look_down('id','yfi_quote_summary_data');
# Make sure there's a <div> to parse.
return undef unless $div;
# The first <b> should contain the quote
my $rate_element=$div->look_down('_tag','b');
# Make sure there's a <b> to parse.
return undef unless $rate_element;
When inspecting the result web page (i.e. http://uk.finance.yahoo.com/q?
s=EURAUD%3DX) with Google Chrome I discovered that the exchange rate is
contained in span#yfs_l10_euraud=x not within the first b-element in
div#yfi_quote_summary_data (there is no b-element at all in that div).
Unfortunately I can't say for sure if I am missing something or this is
a recent change of Yahoo since I never inspected the web page or
Quote.pm before this issue nor can I provide a patch.
Is this a valid bug?