Edit prices for multiple gnucash files

spotty albino jehelsby at iinet.net.au
Sat Sep 28 08:01:03 EDT 2013


Stuart McGraw wrote
> 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
> 
> * 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...
> _______________________________________________
> gnucash-user mailing list

> gnucash-user@

> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> -----

Hello Stuart McGraw and GnuCash community

I'd like to revive an old discussion. I have been unable to work on this
project for some time due to illness and study commitments. I've followed
your instructions and hit a snag. Could you offer advice? 

Firstly, I'm running GnuCash on Ubuntu 12.04LTS. I've installed the python
bindings via the Ubuntu Software Centre. I no longer encounter the error
most recently referred to in this discussion (which appeared on an OSX
system). 

I'm trying to import a price test file (sbux.csv) into test.gnucash using
your imp_history.py script. I'm not using Finance Quote or Perl to retrieve
data since ultimately I will be dealing with unlisted securities. Instead
I'm writing my own .csv files.
File sbux.csv has the form;

SBUX,2012/06/01,53.11,54.06,83.25,52.04,8728200

… and so on as shown at http://wiki.gnucash.org/wiki/Stocks/get_prices

In Terminal I navigate to the directory containing the aforementioned files
and scripts, then execute;

$ python imp_history.py test.gnucash sbux.csv

which generates the following error;

Traceback (most recent call last): 
  File "imp_history.py", line 81, in <module> 
    if __name__ == '__main__': main (sys.argv[1:]) 
  File "imp_history.py", line 11, in main 
    price_data = read_price_data (args[1]) 
  File "imp_history.py", line 19, in read_price_data 
    [x.strip() for x in line.split(',')] 
ValueError: need more than 7 values to unpack 

Under different circumstances (modifying the form of sbux.csv) the error 'No
prices for SBUX, need at least one' was generated. File test.gnucash has a
security named SBUX and one price associated in the price editor.

Can you shed some light on the error? I've modified a number of variables
and repeated without success.

Additionally, I aim to run a single price.csv file (containing prices for
multiple securities) against 100+ client.gnucash files with different
portfolios.  Would im_history.py fail to run where it contained a security
for which there was no equivalent in client.gnucash? If so, would it be
possible to write a script which could do this?

Thank you for any assistance you can offer

Regards
Josh 





--
View this message in context: http://gnucash.1415818.n4.nabble.com/Edit-prices-for-multiple-gnucash-files-tp4656941p4664305.html
Sent from the GnuCash - User mailing list archive at Nabble.com.



More information about the gnucash-user mailing list