20 from gnucash
import Session, GncNumeric, GncPrice, PriceSource, GNC_HOW_DENOM_FIXED, GNC_HOW_RND_ROUND_HALF_UP
21 from gnucash.gnucash_core_c
import COMMODITY_DENOM_MULT
23 from gnc_convenience
import find_account
25 FILE =
"./test.gnucash" 42 for i
in range(1,len(data)):
43 year = int(data[i].rsplit(
',')[1].rsplit(
'/')[0])
44 month = int(data[i].rsplit(
',')[1].rsplit(
'/')[1])
45 day = int(data[i].rsplit(
',')[1].rsplit(
'/')[2])
46 stock_date.append(datetime.datetime(year,month,day))
47 stock_price.append(float(data[i].rsplit(
',')[5]))
50 session = Session(url)
51 root = session.book.get_root_account()
53 account = book.get_root_account()
54 pdb = book.get_price_db()
55 comm_table = book.get_table()
58 ac = find_account(account,
'Intel')[0]
59 stock = ac.GetCommodity()
60 cur = comm_table.lookup(
"CURRENCY",
"USD")
66 price_denom = cur.get_fraction() * COMMODITY_DENOM_MULT
67 for i
in range(0, len(stock_date)):
68 print(
'Adding', i, stock_date[i], stock_price[i])
70 p_new = GncPrice(book)
71 p_new.set_commodity(stock)
72 p_new.set_currency(cur)
73 p_new.set_time64(stock_date[i])
74 p_new.set_value(
GncNumeric(stock_price[i], price_denom,
75 GNC_HOW_DENOM_FIXED | GNC_HOW_RND_ROUND_HALF_UP))
76 p_new.set_source(PriceSource.FINANCE_QUOTE)
77 p_new.set_typestr(
"last")
The primary numeric class for representing amounts and values.