20 from gnucash
import Session, Account, Split
23 from fractions
import Fraction
24 from gnc_convenience
import find_account
26 FILE =
"./test.gnucash" 43 for i
in range(1,len(data)):
44 year = int(data[i].rsplit(
',')[1].rsplit(
'/')[0])
45 month = int(data[i].rsplit(
',')[1].rsplit(
'/')[1])
46 day = int(data[i].rsplit(
',')[1].rsplit(
'/')[2])
47 stock_date.append(datetime.datetime(year,month,day))
48 stock_price.append(float(data[i].rsplit(
',')[5]))
51 session = Session(url,
True,
False,
False)
52 root = session.book.get_root_account()
54 account = book.get_root_account()
55 pdb = book.get_price_db()
56 comm_table = book.get_table()
57 ac = find_account(account,
'Intel')[0]
59 stock = ac.GetCommodity()
61 pdb = book.get_price_db()
62 if len(ac.GetSplitList())<1:
63 print(
'Need at least one Split to get currency info ... ')
65 cur = ac.GetSplitList()[0].GetParent().GetCurrency()
68 pl = pdb.get_prices(stock,cur)
70 print(
'Need at least one database entry to clone ...')
74 for i
in range(1,len(pl)):
75 pdb.remove_price(pl[i])
77 for i
in range(0,len(stock_date)):
78 p_new = pl0.clone(book)
79 p_new = gnucash.GncPrice(instance=p_new)
80 print(
'Adding',i,stock_date[i],stock_price[i])
81 p_new.set_time64(stock_date[i])
83 v.num = int(Fraction.from_float(stock_price[i]).limit_denominator(100000).numerator)
84 v.denom = int(Fraction.from_float(stock_price[i]).limit_denominator(100000).denominator)
86 p_new.set_source(
"Finance::Quotes::Historic")