19 from gnucash
import Session
27 commodity_fullname =
"" 28 FILE =
"PATH_TO_YOUR_TEST_FILE" 33 session = Session(FILE,
True,
False,
False)
35 root = session.book.get_root_account()
37 pdb = book.get_price_db()
38 comm_table = book.get_table()
40 cur = comm_table.lookup(
"CURRENCY", cur_mnemonic)
41 cur_name = cur.get_fullname()
44 if namespace_name !=
"":
45 namespaces [ comm_table.find_namespace(namespace_name) ]
48 namespaces=comm_table.get_namespaces_list()
50 for namespace
in namespaces:
52 namespace_name=namespace.get_name()
56 commodities=comm_table.get_commodities(namespace_name)
59 if len(commodities) == 0 :
61 print(
"No commodity in namespace "+namespace_name+
".")
63 if commodity_fullname:
64 print(
"Searching commodity '"+commodity_fullname+
"' in namespace "+namespace_name)
66 print(
"Commoditys in namespace "+namespace_name+
":")
69 for i, c
in enumerate(commodities):
71 c_fullname = c.get_fullname()
73 if not(commodity_fullname)
or (commodity_fullname == c_fullname):
74 print(
"["+str(i)+
"] Full Name :", c.get_fullname())
76 pl = pdb.get_prices(c,cur)
79 print(
"{0} {1:20}{2:>10} {3}".format(
"Time ",
"Source",
"Price",
"Currency"))
82 source = pr.get_source()
83 time = pr.get_time64()
85 price = float(v.num)/v.denom
87 print(
"{0} {1:20}{2:10.4f} {3}".format(time,source,price,cur_name))