Edit prices for multiple gnucash files

Stuart McGraw smcg4191 at frii.com
Thu Sep 20 19:23:59 EDT 2012


On 09/20/2012 06:40 AM, spotty albino wrote:
> Thank you, that would be very helpful. My email is jehelsby at iinet.net.au 
> 
> Thanks for these comments. While I don't have any programming experience,
> I'm keen to try and follow your suggestions. I really want to make GNUcash
> work to suit my needs. I'll begin looking over that documentation.

Hi Joshua,

I've mailed you the scripts mentioned on the gnucash 
separately.  I figured I post what I know about them here 
in case it is useful to someone else in the future.
As mentioned, the scripts are just modified versions
of what is on http://wiki.gnucash.org/wiki/Stocks/get_prices

* get_history.pl
----------------
To run this you will need Perl which you likely already have 
installed if you are using Gnucash's "get quotes" feature.  
But you'll also need to install the perl Finance::QuotHist 
module from CPAN.

My changes were to add command line options including some to 
retrieve dividend and split info in addition to price quotes,
and to add additional columns to the csv output to make it 
easier to use when imported into a spreadsheet or database.
The dividend/splits options are not really relevant for 
importing price history into Gnucash; I wanted them because 
I wanted to analyze stock performance independently of Gnucash.

Running "perl get_history.pl -h" should print info on what
arguments it takes.

* imp_history.py
----------------
Looking at this it seems to mostly be stylistic changes.  The
only substantive changes seem to be accepting the input file
name on the command line and accepting the additional columns 
that the revised get_history.pl produces.  Note that this program
works only with a Gnucash XML file at the moment (although
it hardwires the input file name into an "//xml:" url internally;
using with db backend might be as simple as changing the url.)
And of course you need Python installed in order to run it.
It also requires a version of Gnucash that was built with the 
Python bindings.  If your version of Gnucash wasn't, then you
will get an error like
  ImportError: No module named gnucash
(and some other stuff) when you run it.

~~~~
I just tried running the programs on a test Gnucash file.
Note that the the stocks for which history is being added
need to be in Gnucash already, with at least one price for
each.  (They can be a bogus price entry that you delete 
after importing the real prices.)  

# Get historical quotes for Starbucks from July 2012 to present:
$ perl get_history.pl -q -f 2012-07-01 -t today > sbux.csv
$ cat sbux.csv
2012/06/01, SBUX, Q, 53.1100, 54.0600, 52.0400, 52.1500, 8728200, Finance::QuoteHist::Yahoo
2012/06/04, SBUX, Q, 52.0000, 53.9700, 51.4900, 53.9000, 12251400, Finance::QuoteHist::Yahoo
2012/06/05, SBUX, Q, 52.3500, 52.6800, 51.6300, 52.4100, 11168800, Finance::QuoteHist::Yahoo
[...]

# Import into Gnucash:
$ python imp_history.py test.gnucash sbux.csv
Adding[0]: SBUX, 2012-06-01 00:00:00, 52.15
Adding[1]: SBUX, 2012-06-04 00:00:00, 53.9
Adding[2]: SBUX, 2012-06-05 00:00:00, 52.41
[...]

And opening gnucash afterwards shows the prices have been 
added.  

Hope this helps...


More information about the gnucash-user mailing list