mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Paul Fenwick's patch to the quoting system to support Finance::Quote 1.01.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2680 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
2
AUTHORS
2
AUTHORS
@@ -58,7 +58,7 @@ Glen Ditchfield <gjditchfield@acm.org> updated documentation
|
||||
Tyson Dowd <tyson@tyse.net> for config/make patches & debian maint
|
||||
Koen D'Hondt <ripley@xs4all.nl> for Solaris patches to XmHTML
|
||||
Bob Drzyzgula <bob@mostly.com> for budgeting design notes
|
||||
Paul Fenwick <pjf@schools.net.au> ASX support
|
||||
Paul Fenwick <pjf@schools.net.au> ASX support, Finance::Quote
|
||||
Hubert Figuiere <hfiguiere@teaser.fr> patch to gnc-prices
|
||||
Valek Filippov <frob@df.ru> Russian translation
|
||||
Jan-Uwe Finck <ju_finck@mail.netwave.de> for German message translation
|
||||
|
||||
@@ -4,12 +4,9 @@ bin_SCRIPTS = gnc-prices
|
||||
perllibdir = ${GNC_LIBDIR}/perl
|
||||
|
||||
perlsharedir = ${GNC_SHAREDIR}/perl
|
||||
perlshare_DATA = \
|
||||
Quote.pm
|
||||
|
||||
EXTRA_DIST = \
|
||||
.cvsignore \
|
||||
Quote.pm \
|
||||
Quote_example.pl \
|
||||
gnc-prices-2.in \
|
||||
gnc-prices.in \
|
||||
|
||||
@@ -120,10 +120,8 @@ bin_SCRIPTS = gnc-prices
|
||||
perllibdir = ${GNC_LIBDIR}/perl
|
||||
|
||||
perlsharedir = ${GNC_SHAREDIR}/perl
|
||||
perlshare_DATA = Quote.pm
|
||||
|
||||
|
||||
EXTRA_DIST = .cvsignore Quote.pm Quote_example.pl gnc-prices-2.in gnc-prices.in value_portfolio
|
||||
EXTRA_DIST = .cvsignore Quote_example.pl gnc-prices-2.in gnc-prices.in value_portfolio
|
||||
|
||||
|
||||
CLEANFILES = gnc-prices
|
||||
@@ -132,8 +130,6 @@ CONFIG_HEADER = ../../config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
SCRIPTS = $(bin_SCRIPTS)
|
||||
|
||||
DATA = $(perlshare_DATA)
|
||||
|
||||
DIST_COMMON = README Makefile.am Makefile.in
|
||||
|
||||
|
||||
@@ -169,25 +165,6 @@ uninstall-binSCRIPTS:
|
||||
list='$(bin_SCRIPTS)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \
|
||||
done
|
||||
|
||||
install-perlshareDATA: $(perlshare_DATA)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(perlsharedir)
|
||||
@list='$(perlshare_DATA)'; for p in $$list; do \
|
||||
if test -f $(srcdir)/$$p; then \
|
||||
echo " $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(perlsharedir)/$$p"; \
|
||||
$(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(perlsharedir)/$$p; \
|
||||
else if test -f $$p; then \
|
||||
echo " $(INSTALL_DATA) $$p $(DESTDIR)$(perlsharedir)/$$p"; \
|
||||
$(INSTALL_DATA) $$p $(DESTDIR)$(perlsharedir)/$$p; \
|
||||
fi; fi; \
|
||||
done
|
||||
|
||||
uninstall-perlshareDATA:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
list='$(perlshare_DATA)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(perlsharedir)/$$p; \
|
||||
done
|
||||
tags: TAGS
|
||||
TAGS:
|
||||
|
||||
@@ -223,20 +200,20 @@ installcheck: installcheck-am
|
||||
install-exec-am: install-binSCRIPTS
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am: install-perlshareDATA
|
||||
install-data-am:
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am: uninstall-binSCRIPTS uninstall-perlshareDATA
|
||||
uninstall-am: uninstall-binSCRIPTS
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(SCRIPTS) $(DATA)
|
||||
all-am: Makefile $(SCRIPTS)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
$(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(perlsharedir)
|
||||
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
@@ -268,13 +245,12 @@ maintainer-clean-am: maintainer-clean-generic distclean-am
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: uninstall-binSCRIPTS install-binSCRIPTS uninstall-perlshareDATA \
|
||||
install-perlshareDATA tags distdir info-am info dvi-am dvi check \
|
||||
check-am installcheck-am installcheck install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
mostlyclean distclean maintainer-clean
|
||||
.PHONY: uninstall-binSCRIPTS install-binSCRIPTS tags distdir info-am \
|
||||
info dvi-am dvi check check-am installcheck-am installcheck \
|
||||
install-exec-am install-exec install-data-am install-data install-am \
|
||||
install uninstall-am uninstall all-redirect all-am all installdirs \
|
||||
mostlyclean-generic distclean-generic clean-generic \
|
||||
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
gnc-prices: gnc-prices.in
|
||||
|
||||
1162
src/quotes/Quote.pm
1162
src/quotes/Quote.pm
File diff suppressed because it is too large
Load Diff
@@ -3,11 +3,14 @@
|
||||
# example script showing how to use the Quote perl module.
|
||||
# gets prices for some stocks, for some mutual funds
|
||||
|
||||
use Quote;
|
||||
use Finance::Quote;
|
||||
|
||||
# Create a quote object.
|
||||
my $quoter = Finance::Quote->new();
|
||||
|
||||
# -----------------------------------
|
||||
# get quotes for two stocks ...
|
||||
%quotes = Quote::yahoo ("IBM", "SGI");
|
||||
%quotes = $quoter->fetch("yahoo","IBM", "SGI");
|
||||
|
||||
# print some selected values
|
||||
print "NYSE by Yahoo: ", $quotes {"IBM", "name"},
|
||||
@@ -28,7 +31,7 @@ print "\n\n";
|
||||
# -----------------------------------
|
||||
# get quotes from Fidelity Investments
|
||||
@funds = ("FGRIX", "FNMIX", "FASGX", "FCONX");
|
||||
%quotes = Quote::fidelity (@funds);
|
||||
%quotes = $quoter->fetch("fidelity",@funds);
|
||||
|
||||
foreach $f (@funds) {
|
||||
$name = $quotes {$f, "name"};
|
||||
@@ -39,7 +42,7 @@ print "\n\n";
|
||||
|
||||
# -----------------------------------
|
||||
@funds = ("FGRXX");
|
||||
%quotes = Quote::fidelity (@funds);
|
||||
%quotes = $quoter->fetch("fidelity",@funds);
|
||||
|
||||
print "Not all funds have a NAV; some have Yeilds:\n";
|
||||
foreach $f (@funds) {
|
||||
@@ -52,7 +55,7 @@ print "\n\n";
|
||||
# -----------------------------------
|
||||
# demo T. Rowe Price -- same as above
|
||||
@funds = ("PRFDX", "PRIDX");
|
||||
%quotes = Quote::troweprice (@funds);
|
||||
%quotes = $quoter->fetch("troweprice",@funds);
|
||||
|
||||
foreach $f (@funds) {
|
||||
$nav = $quotes {$f, "nav"};
|
||||
@@ -66,7 +69,7 @@ print "\n\n";
|
||||
|
||||
# demo for ASX. Grab the price of Coles-Myer and Telstra
|
||||
@funds = ("CML","TLS");
|
||||
%quotes = Quote::asx(@funds);
|
||||
%quotes = $quoter->fetch("australia",@funds);
|
||||
foreach $f (@funds) {
|
||||
print "ASX Price of $f is ".$quotes{$f,"last"}." at ".
|
||||
$quotes{$f,"date"}."\n";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use strict;
|
||||
use English;
|
||||
use Quote;
|
||||
use Finance::Quote;
|
||||
|
||||
## Simple program to get quotes and feed them back to gnucash.
|
||||
|
||||
@@ -46,6 +46,9 @@ use Quote;
|
||||
|
||||
my $exit_status = 0;
|
||||
|
||||
# Create a stockquote object.
|
||||
my $quoter = Finance::Quote->new();
|
||||
|
||||
sub schemify_str {
|
||||
my($str) = @_;
|
||||
|
||||
@@ -92,7 +95,7 @@ while(<>) {
|
||||
next;
|
||||
}
|
||||
|
||||
my %quote_data = &Quote::fetch($quote_source_name,$security_name);
|
||||
my %quote_data = $quoter->fetch($quote_source_name,$security_name);
|
||||
|
||||
unless($quote_data{$quote_source_name,'success'}) {
|
||||
# We don't have to schemify the source or name - the regexp filtered it.
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
# Copyright (c) 1999-2000 Linas Vepstas
|
||||
|
||||
use lib '@-GNC_PERLSHAREDIR-@';
|
||||
use Quote;
|
||||
use lib '@-GNC_PERLLIBDIR-@';
|
||||
|
||||
use Finance::Quote;
|
||||
use gnucash;
|
||||
|
||||
# --------------------------------------------------
|
||||
@@ -133,6 +134,10 @@ $grp = gnucash::xaccSessionBeginFile ($sess,$ARGV[0]);
|
||||
|
||||
die "failed to read file $ARGV[0], maybe its locked? " if (! $grp);
|
||||
|
||||
# Create our quote object
|
||||
|
||||
my $quote = Finance::Quote->new();
|
||||
|
||||
# get a flat list of accounts in the file
|
||||
@acctlist = &account_flatlist ($grp);
|
||||
|
||||
@@ -167,19 +172,9 @@ foreach $acct (@acctlist)
|
||||
|
||||
undef $price; # undef to make sure later if($price) not broken
|
||||
|
||||
# assign to a list, beacuse if fetch fails assignment
|
||||
# to a hash will raise a warning, as it will return a one
|
||||
# element list. where the first element is undef
|
||||
@quotes_list = &Quote::fetch($quotesrc, $security);
|
||||
%quotes = $quote->fetch($quotesrc, $security);
|
||||
|
||||
# if and only if there really is information then assign to the hash
|
||||
%quotes = @quotes_list if $quotes_list[0];
|
||||
|
||||
# the fetch is OK if and only if information is returned AND
|
||||
# it is maked as a success
|
||||
# The first condition is needed becasue if no information
|
||||
# returned then %quotes is uninitialized and perl will raise a warning
|
||||
unless ($quotes_list[0] && $quotes{$security,'success'})
|
||||
unless ($quotes{$security,'success'})
|
||||
{
|
||||
print "Lookup of $quotesrc/$security failed";
|
||||
# Show the error if and only if there is an error message
|
||||
@@ -196,11 +191,6 @@ foreach $acct (@acctlist)
|
||||
|
||||
if ($price)
|
||||
{
|
||||
# if and only if the price is served by Yahoo Europe AND is dealt on
|
||||
# the London stock market then the price will be given in pence. So to
|
||||
# convert this into GBP divide the price by 100 before storing the new price.
|
||||
$price/=100 if (($security=~/.L$/i) && ($quotesrc eq 'YAHOO_EUROPE'));
|
||||
|
||||
print "$name: $security $prodname last price = $price at $dayte\n";
|
||||
# This || construction will store the price if its not already
|
||||
# stored (in the 28 hour period surrounding "dayte")
|
||||
|
||||
Reference in New Issue
Block a user