Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:12.3
perl-Finance-Quote
perl-Finance-Quote-64897-0001-adopted-to-site-c...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File perl-Finance-Quote-64897-0001-adopted-to-site-changes.patch of Package perl-Finance-Quote
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-1.18/lib/Finance/Quote/GoldMoney.pm =================================================================== --- Finance-Quote-1.18.orig/lib/Finance/Quote/GoldMoney.pm +++ Finance-Quote-1.18/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; } }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor