Skip Menu |

This queue is for tickets about the Finance-Currency-Convert-Yahoo CPAN distribution.

Report information
The Basics
Id: 11727
Status: resolved
Priority: 0/
Queue: Finance-Currency-Convert-Yahoo

People
Owner: Nobody in particular
Requestors: rrwo [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 0.045
Fixed in: (no value)



Subject: OPTIMIZATION - No need to parse HTML when querying Yahoo
If you request from the <http://finance.yahoo.com/d/quotes.csv> URL, then you only need to parse a CSV file rather than an HTML file. This is a lot easier, since you just need to remove quotes and split on commas. An example is attached.
# Script to fetch current exchange rate from Yahoo # $Id: xr.pl,v 1.1.1.1 2005/03/02 22:57:24 Rob Exp $ use strict; use warnings; use LWP::Simple; my $Args = { from => 'GBP', to => 'USD', amt => 1, debug => 0, }; sub strip_quotes { my $x = shift; $x =~ s/^\"?(.+)\"$/$1/; return $x; } my $Url = "http://finance.yahoo.com/d/quotes.csv?s=$Args->{from}$Args->{to}=X&f=sl1d1t1ba&e=.csv"; my $Data = get $Url; print $Data, if $Args->{debug}; my ($Symbol, $Rate, $Date, $Time, $Bid, $Ask) = split /,/, $Data; $Args->{date} = strip_quotes($Date); $Args->{time} = strip_quotes($Time); $Args->{rate} = $Rate; $Args->{value} = $Args->{rate} * $Args->{amt}; print sprintf("%1.2f %s = %1.2f %s (as of %s %s)\n", map { $Args->{$_} } (qw( amt from value to date time)));
[guest - Wed Mar 2 18:12:48 2005]: Show quoted text
> If you request from the <http://finance.yahoo.com/d/quotes.csv> URL, > then you only need to parse a CSV file rather than an HTML file. > This is a lot easier, since you just need to remove quotes and > split on commas. > > An example is attached.
Now *that* is what I call an optimization. Is it a relatively new feature? I'll put it in ASAP, many thanks Lee