18 from gnucash
import Session
26 commodity_fullname =
""
27 FILE =
"PATH_TO_YOUR_TEST_FILE"
32 session = Session(FILE,
True,
False,
False)
34 root = session.book.get_root_account()
36 pdb = book.get_price_db()
37 comm_table = book.get_table()
39 cur = comm_table.lookup(
"CURRENCY", cur_mnemonic)
40 cur_name = cur.get_fullname()
43 if namespace_name !=
"":
44 namespaces [ comm_table.find_namespace(namespace_name) ]
47 namespaces=comm_table.get_namespaces_list()
49 for namespace
in namespaces:
51 namespace_name=namespace.get_name()
55 commodities=comm_table.get_commodities(namespace_name)
58 if len(commodities) == 0 :
60 print "No commodity in namespace "+namespace_name+
"."
62 if commodity_fullname:
63 print "Searching commodity '"+commodity_fullname+
"' in namespace "+namespace_name
65 print "Commoditys in namespace "+namespace_name+
":"
68 for i, c
in enumerate(commodities):
70 c_fullname = c.get_fullname()
72 if not(commodity_fullname)
or (commodity_fullname == c_fullname):
73 print "["+str(i)+
"] Full Name :", c.get_fullname()
75 pl = pdb.get_prices(c,cur)
78 print "{0} {1:20}{2:>10} {3}".format(
"Time ",
"Source",
"Price",
"Currency")
81 source = pr.get_source()
84 price = float(v.num)/v.denom
86 print "{0} {1:20}{2:10.4f} {3}".format(time,source,price,cur_name)