2010-12-08 11:52:22 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# Test file for price database stuff
|
|
|
|
|
# To update the price database call
|
|
|
|
|
# $PATH/gnucash --add-price-quotes $PATHTOFILE
|
|
|
|
|
# before running this.
|
|
|
|
|
# Adding to a calling bash script would be better
|
|
|
|
|
# Although calling it from here would be even better!
|
|
|
|
|
# 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.
|
|
|
|
|
|
2010-12-17 20:36:40 +00:00
|
|
|
## @file
|
|
|
|
|
# @brief Test file for price database stuff
|
|
|
|
|
# @author Mike Evans
|
2010-12-27 15:36:15 +00:00
|
|
|
# @ingroup python_bindings_examples
|
2010-12-08 11:52:22 +00:00
|
|
|
|
2010-12-17 14:00:52 +00:00
|
|
|
from gnucash import Session
|
2010-12-08 11:52:22 +00:00
|
|
|
FILE = "PATH_TO_YOUR_TEST_FILE" ## Fail is no saved but use a copy anyway
|
|
|
|
|
|
|
|
|
|
session = Session("xml://%s" % FILE, True, False, False)
|
|
|
|
|
|
|
|
|
|
root = session.book.get_root_account()
|
|
|
|
|
book = session.book
|
|
|
|
|
pdb = book.get_price_db()
|
|
|
|
|
comm_table = book.get_table()
|
|
|
|
|
gbp = comm_table.lookup("CURRENCY", "SOME_CURRENCY")
|
|
|
|
|
arm = comm_table.lookup("NASDAQ", "SOME_STOCK")
|
|
|
|
|
latest = pdb.lookup_latest(arm,gbp) # from the table, NOT live data
|
|
|
|
|
value = latest.get_value()
|
|
|
|
|
pl = pdb.get_prices(arm,gbp)
|
2010-12-17 14:00:52 +00:00
|
|
|
for pr in pl:
|
2010-12-08 11:52:22 +00:00
|
|
|
source = pr.get_source()
|
|
|
|
|
time = pr.get_time()
|
|
|
|
|
v=pr.get_value()
|
|
|
|
|
price = float(v.num)/v.denom
|
|
|
|
|
print time, source, price
|
|
|
|
|
|
2010-12-17 14:00:52 +00:00
|
|
|
if len(pl) > 0:
|
|
|
|
|
v0 = pl[0].get_value()
|
|
|
|
|
print arm.get_fullname(), float(v0.num) / float(v0.denom )
|
2010-12-08 11:52:22 +00:00
|
|
|
|
|
|
|
|
session.end()
|
|
|
|
|
session.destroy()
|
|
|
|
|
quit()
|