Skip Menu |

This queue is for tickets about the Finance-Quote CPAN distribution.

Report information
The Basics
Id: 74660
Status: resolved
Worked: 30 min
Priority: 0/
Queue: Finance-Quote

People
Owner: eco [...] ecocode.net
Requestors: bazzinga59 [...] live.de
Cc: jquelin [...] cpan.org
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.17
Fixed in: (no value)



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?
From: mta [...] umich.edu
Yes, Yahoo changed their web site which broke Finance Quote. The currency quote code tries two different URLs. One of the change several months ago and F::Q fell back to the other. This one changed at the end of January. The patch I've attached fixes both of them.
Subject: currency1.diff
--- lib/Finance/Quote.pm 2012-02-04 19:47:54.000000000 -0500 +++ lib/Finance/Quote.pm 2012-02-05 00:38:07.000000000 -0500 @@ -45,7 +45,7 @@ $USE_EXPERIMENTAL_UA/; $YAHOO_CURRENCY_URL = "http://uk.finance.yahoo.com/q?s="; -$YAHOO_CURRENCY_QUOTES_URL = "http://uk.finance.yahoo.com/d/quotes.csv?e=.csv&f=l&s="; +$YAHOO_CURRENCY_QUOTES_URL = "http://uk.finance.yahoo.com/d/quotes.csv?e=.csv&f=l1&s="; @ISA = qw/Exporter/; @EXPORT = (); @@ -251,13 +251,15 @@ 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'); + my $div = $tb->look_down('id','yfi_investing_content'); # 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. + # Find the <span> that contains the quote + my $lcfrom = lc($from); + my $lcto = lc($to); + my $rate_element=$div->look_down('id', "yfs_l10_$lcfrom$lcto=x"); + # Make sure there's a <span> to parse. return undef unless $rate_element; my $exchange_rate=$rate_element->as_text;
On Sun Feb 05 01:21:00 2012, malexander wrote: Show quoted text
> Yes, Yahoo changed their web site which broke Finance Quote. The > currency quote code tries two different URLs. One of the change several > months ago and F::Q fell back to the other. This one changed at the end > of January. The patch I've attached fixes both of them.
patch doesn't apply cleanly on a 1.17 tarball.
attached patch is applying on bare 1.17
Subject: Finance-Quote-1.17-fix_yahoo_urls_rt74660.patch
--- lib/Finance/Quote.pm.orig 2012-02-15 10:28:52.000000000 +0100 +++ lib/Finance/Quote.pm 2012-02-15 10:30:04.000000000 +0100 @@ -246,13 +246,15 @@ 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'); + my $div = $tb->look_down('id','yfi_investing_content'); # 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. + # Find the <span> that contains the quote + my $lcfrom = lc($from); + my $lcto = lc($to); + my $rate_element=$div->look_down('id', "yfs_l10_$lcfrom$lcto=x"); + # Make sure there's a <span> to parse. return undef unless $rate_element; my $exchange_rate=$rate_element->as_text;
Currency problem is solved in branch YahooApi2012. Will be merged into master today. thanks for all the help -- Erik