Currency Get Online Quotes MTL
AmigaPhil
AmigaPhil at ping.be
Sat Aug 8 18:45:57 EDT 2009
Keith Bellairs wrote:
> Still broken for currency:USD in fedora 10 packaging of 2.2.9
The "online currency quote" problem has nothing to do with GnuCash;
it's a Finance::Quote issue.
This problem is known and a patch has already been applied to fix it
for the next release of Finance::Quote (most probably v1.17).
(The bug report is here:
http://rt.cpan.org/Public/Bug/Display.html?id=46006 )
Either you have to wait for the public release of F::Q 1.17, or you
can apply the patch in the meantime (or have your distribution
source doing it for you).
I've attached the selected patch here as well for your convenience if
you want to apply the patch yourself. Help on how to patch "by hand"
with a text editor is available here:
http://lists.gnucash.org/pipermail/gnucash-user/2009-August/030740.html
AmigaPhil
> Richard Ullger <rullger at ntlworld.com> wrote:
>
>> Derek,
>>
>> I've installed an Ubuntu backport from launchpad, v2.2.9 built from
>> r17949M on 2009-06-04 but the problem is still there.
>>
>> I did a search on bugzilla to determine when this may have been fixed
>> but could not find a bug report specific to this problem.
>>
-------------- next part --------------
@@ -35,16 +35,15 @@ use Exporter ();
use Carp;
use Finance::Quote::UserAgent;
use HTTP::Request::Common;
-use HTML::TableExtract;
+use HTML::TreeBuilder;
use Encode;
+use Data::Dumper;
use vars qw/@ISA @EXPORT @EXPORT_OK @EXPORT_TAGS
$VERSION $TIMEOUT %MODULES %METHODS $AUTOLOAD
$YAHOO_CURRENCY_URL $USE_EXPERIMENTAL_UA/;
-$YAHOO_CURRENCY_URL = "http://uk.finance.yahoo.com/currency/convert?amt=1&submit=Convert&";
-# If the above URL ever fails, try rewriting this module to use the URL below.
-# $YAHOO_CURRENCY_URL = "http://uk.finance.yahoo.com/q?s=USDCAD%3DX";
+$YAHOO_CURRENCY_URL = "http://uk.finance.yahoo.com/q?s=";
@ISA = qw/Exporter/;
@EXPORT = ();
@@ -241,16 +240,23 @@ sub currency {
my $ua = $this->user_agent;
- my $data = $ua->request(GET "${YAHOO_CURRENCY_URL}from=$from&to=$to")->content;
- my $te = HTML::TableExtract->new( headers => ['Symbol', 'Bid', 'Ask'] );
- $te->parse(decode_utf8($data)); # The web page returns utf8 content which gives
- # a warning when parsing $data in HTML::Parser
+ my $data = $ua->request(GET "${YAHOO_CURRENCY_URL}$from$to%3DX")->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));
- # Make sure there's a table to parse.
- return undef unless ($te->tables);
+ # 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;
+
+ my $exchange_rate=$rate_element->as_text;
- my $row = ($te->rows())[0];
- my ($exchange_rate) = $$row[1];
$exchange_rate =~ s/,// ; # solve a bug when conversion rate
# involves thousands. yahoo inserts
# a comma when thousands occur
More information about the gnucash-user
mailing list