|
GnuCash 2.4.99
|
00001 #!/usr/bin/env python 00002 # Test file for price database stuff 00003 # To update the price database call 00004 # $PATH/gnucash --add-price-quotes $PATHTOFILE 00005 # before running this. 00006 # Adding to a calling bash script would be better 00007 # Although calling it from here would be even better! 00008 # OR: export PYTHONPATH=$HOME/progs/lib/python2.6/site-packages 00009 # Then: gnucash-env ipython 00010 # The account file is not saved but always use a disposable copy. 00011 # Change, FILE, CURRENCY and STOCK to those defined in your test account. 00012 00013 ## @file 00014 # @brief Test file for price database stuff 00015 # @author Mike Evans 00016 # @ingroup python_bindings_examples 00017 00018 from gnucash import Session 00019 00020 # FILE should be the path to your existing gnucash file/database 00021 # For a file, simply pass the pathname, for a database you can use 00022 # these forms: 00023 # mysql://user:password@host/dbname 00024 # postgres://user:password@host[:port]/dbname (the port is optional) 00025 # 00026 FILE = "PATH_TO_YOUR_TEST_FILE" ## Fail is not saved but use a copy anyway 00027 00028 session = Session(FILE, True, False, False) 00029 00030 root = session.book.get_root_account() 00031 book = session.book 00032 pdb = book.get_price_db() 00033 comm_table = book.get_table() 00034 gbp = comm_table.lookup("CURRENCY", "SOME_CURRENCY") 00035 arm = comm_table.lookup("NASDAQ", "SOME_STOCK") 00036 latest = pdb.lookup_latest(arm,gbp) # from the table, NOT live data 00037 value = latest.get_value() 00038 pl = pdb.get_prices(arm,gbp) 00039 for pr in pl: 00040 source = pr.get_source() 00041 time = pr.get_time() 00042 v=pr.get_value() 00043 price = float(v.num)/v.denom 00044 print time, source, price 00045 00046 if len(pl) > 0: 00047 v0 = pl[0].get_value() 00048 print arm.get_fullname(), float(v0.num) / float(v0.denom ) 00049 00050 session.end() 00051 session.destroy() 00052 quit()
1.7.4