Skip Menu |

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

Report information
The Basics
Id: 64897
Status: open
Priority: 0/
Queue: Finance-Quote

People
Owner: Nobody in particular
Requestors: ste [...] shared-files.de
Cc:
AdminCc:

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



Subject: GoldMoney site has changed (patch attached)
the goldmoney site has been updated recently and they now allow to purchase palladium as well. attached are two patches for the GoldMoney.pm module and its test. stephan
Subject: 0002-support-palladium-lookup.patch
From e410b33151f394d76219a0f0de24de232f4e8750 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Tue, 18 Jan 2011 20:47:11 +0100 Subject: [PATCH] support 'palladium' lookup --- lib/Finance/Quote/GoldMoney.pm | 46 +++++++++++++++++++++++++++++++-------- t/goldmoney.t | 13 +++++++++- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/Finance/Quote/GoldMoney.pm b/lib/Finance/Quote/GoldMoney.pm index 2081652..03b5b5a 100644 --- a/lib/Finance/Quote/GoldMoney.pm +++ b/lib/Finance/Quote/GoldMoney.pm @@ -7,7 +7,7 @@ # Copyright (C) 2000, Brent Neal <brentn@users.sourceforge.net> # Copyright (C) 2000, Volker Stuerzl <volker.stuerzl@gmx.de> # Copyright (C) 2006, Klaus Dahlke <klaus.dahlke@gmx.de> -# Copyright (C) 2008, Stephan Ebelt <stephan.ebelt@gmx.de> +# Copyright (C) 2011, Stephan Ebelt <ste -at- shared-files -dot- de> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,6 @@ require 5.005; require Crypt::SSLeay; use HTTP::Request::Common; -use HTML::TableExtract; use HTML::TreeBuilder; use strict; @@ -51,7 +50,8 @@ sub labels { # goldmoney($quoter, @symbols) # -# - get 'gold' and 'silver' spot rates from goldmoney.com +# - get 'gold', 'silver', 'platinum' and 'palladium' spot rates from +# goldmoney.com # - error out properly (that is: ignore) all other symbols # sub goldmoney { @@ -64,12 +64,14 @@ sub goldmoney { my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $tree, $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency + $html_string, $tree, $gold_oz, $silver_oz, $platinum_oz, + $palladium_oz, $currency ); my $_want_gold = 0; my $_want_silver = 0; my $_want_platinum = 0; + my $_want_palladium = 0; # - feed all requested symbols into %info (to be returned later) # - set error state to false by default @@ -86,8 +88,10 @@ sub goldmoney { $_want_silver = 1; } elsif($s eq 'platinum') { $_want_platinum = 1; + } elsif($s eq 'palladium') { + $_want_palladium = 1; } else { - $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold' and 'silver')"; + $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold', 'silver', 'platinum' and 'palladium')"; } } @@ -185,6 +189,28 @@ sub goldmoney { $info{'platinum','currency'} = $currency; $info{'platinum','success'} = 1; } + + # get palladium rate + # + if( $_want_palladium ) { + $_ = $tree->look_down("_tag", "span", "id", "spot-price-palladium-oz"); + + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { + $palladium_oz = $1; + $palladium_oz =~ s/,//g; + } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'palladium', {isodate => _goldmoney_time('isodate')}); + $info{'palladium','time'} = _goldmoney_time('time'); + $info{'palladium','name'} = 'Palladium Spot'; + $info{'palladium','last'} = $palladium_oz; + $info{'palladium','price'} = $palladium_oz; + $info{'palladium','currency'} = $currency; + $info{'palladium','success'} = 1; + } } return wantarray() ? %info : \%info; @@ -232,12 +258,12 @@ Finance::Quote::GoldMoney - obtain spot rates from GoldMoney. $q = Finance::Quote->new; - %rates = $q->fetch('goldmoeny','gold', 'silver', 'platinum'); + %rates = $q->fetch('goldmoney','gold', 'silver', 'platinum', 'palladium'); =head1 DESCRIPTION -This module obtains current spot rates for 'gold', 'silver' and -'platinum' from Goldmoney (http://www.goldmoney.com). All other +This module obtains current spot rates for 'gold', 'silver', 'platinum' +and 'palladium' from GoldMoney (http://goldmoney.com). All other symbols are ignored. Information returned by this module is governed by Net Transactions @@ -251,8 +277,8 @@ The following labels are returned by Finance::Quote::GoldMoney: - exchange - name - date, time - - price (per ounce), price_gg (per goldgram, gold only), - price_pg (per platinumgram, platinum only) + - price (per ounce) + - last (per ounce, same as 'price') - currency =head1 SEE ALSO diff --git a/t/goldmoney.t b/t/goldmoney.t index fe656a7..592515e 100755 --- a/t/goldmoney.t +++ b/t/goldmoney.t @@ -7,12 +7,12 @@ if (not $ENV{ONLINE_TEST}) { plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; } -plan tests => 26; +plan tests => 34; # Test GoldMoney functions. my $q = Finance::Quote->new("GoldMoney"); $q->set_currency('EUR'); -my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "BOGUS"); +my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "palladium", "BOGUS"); ok(%quotes); # Check that sound information is returned for gold, silver and platinum. @@ -39,6 +39,13 @@ ok($quotes{"platinum","currency"} eq "EUR"); ok(length($quotes{"platinum","date"}) > 0); ok(length($quotes{"platinum","time"}) > 0); +ok($quotes{"palladium","success"}, 'palladium price lookup'); +ok($quotes{"palladium","last"} > 0); +ok( $quotes{"palladium","last"} !~ /^0/ ); +ok($quotes{"palladium","currency"} eq "EUR"); +ok(length($quotes{"palladium","date"}) > 0); +ok(length($quotes{"palladium","time"}) > 0); + my $year = (localtime())[5] + 1900; ok((substr($quotes{"gold","isodate"},0,4) == $year)); ok((substr($quotes{"gold","date"},6,4) == $year)); @@ -46,6 +53,8 @@ ok((substr($quotes{"silver","isodate"},0,4) == $year)); ok((substr($quotes{"silver","date"},6,4) == $year)); ok((substr($quotes{"platinum","isodate"},0,4) == $year)); ok((substr($quotes{"platinum","date"},6,4) == $year)); +ok((substr($quotes{"palladium","isodate"},0,4) == $year)); +ok((substr($quotes{"palladium","date"},6,4) == $year)); # Check that a bogus symbol returns no-success. ok(! $quotes{"BOGUS","success"}); -- 1.5.5.6
Subject: 0001-adopted-to-site-changes.patch
From da395b7bf039ce13e50e0da8a6c3dbd84427aa2e Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Tue, 18 Jan 2011 20:33:09 +0100 Subject: [PATCH] adopted to site changes they dropped pretty much all tables, therefore we use HTML::TreeBuilder now --- lib/Finance/Quote/GoldMoney.pm | 102 ++++++++++++++++++--------------------- 1 files changed, 47 insertions(+), 55 deletions(-) diff --git a/lib/Finance/Quote/GoldMoney.pm b/lib/Finance/Quote/GoldMoney.pm index dc7c781..2081652 100644 --- a/lib/Finance/Quote/GoldMoney.pm +++ b/lib/Finance/Quote/GoldMoney.pm @@ -32,6 +32,7 @@ require Crypt::SSLeay; use HTTP::Request::Common; use HTML::TableExtract; +use HTML::TreeBuilder; use strict; use warnings; @@ -58,11 +59,12 @@ sub goldmoney { my @symbols = @_; return unless @symbols; + my $GOLDMONEY_URL = "http://goldmoney.com"; + my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $te, $table_gold, $table_silver, $table_platinum, - $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency + $html_string, $tree, $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency ); my $_want_gold = 0; @@ -92,18 +94,14 @@ sub goldmoney { # get the page # - but only if we want either gold, silver or platinum (there is nothing else there) if( $_want_gold or $_want_silver or $_want_platinum) { - my $GOLDMONEY_URL = "http://goldmoney.com"; my $response = $ua->request(GET $GOLDMONEY_URL); if ($response->is_success) { $html_string =$response->content; - # we want the 'Current Spot Rates' table - $te = new HTML::TableExtract->new( attribs=>{class=>'spot'}, subtables=>1); - $te->parse($html_string); - $table_gold=$te->table(3,0); - $table_silver=$te->table(3,1); - $table_platinum=$te->table(3,2); + # setup the HTML tag tree + $tree = new HTML::TreeBuilder->new(); + $tree->parse($html_string); } else { # retrieval error - flag an error and return right away foreach my $s (@symbols) { @@ -125,73 +123,67 @@ sub goldmoney { # get gold rate # if( $_want_gold ) { - $_ = $table_gold->cell(0,0); - if( /(\d*\.\d*).*\/gg/ ) { - $gold_gg = $1; - } + $_ = $tree->look_down("_tag", "span", "id", "spot-price-gold-oz"); - $_ = $table_gold->cell(0,0); - if( /([,\d]*\.\d*).*\/oz/ ) { + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $gold_oz = $1; $gold_oz =~ s/,//g; - - # assemble final dataset - # - take "now" as date/time as the site is always current and does - # not provide this explicitly - so there is a time-slip - $quoter->store_date(\%info, 'gold', {isodate => _goldmoney_time('isodate')}); - $info{'gold','time'} = _goldmoney_time('time'); - $info{'gold','name'} = 'Gold Spot'; - $info{'gold','last'} = $gold_oz; - $info{'gold','price'} = $gold_oz; - $info{'gold','price_gg'} = $gold_gg; - $info{'gold','currency'} = $currency; - $info{'gold','success'} = 1; } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'gold', {isodate => _goldmoney_time('isodate')}); + $info{'gold','time'} = _goldmoney_time('time'); + $info{'gold','name'} = 'Gold Spot'; + $info{'gold','last'} = $gold_oz; + $info{'gold','price'} = $gold_oz; + $info{'gold','currency'} = $currency; + $info{'gold','success'} = 1; } # get silver rate # if( $_want_silver ) { - $_ = $table_silver->cell(0,0); - if( /([,\d]*\.\d*).*\/oz/ ) { + $_ = $tree->look_down("_tag", "span", "id", "spot-price-silver-oz"); + + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $silver_oz = $1; $silver_oz =~ s/,//g; - - $quoter->store_date(\%info, 'silver', {isodate => _goldmoney_time('isodate')}); - $info{'silver','time'} = _goldmoney_time('time'); - $info{'silver','name'} = 'Silver Spot'; - $info{'silver','last'} = $silver_oz; - $info{'silver','price'} = $silver_oz; - $info{'silver','currency'} = $currency; - $info{'silver','success'} = 1; } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'silver', {isodate => _goldmoney_time('isodate')}); + $info{'silver','time'} = _goldmoney_time('time'); + $info{'silver','name'} = 'Silver Spot'; + $info{'silver','last'} = $silver_oz; + $info{'silver','price'} = $silver_oz; + $info{'silver','currency'} = $currency; + $info{'silver','success'} = 1; } # get platinum rate # if( $_want_platinum ) { - $_ = $table_platinum->cell(0,0); - if( /(\d*\.\d*).*\/pg/ ) { - $platinum_pg = $1; - } + $_ = $tree->look_down("_tag", "span", "id", "spot-price-platinum-oz"); - $_ = $table_platinum->cell(0,0); - if( /([,\d]*\.\d*).*\/oz/ ) { + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $platinum_oz = $1; $platinum_oz =~ s/,//g; - - # assemble final dataset - # - take "now" as date/time as the site is always current and does - # not provide this explicitly - so there is a time-slip - $quoter->store_date(\%info, 'platinum', {isodate => _goldmoney_time('isodate')}); - $info{'platinum','time'} = _goldmoney_time('time'); - $info{'platinum','name'} = 'Platinum Spot'; - $info{'platinum','last'} = $platinum_oz; - $info{'platinum','price'} = $platinum_oz; - $info{'platinum','price_pg'} = $platinum_pg; - $info{'platinum','currency'} = $currency; - $info{'platinum','success'} = 1; } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'platinum', {isodate => _goldmoney_time('isodate')}); + $info{'platinum','time'} = _goldmoney_time('time'); + $info{'platinum','name'} = 'Platinum Spot'; + $info{'platinum','last'} = $platinum_oz; + $info{'platinum','price'} = $platinum_oz; + $info{'platinum','currency'} = $currency; + $info{'platinum','success'} = 1; } } -- 1.5.5.6
From: sbrabec [...] suse.cz
Your patches were based on a git version that does not exist in the public git and differs from it. Here are three patches. Two of them are my attempts to rebase yout patches to the latest git snapshot. Third patch removes U.S. locale thousand mark from the string. (It seems it was already in your snapshot, but not in the upstream one.)
Subject: perl-Finance-Quote-64897-0001-adopted-to-site-changes.patch
https://rt.cpan.org/Public/Bug/Display.html?id=64897 This is a merge of the patch provided by the bug tracker to the upstream GIT snapshot. Date: Tue Jan 18 15:29:56 2011 stephan.ebelt [...] gmx.net - Ticket created Subject: GoldMoney site has changed (patch attached) the goldmoney site has been updated recently and they now allow to purchase palladium as well. attached are two patches for the GoldMoney.pm module and its test. From da395b7bf039ce13e50e0da8a6c3dbd84427aa2e Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Tue, 18 Jan 2011 20:33:09 +0100 Subject: [PATCH] adopted to site changes they dropped pretty much all tables, therefore we use HTML::TreeBuilder now --- lib/Finance/Quote/GoldMoney.pm | 102 ++++++++++++++++++--------------------- 1 files changed, 47 insertions(+), 55 deletions(-) Index: finance-quote/lib/Finance/Quote/GoldMoney.pm =================================================================== --- finance-quote.orig/lib/Finance/Quote/GoldMoney.pm +++ finance-quote/lib/Finance/Quote/GoldMoney.pm @@ -32,6 +32,7 @@ require Crypt::SSLeay; use HTTP::Request::Common; use HTML::TableExtract; +use HTML::TreeBuilder; use strict; use warnings; @@ -58,11 +59,12 @@ sub goldmoney { my @symbols = @_; return unless @symbols; + my $GOLDMONEY_URL = "http://goldmoney.com"; + my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $te, $table_gold, $table_silver, $table_platinum, - $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency + $html_string, $tree, $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency ); my $_want_gold = 0; @@ -92,18 +94,14 @@ sub goldmoney { # get the page # - but only if we want either gold, silver or platinum (there is nothing else there) if( $_want_gold or $_want_silver or $_want_platinum) { - my $GOLDMONEY_URL = "http://goldmoney.com"; my $response = $ua->request(GET $GOLDMONEY_URL); if ($response->is_success) { $html_string =$response->content; - # we want the 'Current Spot Rates' table - $te = new HTML::TableExtract->new( attribs=>{class=>'spot'}, subtables=>1); - $te->parse($html_string); - $table_gold=$te->table(3,0); - $table_silver=$te->table(3,1); - $table_platinum=$te->table(3,2); + # setup the HTML tag tree + $tree = new HTML::TreeBuilder->new(); + $tree->parse($html_string); } else { # retrieval error - flag an error and return right away foreach my $s (@symbols) { @@ -125,70 +123,64 @@ sub goldmoney { # get gold rate # if( $_want_gold ) { - $_ = $table_gold->cell(0,0); - if( /(\d*\.\d*).*\/gg/ ) { - $gold_gg = $1; - } + $_ = $tree->look_down("_tag", "span", "id", "spot-price-gold-oz"); - $_ = $table_gold->cell(0,0); - if( /(\d*\.\d*).*\/oz/ ) { + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $gold_oz = $1; - - # assemble final dataset - # - take "now" as date/time as the site is always current and does - # not provide this explicitly - so there is a time-slip - $quoter->store_date(\%info, 'gold', {isodate => _goldmoney_time('isodate')}); - $info{'gold','time'} = _goldmoney_time('time'); - $info{'gold','name'} = 'Gold Spot'; - $info{'gold','last'} = $gold_oz; - $info{'gold','price'} = $gold_oz; - $info{'gold','price_gg'} = $gold_gg; - $info{'gold','currency'} = $currency; - $info{'gold','success'} = 1; } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'gold', {isodate => _goldmoney_time('isodate')}); + $info{'gold','time'} = _goldmoney_time('time'); + $info{'gold','name'} = 'Gold Spot'; + $info{'gold','last'} = $gold_oz; + $info{'gold','price'} = $gold_oz; + $info{'gold','currency'} = $currency; + $info{'gold','success'} = 1; } # get silver rate # if( $_want_silver ) { - $_ = $table_silver->cell(0,0); - if( /(\d*\.\d*).*\/oz/ ) { - $silver_oz = $1; + $_ = $tree->look_down("_tag", "span", "id", "spot-price-silver-oz"); - $quoter->store_date(\%info, 'silver', {isodate => _goldmoney_time('isodate')}); - $info{'silver','time'} = _goldmoney_time('time'); - $info{'silver','name'} = 'Silver Spot'; - $info{'silver','last'} = $silver_oz; - $info{'silver','price'} = $silver_oz; - $info{'silver','currency'} = $currency; - $info{'silver','success'} = 1; + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { + $silver_oz = $1; } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'silver', {isodate => _goldmoney_time('isodate')}); + $info{'silver','time'} = _goldmoney_time('time'); + $info{'silver','name'} = 'Silver Spot'; + $info{'silver','last'} = $silver_oz; + $info{'silver','price'} = $silver_oz; + $info{'silver','currency'} = $currency; + $info{'silver','success'} = 1; } # get platinum rate # if( $_want_platinum ) { - $_ = $table_platinum->cell(0,0); - if( /(\d*\.\d*).*\/pg/ ) { - $platinum_pg = $1; - } + $_ = $tree->look_down("_tag", "span", "id", "spot-price-platinum-oz"); - $_ = $table_platinum->cell(0,0); - if( /(\d*\.\d*).*\/oz/ ) { + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $platinum_oz = $1; - - # assemble final dataset - # - take "now" as date/time as the site is always current and does - # not provide this explicitly - so there is a time-slip - $quoter->store_date(\%info, 'platinum', {isodate => _goldmoney_time('isodate')}); - $info{'platinum','time'} = _goldmoney_time('time'); - $info{'platinum','name'} = 'Platinum Spot'; - $info{'platinum','last'} = $platinum_oz; - $info{'platinum','price'} = $platinum_oz; - $info{'platinum','price_pg'} = $platinum_pg; - $info{'platinum','currency'} = $currency; - $info{'platinum','success'} = 1; } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'platinum', {isodate => _goldmoney_time('isodate')}); + $info{'platinum','time'} = _goldmoney_time('time'); + $info{'platinum','name'} = 'Platinum Spot'; + $info{'platinum','last'} = $platinum_oz; + $info{'platinum','price'} = $platinum_oz; + $info{'platinum','currency'} = $currency; + $info{'platinum','success'} = 1; } }
Subject: perl-Finance-Quote-64897-0002-support-palladium-lookup.patch
https://rt.cpan.org/Public/Bug/Display.html?id=64897 This is a merge of the patch provided by the bug tracker to the upstream GIT snapshot. Date: Tue Jan 18 15:29:56 2011 stephan.ebelt [...] gmx.net - Ticket created Subject: GoldMoney site has changed (patch attached) the goldmoney site has been updated recently and they now allow to purchase palladium as well. attached are two patches for the GoldMoney.pm module and its test. From e410b33151f394d76219a0f0de24de232f4e8750 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Tue, 18 Jan 2011 20:47:11 +0100 Subject: [PATCH] support 'palladium' lookup --- lib/Finance/Quote/GoldMoney.pm | 46 +++++++++++++++++++++++++++++++-------- t/goldmoney.t | 13 +++++++++- 2 files changed, 47 insertions(+), 12 deletions(-) Index: finance-quote/lib/Finance/Quote/GoldMoney.pm =================================================================== --- finance-quote.orig/lib/Finance/Quote/GoldMoney.pm +++ finance-quote/lib/Finance/Quote/GoldMoney.pm @@ -7,7 +7,7 @@ # Copyright (C) 2000, Brent Neal <brentn@users.sourceforge.net> # Copyright (C) 2000, Volker Stuerzl <volker.stuerzl@gmx.de> # Copyright (C) 2006, Klaus Dahlke <klaus.dahlke@gmx.de> -# Copyright (C) 2008, Stephan Ebelt <stephan.ebelt@gmx.de> +# Copyright (C) 2011, Stephan Ebelt <ste -at- shared-files -dot- de> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,6 @@ require 5.005; require Crypt::SSLeay; use HTTP::Request::Common; -use HTML::TableExtract; use HTML::TreeBuilder; use strict; @@ -51,7 +50,8 @@ sub labels { # goldmoney($quoter, @symbols) # -# - get 'gold' and 'silver' spot rates from goldmoney.com +# - get 'gold', 'silver', 'platinum' and 'palladium' spot rates from +# goldmoney.com # - error out properly (that is: ignore) all other symbols # sub goldmoney { @@ -64,12 +64,14 @@ sub goldmoney { my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $tree, $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency + $html_string, $tree, $gold_oz, $silver_oz, $platinum_oz, + $palladium_oz, $currency ); my $_want_gold = 0; my $_want_silver = 0; my $_want_platinum = 0; + my $_want_palladium = 0; # - feed all requested symbols into %info (to be returned later) # - set error state to false by default @@ -86,8 +88,10 @@ sub goldmoney { $_want_silver = 1; } elsif($s eq 'platinum') { $_want_platinum = 1; + } elsif($s eq 'palladium') { + $_want_palladium = 1; } else { - $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold' and 'silver')"; + $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold', 'silver', 'platinum' and 'palladium')"; } } @@ -182,6 +186,28 @@ sub goldmoney { $info{'platinum','currency'} = $currency; $info{'platinum','success'} = 1; } + + # get palladium rate + # + if( $_want_palladium ) { + $_ = $tree->look_down("_tag", "span", "id", "spot-price-palladium-oz"); + + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { + $palladium_oz = $1; + $palladium_oz =~ s/,//g; + } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'palladium', {isodate => _goldmoney_time('isodate')}); + $info{'palladium','time'} = _goldmoney_time('time'); + $info{'palladium','name'} = 'Palladium Spot'; + $info{'palladium','last'} = $palladium_oz; + $info{'palladium','price'} = $palladium_oz; + $info{'palladium','currency'} = $currency; + $info{'palladium','success'} = 1; + } } return wantarray() ? %info : \%info; @@ -229,12 +255,12 @@ Finance::Quote::GoldMoney - obtain spot $q = Finance::Quote->new; - %rates = $q->fetch('goldmoeny','gold', 'silver', 'platinum'); + %rates = $q->fetch('goldmoney','gold', 'silver', 'platinum', 'palladium'); =head1 DESCRIPTION -This module obtains current spot rates for 'gold', 'silver' and -'platinum' from Goldmoney (http://www.goldmoney.com). All other +This module obtains current spot rates for 'gold', 'silver', 'platinum' +and 'palladium' from GoldMoney (http://goldmoney.com). All other symbols are ignored. Information returned by this module is governed by Net Transactions @@ -248,8 +274,8 @@ The following labels are returned by Fin - exchange - name - date, time - - price (per ounce), price_gg (per goldgram, gold only), - price_pg (per platinumgram, platinum only) + - price (per ounce) + - last (per ounce, same as 'price') - currency =head1 SEE ALSO Index: finance-quote/t/goldmoney.t =================================================================== --- finance-quote.orig/t/goldmoney.t +++ finance-quote/t/goldmoney.t @@ -7,12 +7,12 @@ if (not $ENV{ONLINE_TEST}) { plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; } -plan tests => 23; +plan tests => 31; # Test GoldMoney functions. my $q = Finance::Quote->new("GoldMoney"); $q->set_currency('EUR'); -my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "BOGUS"); +my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "palladium", "BOGUS"); ok(%quotes); # Check that sound information is returned for gold, silver and platinum. @@ -34,6 +34,13 @@ ok($quotes{"platinum","currency"} eq "EU ok(length($quotes{"platinum","date"}) > 0); ok(length($quotes{"platinum","time"}) > 0); +ok($quotes{"palladium","success"}, 'palladium price lookup'); +ok($quotes{"palladium","last"} > 0); +ok( $quotes{"palladium","last"} !~ /^0/ ); +ok($quotes{"palladium","currency"} eq "EUR"); +ok(length($quotes{"palladium","date"}) > 0); +ok(length($quotes{"palladium","time"}) > 0); + my $year = (localtime())[5] + 1900; ok((substr($quotes{"gold","isodate"},0,4) == $year)); ok((substr($quotes{"gold","date"},6,4) == $year)); @@ -41,6 +48,8 @@ ok((substr($quotes{"silver","isodate"},0 ok((substr($quotes{"silver","date"},6,4) == $year)); ok((substr($quotes{"platinum","isodate"},0,4) == $year)); ok((substr($quotes{"platinum","date"},6,4) == $year)); +ok((substr($quotes{"palladium","isodate"},0,4) == $year)); +ok((substr($quotes{"palladium","date"},6,4) == $year)); # Check that a bogus symbol returns no-success. ok(! $quotes{"BOGUS","success"});
Subject: perl-Finance-Quote-goldmoney-decimal-point.patch
Index: finance-quote/lib/Finance/Quote/GoldMoney.pm =================================================================== --- finance-quote.orig/lib/Finance/Quote/GoldMoney.pm +++ finance-quote/lib/Finance/Quote/GoldMoney.pm @@ -131,6 +131,7 @@ sub goldmoney { if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $gold_oz = $1; + $gold_oz =~ s/,//; } # assemble final dataset @@ -152,6 +153,7 @@ sub goldmoney { if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $silver_oz = $1; + $silver_oz =~ s/,//; } # assemble final dataset @@ -173,6 +175,7 @@ sub goldmoney { if( $_->as_text =~ /([\d,]*\.\d*)/ ) { $platinum_oz = $1; + $platinum_oz =~ s/,//; } # assemble final dataset