Import Json web data source to xls or csv

Cousin Stanley cousinstanley at gmail.com
Wed Feb 20 01:59:46 EST 2013


io wrote:

> ....
> How do i manage to read the data source 
> from http://bitcoincharts.com/t/markets.json
> ....
> I just need currency, symbol, bid, ask, volume
> ....

  Following is a simple way load the json data
  and write the desired fields to a  .csv  file


import json
import urllib

url        = "http://bitcoincharts.com/t/markets.json"

response   = urllib.urlopen( url ) ;

data       = json.loads( response.read() )

list_dicts = [ dict( this ) for this in data ]

f          = open( 'markets.csv' , 'w' ) 

for this_dict in list_dicts :

    currency  = str( this_dict[ 'currency'] )
    symbol    = str( this_dict[ 'symbol' ] )
    bid       = str( this_dict[ 'bid' ] )
    ask       = str( this_dict[ 'ask' ] )
    volume    = str( this_dict[ 'volume' ] )

    this_list = [ currency , symbol , bid , ask , volume ]

    this_str  = ','.join( this_list )

    f.write( this_str + '\n' )

f.close()
  

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona




More information about the Python-list mailing list