[GNC] Scripted price editing and adding

Jon Schewe jpschewe at mtu.net
Fri Jan 17 19:33:42 EST 2020


On 1/14/20 10:28 PM, Raymond Smith wrote:
> Hi, Gnucash list.
>
> I'm interested in using a script to add and edit prices in my Gnucash file.
> For example, I'd like to
> (a) loop over a file containing historical price data and add prices for
> dates where the price is missing because I didn't do a quote retrieval in
> Gnucash that day
> (b) loop over the prices I have of one security and add prices for call
> options using max(0, security price - strike price).
> I would prefer working in Python if possible, and I'm looking for guidance
> on the right approach.
>
> I've seen there are some Python bindings and also the piecash library, but
> it's not clear to me how well maintained or supported either is right now.
> I found relatively little documentation on the Python bindings (
> https://wiki.gnucash.org/wiki/Python_Bindings). Piecash looks very nice,
> and I was able to set up a simple example where I added a price using it.
> But, it currently has a very minor issue (
> https://github.com/sdementen/piecash/issues/126) that prevented it from
> running on my recent gnucash save files without a simple fix. Not a big
> deal to do that, but I'd like to avoid tying myself to a library that
> stalls while Gnucash and my save files continue to evolve.
>
> Another option I've thought about is to parse xml files using something
> like Python's xml library. That seems reasonably straightforward at first
> glance, but perhaps there are some things I should be aware of that I'm
> missing that would make this a bad idea? One question that has already come
> up is how to manage guid's of the prices. Can they be any string of the
> appropriate length as long as each is unique within the file? I tried a
> super simple test file where I copied one <price></price> block and changed
> the date, price, and guid, then re-opened the file, and it seemed to work,
> but I'm not sure if that's dangerous.
Take a look at this post that I put up last month 
https://lists.gnucash.org/pipermail/gnucash-user/2019-December/088313.html
This has a reference to a script that I wrote to get my price quotes on 
a regular basis when the normal mechanism wasn't working. The python 
bindings seem to work fine.

Jon

-- 
http://mtu.net/~jpschewe



More information about the gnucash-user mailing list