From owner-freebsd-ports-bugs@FreeBSD.ORG Fri Aug 31 14:10:09 2012 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E2DA2106566B for ; Fri, 31 Aug 2012 14:10:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B716D8FC0A for ; Fri, 31 Aug 2012 14:10:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q7VEA9Hc023546 for ; Fri, 31 Aug 2012 14:10:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q7VEA98n023545; Fri, 31 Aug 2012 14:10:09 GMT (envelope-from gnats) Resent-Date: Fri, 31 Aug 2012 14:10:09 GMT Resent-Message-Id: <201208311410.q7VEA98n023545@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Guido Falsi Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 96FD5106564A for ; Fri, 31 Aug 2012 14:02:44 +0000 (UTC) (envelope-from mad@madpilot.net) Received: from micro.madpilot.net (micro.madpilot.net [88.149.173.206]) by mx1.freebsd.org (Postfix) with ESMTP id 0C6518FC08 for ; Fri, 31 Aug 2012 14:02:42 +0000 (UTC) Received: from micro.madpilot.net (localhost [127.0.0.1]) by micro.madpilot.net (Postfix) with ESMTP id 3X7j242Gv1z2ZP for ; Fri, 31 Aug 2012 16:02:36 +0200 (CEST) Received: from micro.madpilot.net ([127.0.0.1]) by micro.madpilot.net (micro.madpilot.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TrjTvlj2Djd5 for ; Fri, 31 Aug 2012 16:02:30 +0200 (CEST) Received: by micro.madpilot.net (Postfix, from userid 1000) id 3X7j1y09JKz2ZN; Fri, 31 Aug 2012 16:02:29 +0200 (CEST) Message-Id: <3X7j1y09JKz2ZN@micro.madpilot.net> Date: Fri, 31 Aug 2012 16:02:29 +0200 (CEST) From: Guido Falsi To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: ports/171207: [PATCH] finance/p5-Finance-Quote unable to get Currency quotes X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Guido Falsi List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Aug 2012 14:10:10 -0000 >Number: 171207 >Category: ports >Synopsis: [PATCH] finance/p5-Finance-Quote unable to get Currency quotes >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Aug 31 14:10:09 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Guido Falsi >Release: FreeBSD 9.1-PRERELEASE amd64 >Organization: >Environment: System: FreeBSD micro.madpilot.net 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r239180: Sat Aug 11 00:14:47 CEST 2012 root@micro.madpilot.net:/usr/obj/usr/src/sys/MICRO amd64 >Description: The Yahoo API to get currency quotes used by this perl module has changed. The attached patch is based on the updated file in the upstream github repository: https://github.com/pfenwick/finance-quote/blob/master/lib/Finance/Quote.pm This module is used by finance/gnucash for it's feature to automatically update multiple currency quotes, with this fix applied it works correctly. >How-To-Repeat: Install finance/gnucash and try fetching quotes for currencies as described here: http://gnucash.org/docs/v2.4/C/gnucash-guide/invest-stockprice1.html#invest-stockprice-auto2 >Fix: Index: files/patch-lib-Finance-Quote.pm =================================================================== --- files/patch-lib-Finance-Quote.pm (revision 303413) +++ files/patch-lib-Finance-Quote.pm (working copy) @@ -1,13 +1,149 @@ -http://github.com/pfenwick/finance-quote/commit/7de984bea80e9c5e00504ededba6897183bb8c45 - ---- lib/Finance/Quote.pm.orig 2009-10-06 01:39:57.000000000 +0800 -+++ lib/Finance/Quote.pm 2010-02-13 18:25:22.000000000 +0800 -@@ -167,7 +167,7 @@ - if (!@reqmodules or $reqmodules[0] eq "-defaults") { - shift(@reqmodules) if (@reqmodules); - # Default modules -- @modules = qw/AEX AIAHK ASEGR ASX BMONesbittBurns Bourso Cdnfundlibrary -+ @modules = qw/AEX AIAHK ASEGR ASX BMONesbittBurns BSERO Bourso Cdnfundlibrary - Currencies Deka DWS FTPortfolios Fidelity FinanceCanada Fool HU - GoldMoney HEX - IndiaMutual LeRevenu ManInvestments Morningstar NZX Platinum SEB +--- lib/Finance/Quote.pm.orig 2012-08-31 15:38:42.023832749 +0200 ++++ lib/Finance/Quote.pm 2012-08-31 15:42:45.299834285 +0200 +@@ -35,7 +35,6 @@ + use Carp; + use Finance::Quote::UserAgent; + use HTTP::Request::Common; +-use HTML::TreeBuilder; + use Encode; + use Data::Dumper; + +@@ -43,7 +42,14 @@ + $VERSION $TIMEOUT %MODULES %METHODS $AUTOLOAD + $YAHOO_CURRENCY_URL $USE_EXPERIMENTAL_UA/; + +-$YAHOO_CURRENCY_URL = "http://uk.finance.yahoo.com/q?s="; ++# Call on the Yahoo API: ++# - "f=l1" should return a single value - the "Last Trade (Price Only)" ++# - "s=" the value of s should be "=X" ++# where and are currencies ++# Excample: http://finance.yahoo.com/d/quotes.csv?f=l1&s=AUDGBP=X ++# Documentation can be found here: ++# http://code.google.com/p/yahoo-finance-managed/wiki/csvQuotesDownload ++$YAHOO_CURRENCY_URL = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=l1&s="; + + @ISA = qw/Exporter/; + @EXPORT = (); +@@ -240,26 +246,13 @@ + + my $ua = $this->user_agent; + +- 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)); +- +- # Find the
with the data +- my $div = $tb->look_down('id','yfi_quote_summary_data'); +- # Make sure there's a
to parse. +- return undef unless $div; +- +- # The first should contain the quote +- my $rate_element=$div->look_down('_tag','b'); +- # Make sure there's a to parse. +- return undef unless $rate_element; +- +- my $exchange_rate=$rate_element->as_text; +- +- $exchange_rate =~ s/,// ; # solve a bug when conversion rate +- # involves thousands. yahoo inserts +- # a comma when thousands occur ++ # The response should be a single value (the exchange rate) ++ my $data = $ua->request(GET "${YAHOO_CURRENCY_URL}${from}${to}=X")->content; ++ my $exchange_rate = $data; ++ ++ $exchange_rate =~ s/,// ; # solve a bug when conversion rate ++ # involves thousands. yahoo inserts ++ # a comma when thousands occur + + { + local $^W = 0; # Avoid undef warnings. +@@ -268,6 +261,18 @@ + # we may have extra cruft, or no amount. + return undef unless ($exchange_rate+0); + } ++ ++if ( $exchange_rate < 0.001 ) { ++ # exchange_rate is too little. we'll get more accuracy by using ++ # the inverse rate and inverse it ++ my $inverse_rate = $this->currency( $to, $from ); ++ { ++ local $^W = 0; ++ return undef unless ( $exchange_rate + 0 ); ++ } ++ $exchange_rate = int( 100000000 / $inverse_rate + .5 ) / 100000000; ++} ++ + return ($exchange_rate * $amount); + } + +@@ -770,6 +775,60 @@ + return $retTime; + } + ++ ++# If $str ends with a B like "20B" or "1.6B" then expand it as billions like ++# "20000000000" or "1600000000". ++# ++# This is done with string manipulations so floating-point rounding doesn't ++# produce spurious digits for values like "1.6" which aren't exactly ++# representable in binary. ++# ++# Is "B" for billions the only abbreviation from Yahoo? ++# Could extend and rename this if there's also millions or thousands. ++# ++# For reference, if the value was just for use within perl then simply ++# substituting to exponential "1.5e9" might work. But expanding to full ++# digits seems a better idea as the value is likely to be printed directly ++# as a string. ++sub B_to_billions { ++ ++ my ($self,$str) = @_; ++ ### B_to_billions(): $str ++ if ($str =~ s/B$//i) { ++ $str = $self->decimal_shiftup ($str, 9); ++ } ++ return $str; ++} ++ ++# $str is a number like "123" or "123.45" ++# return it with the decimal point moved $shift places to the right ++# must have $shift>=1 ++# eg. decimal_shiftup("123",3) -> "123000" ++# decimal_shiftup("123.45",1) -> "1234.5" ++# decimal_shiftup("0.25",1) -> "2.5" ++# ++sub decimal_shiftup { ++ my ($self, $str, $shift) = @_; ++ ++ # delete decimal point and set $after to count of chars after decimal. ++ # Leading "0" as in "0.25" is deleted too giving "25" so as not to end up ++ # with something that might look like leading 0 for octal. ++ my $after = ($str =~ s/(?:^0)?\.(.*)/$1/ ? length($1) : 0); ++ ++ $shift -= $after; ++ # now $str is an integer and $shift is relative to the end of $str ++ ++ if ($shift >= 0) { ++ # moving right, eg. "1234" becomes "12334000" ++ return $str . ('0' x $shift); # extra zeros appended ++ } else { ++ # negative means left, eg. "12345" becomes "12.345" ++ # no need to prepend zeros since demanding initial $shift>=1 ++ substr ($str, $shift,0, '.'); # new '.' at shifted spot from end ++ return $str; ++ } ++} ++ + # Dummy destroy function to avoid AUTOLOAD catching it. + sub DESTROY { return; } + +@@ -803,7 +862,7 @@ + This module gets stock quotes from various internet sources, including + Yahoo! Finance, Fidelity Investments, and the Australian Stock Exchange. + There are two methods of using this module -- a functional interface +-that is depreciated, and an object-orientated method that provides ++that is deprecated, and an object-orientated method that provides + greater flexibility and stability. + + With the exception of straight currency exchange rates, all information >Release-Note: >Audit-Trail: >Unformatted: