mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Changes to example Script to include added namespace functionality
This patch changes the example script to reflect the capability of reading all namespaces. Patch provided by Christoph Holtermann. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19954 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# Test file for price database stuff
|
||||
# Another test file for price database stuff
|
||||
# To update the price database call
|
||||
# $PATH/gnucash --add-price-quotes $PATHTOFILE
|
||||
# before running this.
|
||||
@@ -8,7 +8,6 @@
|
||||
# OR: export PYTHONPATH=$HOME/progs/lib/python2.6/site-packages
|
||||
# Then: gnucash-env ipython
|
||||
# The account file is not saved but always use a disposable copy.
|
||||
# Change, FILE, CURRENCY and STOCK to those defined in your test account.
|
||||
# Thanks for contributions by Christoph Holtermann
|
||||
|
||||
import gnucash
|
||||
@@ -18,10 +17,10 @@ from gnucash.gnucash_core import *
|
||||
# -------------------------------------------
|
||||
# Configuration options can be changed here :
|
||||
|
||||
cur_mnemonic="EUR" # Possibilities include "EUR","GBP"
|
||||
namespace = "EUREX" # Predefined namespaces are "CURRENCY","EUREX","AMEX","template"
|
||||
show_prices = True
|
||||
commodity_fullname = "ThyssenKrupp AG" # If no name is given, all commoditys in namespace will be printed out
|
||||
cur_mnemonic="EUR" # Currency that prices are shown in. Possibilities include "EUR","GBP",...
|
||||
namespace_name = "" # If no namespace_name is set, all namespaces will be shown
|
||||
show_prices = True # If True, all prices for commodity are shown
|
||||
commodity_fullname = "" # If no name is given, all commoditys in namespace will be shown
|
||||
FILE = "PATH_TO_YOUR_TEST_FILE" # File is not saved but use a copy anyway
|
||||
url = "xml://"+FILE
|
||||
|
||||
@@ -38,39 +37,47 @@ comm_table = book.get_table()
|
||||
cur = comm_table.lookup("CURRENCY", cur_mnemonic)
|
||||
cur_name = cur.get_fullname()
|
||||
|
||||
# Get a list of all commodities in namespace
|
||||
commodities=comm_table.get_commodities(namespace)
|
||||
if namespace_name: # Show single namespace
|
||||
namespaces=[]
|
||||
namespace=gnucash.gnucash_core_c.gnc_commodity_table_find_namespace(comm_table.instance,"EUREX")
|
||||
else: # Show all namespaces
|
||||
namespaces=comm_table.get_namespaces_list()
|
||||
|
||||
if not commodities:
|
||||
print "No commodity in namespace "+namespace+" !"
|
||||
quit()
|
||||
for namespace in namespaces:
|
||||
namespace_name=gnucash.gnucash_core_c.gnc_commodity_namespace_get_name(namespace)
|
||||
|
||||
if commodity_fullname:
|
||||
print "Searching commodity '"+commodity_fullname+"' in namespace "+namespace
|
||||
else:
|
||||
print "Commoditys in namespace "+namespace+":"
|
||||
# Get a list of all commodities in namespace
|
||||
commodities=comm_table.get_commodities(namespace_name)
|
||||
|
||||
for i in range(len(commodities)):
|
||||
c=gnucash.GncCommodity(instance=commodities[i])
|
||||
commodities[i]=c
|
||||
if not commodities:
|
||||
print "No commodity in namespace "+namespace_name+"."
|
||||
else:
|
||||
if commodity_fullname:
|
||||
print "Searching commodity '"+commodity_fullname+"' in namespace "+namespace_name
|
||||
else:
|
||||
print "Commoditys in namespace "+namespace_name+":"
|
||||
|
||||
c_fullname = c.get_fullname()
|
||||
for i in range(len(commodities)):
|
||||
c=gnucash.GncCommodity(instance=commodities[i])
|
||||
commodities[i]=c
|
||||
|
||||
if not(commodity_fullname) or (commodity_fullname == c_fullname):
|
||||
print "["+str(i)+"] Full Name :", c.get_fullname()
|
||||
if show_prices:
|
||||
pl = pdb.get_prices(c,cur)
|
||||
if pl:
|
||||
print "{0} {1:20}{2:10} {3}".format("Time ","Source","Price","Currency")
|
||||
for i in pl:
|
||||
pr = GncPrice(instance=i)
|
||||
source = pr.get_source()
|
||||
time = pr.get_time()
|
||||
v=pr.get_value()
|
||||
price = float(v.num)/v.denom
|
||||
c_fullname = c.get_fullname()
|
||||
|
||||
print "{0} {1:20}{2:10.4f} {3}".format(time,source,price,cur_name)
|
||||
# I didn't find out how to format the time option...
|
||||
if not(commodity_fullname) or (commodity_fullname == c_fullname):
|
||||
print "["+str(i)+"] Full Name :", c.get_fullname()
|
||||
if show_prices:
|
||||
pl = pdb.get_prices(c,cur)
|
||||
if pl:
|
||||
print "{0} {1:20}{2:>10} {3}".format("Time ","Source","Price","Currency")
|
||||
for i in pl:
|
||||
pr = GncPrice(instance=i)
|
||||
source = pr.get_source()
|
||||
time = pr.get_time()
|
||||
v=pr.get_value()
|
||||
price = float(v.num)/v.denom
|
||||
|
||||
print "{0} {1:20}{2:10.4f} {3}".format(time,source,price,cur_name)
|
||||
# I didn't find out how to format the time option...
|
||||
|
||||
session.end()
|
||||
session.destroy()
|
||||
|
||||
Reference in New Issue
Block a user