Skip Menu |

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

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

People
Owner: eco [...] ecocode.net
Requestors: stephan.ebelt [...] gmx.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.16
Fixed in: (no value)



Hello Erik, here are a couple new patches for goldmoney to reflect site changes and to add support for paladium which was recently introduced. Hope it applies properly (0007 might have been a problem limited to my working copy). stephan
Subject: 0008-adjusted-to-site-changes.patch
From c994f46fb952988a0e5f8ca4b6d795990600cd51 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Fri, 19 Jun 2009 13:38:47 +0200 Subject: [PATCH] adjusted to site changes - the coordinates of the gold and silber spot rate tables changed - added description to essential tests for better oversight of test output --- lib/Finance/Quote/GoldMoney.pm | 4 ++-- t/goldmoney.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Finance/Quote/GoldMoney.pm b/lib/Finance/Quote/GoldMoney.pm index 96f1519..54c563f 100644 --- a/lib/Finance/Quote/GoldMoney.pm +++ b/lib/Finance/Quote/GoldMoney.pm @@ -98,8 +98,8 @@ sub goldmoney { # 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(1,0); - $table_silver=$te->table(1,1); + $table_gold=$te->table(2,0); + $table_silver=$te->table(2,1); } else { # retrieval error - flag an error and return right away foreach my $s (@symbols) { diff --git a/t/goldmoney.t b/t/goldmoney.t index 6cc330a..3511114 100755 --- a/t/goldmoney.t +++ b/t/goldmoney.t @@ -16,13 +16,13 @@ my %quotes = $q->fetch("goldmoney","gold", "silver", "BOGUS"); ok(%quotes); # Check that sound information is returned for gold and silver. -ok($quotes{"gold","success"}); +ok($quotes{"gold","success"}, 'gold price lookup'); ok($quotes{"gold","last"} > 0); ok($quotes{"gold","currency"} eq "EUR"); ok(length($quotes{"gold","date"}) > 0); ok(length($quotes{"gold","time"}) > 0); -ok($quotes{"silver","success"}); +ok($quotes{"silver","success"}, 'silver price lookup'); ok($quotes{"silver","last"} > 0); ok($quotes{"silver","currency"} eq "EUR"); ok(length($quotes{"silver","date"}) > 0); -- 1.5.2.1
Subject: 0010-adretrieve-rates-for-platinum.patch
From 85c221aa508b5073267fdf702c2a8ea4cc39166f Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Tue, 14 Jul 2009 15:02:24 +0200 Subject: [PATCH] adretrieve rates for platinum --- lib/Finance/Quote/GoldMoney.pm | 52 ++++++++++++++++++++++++++++++++------- t/goldmoney.t | 14 ++++++++-- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/lib/Finance/Quote/GoldMoney.pm b/lib/Finance/Quote/GoldMoney.pm index 4a1b31e..7ad06e9 100644 --- a/lib/Finance/Quote/GoldMoney.pm +++ b/lib/Finance/Quote/GoldMoney.pm @@ -61,12 +61,13 @@ sub goldmoney { my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $te, $table_gold, $table_silver, - $gold_gg, $gold_oz, $silver_oz, $currency + $html_string, $te, $table_gold, $table_silver, $table_platinum, + $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency ); my $_want_gold = 0; my $_want_silver = 0; + my $_want_platinum = 0; # - feed all requested symbols into %info (to be returned later) # - set error state to false by default @@ -81,14 +82,16 @@ sub goldmoney { $_want_gold = 1; } elsif($s eq 'silver') { $_want_silver = 1; + } elsif($s eq 'platinum') { + $_want_platinum = 1; } else { $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold' and 'silver')"; } } # get the page - # - but only if we want either gold or silver (there is nothing else there) - if( $_want_gold or $_want_silver ) { + # - 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); @@ -100,6 +103,7 @@ sub goldmoney { $te->parse($html_string); $table_gold=$te->table(3,0); $table_silver=$te->table(3,1); + $table_platinum=$te->table(3,2); } else { # retrieval error - flag an error and return right away foreach my $s (@symbols) { @@ -161,6 +165,31 @@ sub goldmoney { } } + # get platinum rate + # + if( $_want_platinum ) { + $_ = $table_platinum->cell(0,0); + if( /(\d*\.\d*).*\/pg/ ) { + $platinum_pg = $1; + } + + $_ = $table_platinum->cell(0,0); + if( /(\d*\.\d*).*\/oz/ ) { + $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; + } + } } return wantarray() ? %info : \%info; @@ -200,7 +229,7 @@ sub _goldmoney_time { =head1 NAME -Finance::Quote::GoldMoney - obtain gold and silver rates from GoldMoney. +Finance::Quote::GoldMoney - obtain spot rates from GoldMoney. =head1 SYNOPSIS @@ -208,15 +237,17 @@ Finance::Quote::GoldMoney - obtain gold and silver rates from GoldMoney. $q = Finance::Quote->new; - %rates = $q->fetch('goldmoeny','gold', 'silver'); + %rates = $q->fetch('goldmoeny','gold', 'silver', 'platinum'); =head1 DESCRIPTION -This module obtains current spot rates for 'gold' and 'silver' from -Goldmoney (http://www.goldmoney.com). All other symbols are ignored. +This module obtains current spot rates for 'gold', 'silver' and +'platinum' from Goldmoney (http://www.goldmoney.com). All other +symbols are ignored. Information returned by this module is governed by Net Transactions -Ltd.'s terms and conditions. +Ltd.'s terms and conditions. This module is *not* affiliated with the +company in any way. Use at your own risk. =head1 LABELS RETURNED @@ -225,7 +256,8 @@ The following labels are returned by Finance::Quote::GoldMoney: - exchange - name - date, time - - price (per ounce), price_gg (per goldgram, gold only) + - price (per ounce), price_gg (per goldgram, gold only), + price_pg (per platinumgram, platinum only) - currency =head1 SEE ALSO diff --git a/t/goldmoney.t b/t/goldmoney.t index 3511114..7176f72 100755 --- a/t/goldmoney.t +++ b/t/goldmoney.t @@ -7,15 +7,15 @@ if (not $ENV{ONLINE_TEST}) { plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; } -plan tests => 16; +plan tests => 23; # Test GoldMoney functions. my $q = Finance::Quote->new("GoldMoney"); $q->set_currency('EUR'); -my %quotes = $q->fetch("goldmoney","gold", "silver", "BOGUS"); +my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "BOGUS"); ok(%quotes); -# Check that sound information is returned for gold and silver. +# Check that sound information is returned for gold, silver and platinum. ok($quotes{"gold","success"}, 'gold price lookup'); ok($quotes{"gold","last"} > 0); ok($quotes{"gold","currency"} eq "EUR"); @@ -28,11 +28,19 @@ ok($quotes{"silver","currency"} eq "EUR"); ok(length($quotes{"silver","date"}) > 0); ok(length($quotes{"silver","time"}) > 0); +ok($quotes{"platinum","success"}, 'platinum price lookup'); +ok($quotes{"platinum","last"} > 0); +ok($quotes{"platinum","currency"} eq "EUR"); +ok(length($quotes{"platinum","date"}) > 0); +ok(length($quotes{"platinum","time"}) > 0); + my $year = (localtime())[5] + 1900; ok((substr($quotes{"gold","isodate"},0,4) == $year)); ok((substr($quotes{"gold","date"},6,4) == $year)); 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)); # Check that a bogus symbol returns no-success. ok(! $quotes{"BOGUS","success"}); -- 1.5.2.1
Subject: 0006-adopted-module-to-site-changes-introduced-in-01-2009.patch
From e341a176943b7c2bef0882768b31347501a0c0f8 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Sat, 21 Feb 2009 13:26:17 +0100 Subject: [PATCH] adopted module to site changes introduced in 01/2009, FIXME: currency is broken now, see comment --- lib/Finance/Quote/GoldMoney.pm | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/Finance/Quote/GoldMoney.pm b/lib/Finance/Quote/GoldMoney.pm index 78daa53..4230823 100644 --- a/lib/Finance/Quote/GoldMoney.pm +++ b/lib/Finance/Quote/GoldMoney.pm @@ -54,7 +54,7 @@ sub goldmoney { my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $te, $table, + $html_string, $te, $table_gold, $table_silver, $gold_gg, $gold_oz, $silver_oz, $currency ); @@ -89,9 +89,10 @@ sub goldmoney { $html_string =$response->content; # we want the 'Current Spot Rates' table - $te = new HTML::TableExtract->new( depth=>2, count=>3 , keep_html=>1); + $te = new HTML::TableExtract->new( attribs=>{class=>'spot'}, subtables=>1); $te->parse($html_string); - $table=$te->table(2,3); + $table_gold=$te->table(1,0); + $table_silver=$te->table(1,1); } else { # retrieval error - flag an error and return right away foreach my $s (@symbols) { @@ -102,22 +103,24 @@ sub goldmoney { } # get list of currencies - # - we get the 'selected' element and extract its content - $currency = $table->cell(0,0); - if( $currency =~ /selected.*>(.*)</ ) { - $currency = $1; - } + # FIXME: + # - assume euro since the site change in 01/2009 + # - currency is JavaScript()ed since then and therefore hard to parse, if you + # know how please tell me + # - this assumption causes trouble when the module is used outside the + # european region (F::Q considers every number it gets as EUR and converts it...) + $currency = 'EUR'; # get gold rate # if( $_want_gold ) { - $_ = $table->cell(2,1); - if( /^(\d*\.\d*).*\/gg$/ ) { + $_ = $table_gold->cell(0,1); + if( /(\d*\.\d*).*\/gg/ ) { $gold_gg = $1; } - $_ = $table->cell(4,1); - if( /^(\d*\.\d*).*\/oz$/ ) { + $_ = $table_gold->cell(0,1); + if( /(\d*\.\d*).*\/oz/ ) { $gold_oz = $1; # assemble final dataset @@ -137,8 +140,8 @@ sub goldmoney { # get silver rate # if( $_want_silver ) { - $_ = $table->cell(6,1); - if( /^(\d*\.\d*).*\/oz$/ ) { + $_ = $table_silver->cell(0,1); + if( /(\d*\.\d*).*\/oz/ ) { $silver_oz = $1; $quoter->store_date(\%info, 'silver', {isodate => _goldmoney_time('isodate')}); -- 1.5.2.1
Subject: 0007-resolved-conflicts.patch
From 6bbe4d89c8729c83c1e40a2c38cf607e651dd448 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Fri, 19 Jun 2009 09:50:24 +0200 Subject: [PATCH] resolved conflicts (conflict markers were comitted by accident) --- lib/Finance/Quote.pm | 57 +------------------------------------------------- 1 files changed, 1 insertions(+), 56 deletions(-) diff --git a/lib/Finance/Quote.pm b/lib/Finance/Quote.pm index 1d70d02..cdafc30 100644 --- a/lib/Finance/Quote.pm +++ b/lib/Finance/Quote.pm @@ -145,31 +145,15 @@ sub _load_modules { # loads a default set of methods. sub new { -<<<<<<< HEAD:lib/Finance/Quote.pm my $self = shift; my $class = ref($self) || $self; -======= - my $self = shift; - my $class = ref($self) || $self; ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm -<<<<<<< HEAD:lib/Finance/Quote.pm my $this = {}; bless $this, $class; -======= - my $this = {}; - bless $this, $class; ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm -<<<<<<< HEAD:lib/Finance/Quote.pm my @modules = (); my @reqmodules = (); # Requested modules. -======= - my @modules = (); - my @reqmodules = (); # Requested modules. ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm -<<<<<<< HEAD:lib/Finance/Quote.pm # If there's no argument list, but we have the appropriate # environment variable set, we'll use that instead. if ($ENV{FQ_LOAD_QUOTELET} and !@_) { @@ -177,17 +161,7 @@ sub new { } else { @reqmodules = @_; } -======= - # If there's no argument list, but we have the appropriate - # environment variable set, we'll use that instead. - if ($ENV{FQ_LOAD_QUOTELET} and !@_) { - @reqmodules = split(' ',$ENV{FQ_LOAD_QUOTELET}); - } else { - @reqmodules = @_; - } ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm -<<<<<<< HEAD:lib/Finance/Quote.pm # If we get an empty new(), or one starting with -defaults, # then load up the default methods. if (!@reqmodules or $reqmodules[0] eq "-defaults") { @@ -200,43 +174,14 @@ sub new { USFedBonds VWD ZA Cominvest Finanzpartner Yahoo::Asia Yahoo::Australia Yahoo::Brasil Yahoo::Europe Yahoo::NZ Yahoo::USA/; } -======= - # If we get an empty new(), or one starting with -defaults, - # then load up the default methods. - if (!@reqmodules or $reqmodules[0] eq "-defaults") { - shift(@reqmodules) if (@reqmodules); - # Default modules - @modules = qw/AEX AIAHK ASEGR ASX BMONesbittBurns Bourso Cdnfundlibrary - Currencies Deka DWS FTPortfolios Fidelity FinanceCanada Fool - GoldMoney HEX - IndiaMutual LeRevenu ManInvestments Morningstar NZX Platinum SEB - StockHouseCanada TSP TSX Tdefunds Tdwaterhouse Tiaacref Troweprice - Trustnet Union USFedBonds VWD ZA Cominvest Finanzpartner - Yahoo::Asia Yahoo::Australia Yahoo::Brasil Yahoo::Europe Yahoo::NZ - Yahoo::USA/; } ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm - -<<<<<<< HEAD:lib/Finance/Quote.pm + $this->_load_modules(@modules,@reqmodules); -======= - $this->_load_modules(@modules,@reqmodules); ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm -<<<<<<< HEAD:lib/Finance/Quote.pm $this->{TIMEOUT} = $TIMEOUT if defined($TIMEOUT); $this->{FAILOVER} = 1; $this->{REQUIRED} = []; -======= - $this->{TIMEOUT} = $TIMEOUT if defined($TIMEOUT); - $this->{FAILOVER} = 1; - $this->{REQUIRED} = []; ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm -<<<<<<< HEAD:lib/Finance/Quote.pm return $this; -======= - return $this; ->>>>>>> 3b22c9cc1f4f4e49dde7bab1b484f29f159a7f69:lib/Finance/Quote.pm } # ======================================================================= -- 1.5.2.1
Subject: 0009-more-site-changes.patch
From c8f813f3e0d228087abd12293ed51922c43925f2 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Mon, 13 Jul 2009 19:15:26 +0200 Subject: [PATCH] more site changes gold and silver tables moved down one level and lost a column --- lib/Finance/Quote/GoldMoney.pm | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Finance/Quote/GoldMoney.pm b/lib/Finance/Quote/GoldMoney.pm index 54c563f..4a1b31e 100644 --- a/lib/Finance/Quote/GoldMoney.pm +++ b/lib/Finance/Quote/GoldMoney.pm @@ -98,8 +98,8 @@ sub goldmoney { # 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(2,0); - $table_silver=$te->table(2,1); + $table_gold=$te->table(3,0); + $table_silver=$te->table(3,1); } else { # retrieval error - flag an error and return right away foreach my $s (@symbols) { @@ -121,12 +121,12 @@ sub goldmoney { # get gold rate # if( $_want_gold ) { - $_ = $table_gold->cell(0,1); + $_ = $table_gold->cell(0,0); if( /(\d*\.\d*).*\/gg/ ) { $gold_gg = $1; } - $_ = $table_gold->cell(0,1); + $_ = $table_gold->cell(0,0); if( /(\d*\.\d*).*\/oz/ ) { $gold_oz = $1; @@ -147,7 +147,7 @@ sub goldmoney { # get silver rate # if( $_want_silver ) { - $_ = $table_silver->cell(0,1); + $_ = $table_silver->cell(0,0); if( /(\d*\.\d*).*\/oz/ ) { $silver_oz = $1; -- 1.5.2.1
Subject: Goldmoney patches
Hi Stephan ! Patches applied Thank you for your work ! -- Erik