Subject: | from sourceforge : Yahoo Europe bugs with patch v2 |
This is an improved version of the patch attached to "Yahoo Europe bugs
with patch" bug report.
Some London funds have changed names and the names come back with "GBP"
instead of ".L".
Submitted By:
Nobody/Anonymous - nobody
Date Submitted:
2008-03-08 16:15
Followups:
Comments
Date: 2008-08-01 00:50
Sender: jmarter
Logged In: YES
user_id=2153021
Originator: NO
Here is my patch. It is against the existing patch. I don't see how I can
upload it as file. Is there a way to do that?
--- usr/share/perl5/Finance/Quote/Yahoo/Base.pm.orig 2008-06-29
12:04:10.000000000 -0500
+++ usr/share/perl5/Finance/Quote/Yahoo/Base.pm 2008-07-31
19:16:54.000000000 -0500
@@ -60,7 +60,7 @@
close open day_range year_range eps pe div_date div
div_yield
cap ex_div avg_vol currency/;
-@FIELD_ENCODING = qw/s n l1 d1 t1 c1 p2 v b a p o m w e r r1 d y j1 q a2
c4/;
+@FIELD_ENCODING = qw/s n l1 t1 d1 c1 p2 v b a p o m w e r r1 d y j1 q a2
c4/;
# This returns a list of labels that are provided, so that code
# that make use of this module can know what it's dealing with.
Date: 2008-08-01 00:10
Sender: jmarter
Logged In: YES
user_id=2153021
Originator: NO
Okay, I finally had a chance to sit down and see how those URLs work. I
think this is going to be easy. My concern about the $FIELD_ENCODING looks
right, but not for the reason I thought.
The letters or letter-number pairs after the f= is the list of fields
requested and their order. However there is a difference between
uk.finance.yahoo.com and finance.yahoo.com. With uk, the t1 indicator
stands for two fields time and date in order and d1 serves no purpose.
With finance t1 is just the time and d1 is the date.
so if we make the order t1d1, then everyone should be happy. How to
document this--I don't know.
Date: 2008-07-24 01:45
Sender: jmarter
Logged In: YES
user_id=2153021
Originator: NO
I have two concerns about the patch. Mind you, I have not done any work
on this package in the past, I'm just interested because it broke things
for me.
First, I think it is a good guess that @FIELD_ENCODING should have the
corresponding fields flipped when we flip the date and time fields.
Second, I am guessing that this date/time ordering is UK specific, so we
should find a way to move that change into the region file. I'm not sure
if that is europe.pm or if a UK.pm file needs to be added.
I hope this weekend I have a chance to learn this better and propose a
fix. But maybe someone will beat me to it.
Date: 2008-07-23 18:29
Sender: nobody
Logged In: NO
Yes, there is a reason for the FIELDS array to be arranged with time
before date. Without this change gnucash fails to accept the data. If I
swap them round (so that date is before time) then gnucash fails. The
contents of the URL that comes back from Yahoo has time before date.
For example using the URL that gnucash creates:
wget
'http://uk.finance.yahoo.com/d/quotes.csv?
f=snl1d1t1c1p2vbapomwerr1dyj1qa2c4&e=.csv&s=BNC.L'
gets back data containing the time before the date.
BNC.L,BANCO SANTANDER
R,957.50,11:35AM,07/23/2008,+34.50,+3.74%,491715,957.00,958.00,923.00,946.29,N/A,
N/A,0.00,0.00,0.00,0.00,N/A,11166,GBp
Date: 2008-07-19 23:03
Sender: jmarter
Logged In: YES
user_id=2153021
Originator: NO
This patch was applied to Debian's libfinance-quote-perl package. I just
submitted a patch to the bug system which partially undoes this patch.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=490395
Is there a reason for your patch to change the order of date and time in
the @FIELDS array?
Subject: | libfinance-quote-yahoo-2.diff |
--- /usr/share/perl5/Finance/Quote/Yahoo/Base.pm.bak 2007-12-16 12:27:13.000000000 +0000
+++ /usr/share/perl5/Finance/Quote/Yahoo/Base.pm 2008-03-08 16:02:04.000000000 +0000
@@ -56,7 +56,7 @@
# in the URL. These are recorded below, along with their corresponding
# field names.
-@FIELDS = qw/symbol name last date time net p_change volume bid ask
+@FIELDS = qw/symbol name last time date net p_change volume bid ask
close open day_range year_range eps pe div_date div div_yield
cap ex_div avg_vol currency/;
@@ -142,7 +142,7 @@
# yahoo_request (restricted function)
#
# This function expects a Finance::Quote object, a base URL to use,
-# a refernece to a list of symbols to lookup. If a fourth argument is
+# a reference to a list of symbols to lookup. If a fourth argument is
# used then it will act as a suffix that needs to be appended to the stocks
# in order to obtain the correct information. This function relies upon
# the fact that the various Yahoo's all work the same way.
@@ -189,12 +189,21 @@
@q = $quoter->parse_csv($_);
}
my $symbol = $q[0];
+ $symbol =~ s/GBP$/.L/;
my ($exchange) = $symbol =~ m/\.([A-Z]+)/;
# Strip out suffixes. Mmmm, functions as lvalues.
substr($symbol,-length($suffix),length($suffix)) = "";
- # If we weren't using a two dimesonal
+ # Some Yahoo Europe quotes have an N/A field before
+ # the date. Check for this and drop the N/A if it is
+ # there and the date is valid.
+
+ if($q[3] eq "N/A" && $q[4] =~ m/[0-9]+:[0-9]{2}[AP]M/) {
+ splice(@q,3,1);
+ }
+
+ # If we weren't using a two dimensional
# hash, we could do the following with
# a hash-slice. Alas, we can't. This just
# loads all the returned fields into our hash.
@@ -245,6 +254,8 @@
# backward compatability. Needed because Yahoo
# returns GBP as GBp. There may be others.
$info{$symbol,"currency"} =~ tr/a-z/A-Z/;
+ # Remove spaces from currency.
+ $info{$symbol,"currency"} =~ s/ //;
# printf "Currency %s specified by Yahoo\n", $info{$symbol,"currency"};
} else {
# Determine the currency from the exchange name.
@@ -265,7 +276,7 @@
# return in pence. We'd like them to return in pounds
# (divide by 100).
if (defined($exchange)) {
- if (($exchange eq "L" && $info{$symbol,"currency"} eq "GBP") ||
+ if ((($exchange eq "L" || $exchange eq "MF") && $info{$symbol,"currency"} eq "GBP") ||
($exchange eq "TA")) {
foreach my $field ($quoter->default_currency_fields) {
next unless ($info{$symbol,$field});