Bob, your script worked great! thank you very much!

I've now a script that downloads a json file for each release of GnuCash in the 2.4 series with data from 2010-11-01 to 2012-11-30. It is like this:

for i in {0..11}; do wget "http://sourceforge.net/projects/gnucash/files/gnucash%20%28stable%29/2.4.$i/stats/json?start_date=2010-11-01&end_date=2012-11-30"; -O gnucash2.4.$i.json; done

I can then convert each json file to a csv file with your script so that I can copy-paste data in a single spreadsheet to generate the graph.

In order to make the process more automatic, would it be possible to create a csv file with only ["downloads"] data ordered as shown in the attached downloads.csv file?

Regards
Cristian

Il 02/12/2012 02:35, Bob Hossley ha scritto:
On 2012-11-30 13:16, Cristian Marchi wrote:
I would like to create some graphs about GnuCash downloads. I noticed
that sourceforge makes available the data for every file in json format
[1].
What I would like to do is to create a script that download all the
files for the GnuCash 2.4 releases (11 files as of now), reads the
downloads number associated to a month, and create a formatted file
(rows of downloads and date) to be imported in calc. I looked for a way
to do this but I had no luck. Can someone with a better experience with
json files give me a hint on how to do that?

Thanks for any help!

[1]
http://sourceforge.net/projects/gnucash/files/gnucash%20%28stable%29/2.4.11/stats/json?start_date=2010-11-01&end_date=2012-11-30

_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Cristian,

I'm not sure what information in what format you want, but the attached
will allow you to import ALL the information into LibreOffice Calc.

usage: stats01.py [options] jsonPath csvPath

GnuCash Stats for Cristian Marchi

positional arguments:
   jsonPath    Pathname of json file containing stats.
   csvPath     Pathname of csv file to create

optional arguments:
   -h, --help  show this help message and exit

I made the stats1-raw.json by looking at the stats page using Firefox,
Ctrl-A to select all the data.  Opening an editor and pasting all the
data, and then writing stats1-raw.json.

I made stats1-pretty.json with this script:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import codecs
import os
import json
import sys

fiPaName = sys.argv[1]
handle = codecs.open(fiPaName, 'r', encoding='utf-8')
oft = json.load(handle)
handle.close()
os.rename(fiPaName, fiPaName + '.bak')
handle = codecs.open(fiPaName, 'w', encoding='utf-8')
handle.write(json.dumps(oft, sort_keys=True, indent=4))
handle.close()

stats1-pretty.json is human readable using any editor.
stats01.py works on both "raw" and "pretty" json.

The Calc import default parameters work for stats1.csv. The columns are
comma delimited.

Note:  There is exactly one non-ASCII character in the statistics.
Dealing with this took most of my debug time.

I hope you find this helpful.

SegundoBob


"['downloads']",,"GnuCash 2.4.0","GnuCash 2.4.1","ecc..."
,"2010-11-01 00:00:00",0,0,
,"2010-12-01 00:00:00",0,0,
,"2011-01-01 00:00:00",0,0,
,"2011-02-01 00:00:00",0,0,
,"2011-03-01 00:00:00",0,0,
,"2011-04-01 00:00:00",0,0,
,"2011-05-01 00:00:00",0,0,
,"2011-06-01 00:00:00",0,0,
,"2011-07-01 00:00:00",0,0,
,"2011-08-01 00:00:00",0,0,
,"2011-09-01 00:00:00",0,0,
,"2011-10-01 00:00:00",0,0,
,"2011-11-01 00:00:00",0,0,
,"2011-12-01 00:00:00",0,0,
,"2012-01-01 00:00:00",504,0,
,"2012-02-01 00:00:00",49872,0,
,"2012-03-01 00:00:00",54499,0,
,"2012-04-01 00:00:00",56121,0,
,"2012-05-01 00:00:00",40694,0,
,"2012-06-01 00:00:00",38079,0,
,"2012-07-01 00:00:00",22475,27518,
,"2012-08-01 00:00:00",7802,53411,
,"2012-09-01 00:00:00",7901,45029,
,"2012-10-01 00:00:00",770,44544,
,"2012-11-01 00:00:00",676,46714,
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to