From 3e534b254e89f1fb3e8bf0e4eed88992ef3aee36 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Thu, 31 Dec 1998 07:55:37 +0000 Subject: [PATCH] more stuff git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1509 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/quotes/README | 4 ++ src/quotes/YahooQuote.pm | 127 +++++++++++++++++++++++++++++++++++++++ src/quotes/getquotes.pl | 28 +-------- 3 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 src/quotes/YahooQuote.pm diff --git a/src/quotes/README b/src/quotes/README index 225a153850..5fe940f733 100644 --- a/src/quotes/README +++ b/src/quotes/README @@ -11,3 +11,7 @@ getquotes.pl is a set of perl routines to fetch stock quotes from various services. dervied from the above. Still under development. +Finance::YahooQuote + This is a perl 5 module that will pull one or more stock quotes from + Yahoo! Finance. From version 0.06 by Dj Padzensky . + Home site at http://www.padz.net/~djpadz/ diff --git a/src/quotes/YahooQuote.pm b/src/quotes/YahooQuote.pm new file mode 100644 index 0000000000..48e143c0c5 --- /dev/null +++ b/src/quotes/YahooQuote.pm @@ -0,0 +1,127 @@ +# perl -w +# +# Copyright (C) 1998, Dj Padzensky +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +package Finance::YahooQuote; +require 5.000; + +require Exporter; +use strict; +use vars qw($VERSION @EXPORT @ISA $QURL); + +use LWP::UserAgent; +use HTTP::Request::Common; + +$VERSION = '0.06'; +$QURL = ("http://quote.yahoo.com/d?f=snl1d1t1c1p2va2bapomwerr1dyj1&s="); +@ISA = qw(Exporter); +@EXPORT = qw(&getquote &getonequote); + +sub getquote { + my @symbols = @_; + my($x,@q,@qr,$ua,$url); + $x = $"; + $" = "+"; + $url = $QURL."@symbols"; + $" = $x; + $ua = LWP::UserAgent->new; + foreach (split('\n',$ua->request(GET $url)->content)) { + @q = grep { s/^"?(.*?)\s*"?\s*$/$1/; } split(','); + push(@qr,[@q]); + } + return wantarray() ? @qr : \@qr; +} + +# Input: A single stock symbol +# Output: An array, containing the list elements mentioned above. + +sub getonequote { + my @x; + @x = &getquote($_[0]); + return @{$x[0]} if defined @x; +} + +__END__ + +1; + +=head1 NAME + +Finance::YahooQuote - Get a stock quote from Yahoo! + +=head1 SYNOPSIS + + use Finance::YahooQuote; + @quote = getonequote $symbol; # Get a quote for a single symbol + @quotes = getquote @symbols; # Get quotes for a bunch of symbols + +=head1 DESCRIPTION + +This module gets stock quotes from Yahoo! Finance. The B +function will return a quote for a single stock symbol, while the +B function will return a quote for each of the stock symbols +passed to it. The return value of B is an array, with +the following elements: + + 0 Symbol + 1 Company Name + 2 Last Price + 3 Last Trade Date + 4 Last Trade Time + 5 Change + 6 Percent Change + 7 Volume + 8 Average Daily Vol + 9 Bid + 10 Ask + 11 Previous Close + 12 Today's Open + 13 Day's Range + 14 52-Week Range + 15 Earnings per Share + 16 P/E Ratio + 17 Dividend Pay Date + 18 Dividend per Share + 19 Dividend Yield + 20 Market Capitalization + +The B function returns an array of pointers to arrays with +the above structure. + +=head1 COPYRIGHT + +Copyright 1998, Dj Padzensky + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +The information that you obtain with this library may be copyrighted +by Yahoo! Inc., and is governed by their usage license. See +http://www.yahoo.com/docs/info/gen_disclaimer.html for more +information. + +=head1 AUTHOR + +Dj Padzensky (C), PadzNet, Inc. + +The Finance::YahooQuote home page can be found at +http://www.padz.net/~djpadz/YahooQuote/ + +=cut diff --git a/src/quotes/getquotes.pl b/src/quotes/getquotes.pl index ac62afe283..5ca8f9d155 100755 --- a/src/quotes/getquotes.pl +++ b/src/quotes/getquotes.pl @@ -26,7 +26,7 @@ sub get_url_command { ####################################################################### -###################### &get_quote_from_qyahoo(); ###################### +###################### &get_quote_from_yahoo(); ###################### ####################################################################### # Look up a stock via "yahoo" # usage: &get_yaho ("IBM", "NYSE"); @@ -80,31 +80,6 @@ sub get_quote_from_yahoo { } } -####################################################################### -############### &add_stock("NVA", 100, 1345.5, "TSE"); ################ -####################################################################### -# Add a security to the "active list," including the "ticker symbol," -# quantity of shares, original total cost, and the exchange to look it -# up on. -####################################################################### -sub add_stock { - local($ticker, $num, $cost, $exchange) = @_; - $NUM{$ticker} = $num; - $COST{$ticker} = $cost; - $EXCHANGE{$ticker} = $exchange; - local ($currency) = "CDN"; - if ($exchange eq "TSE") { - $currency = "CDN"; - } - if ($exchange eq "NYSE") { - $currency = "USD"; - } - if ($exchange eq "NY") { - $currency = "USD"; - } - $CURRENCY{$ticker} = $currency; -} - ####################################################################### ###################### &search_web_for_prices(); ###################### ####################################################################### @@ -148,6 +123,7 @@ sub search_web_for_prices { ########################## &get_TSE ("RY"); ########################### ####################################################################### # Look up a stock's price on the TSE using the Telenium service +# TSE == toronoto stock exchange, primarily canadian stocks ####################################################################### sub get_TSE { local ($stock) = @_;