Edit prices for multiple gnucash files

smcg4191 at frii.com smcg4191 at frii.com
Sun Sep 29 20:21:07 EDT 2013


On 09/28/2013 06:01 AM, spotty albino wrote:
> Stuart McGraw wrote
[...]
>> # 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.  
> 
> 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

This has 7 fields in the order: 
 symbol, date, price, price, price, price, volume

But looking at the Starbucks example above there are 9 fields:
 date, symbol, Q (for quote), price, price, price, price, volume, source

So I would say that the first thing is to generate your
CSV file with 9 fields in the given order.  I don't remember 
off hand the order of the price values, (low, high, close, etc).
'source' is an arbitrary string that I don't think either
imp_history.py or gnucash uses for anything other than display.

> … 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 

Without going back to look at the code, this looks like a 
symptom consistent with having the wrong number of fields
in the input CSV file.

> 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 



More information about the gnucash-user mailing list