Read csv file and create a new file
io
maroso at libero.it
Thu Feb 28 14:51:15 EST 2013
I'm a noob in python but my code looks like this :
import json
import urllib
import csv
url = "http://bitcoincharts.com/t/markets.json"
response = urllib.urlopen(url);
data = json.loads(response.read())
f = open("/home/io/markets.csv","wb")
c = csv.writer(f)
#apre un file di testo e legge il contenuto del file inserendolo in una
stringa
esclusioni = open('/home/io/exclusions.txt','r')
string = ""
while 1:
line = esclusioni.readline()
if not line:break
string += line
print string
# write headers
c.writerow(["Currency","Symbol","Bid", "Ask", "Volume"])
for d in data :
if d["currency"] <> "SLL": #esclude la valuta di secondlife SLL
if d["bid"] is not None and d["ask"] is not None:
if not any(str(d["symbol"]) in s for s in string):
c.writerow([str(d["currency"]),str(d["symbol"]),str(d
["bid"]),str(d["ask"]),str(d["currency_volume"])])
esclusioni.close()
More information about the Python-list
mailing list