File size: 1,104 Bytes
3ea44ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #!/usr/bin/env python
#Convert json array file in csv file
#import
import ijson
import csv
import time
import sys
import os
import datetime
os.chdir('/home/julien_ha/data')
#Start timer
start_time = time.time()
input_file = sys.argv[1]
output_file = input_file.replace('.json','.csv')
#Parse json file
f1 = open(input_file)
d1 = []
for item in ijson.items(f1, "item"):
d1.append(item)
f = csv.writer(open(output_file, "wb+"))
# Write CSV Header, If you dont need that, remove this line
f.writerow(["blockHash","blockNumber","from","gas","gasPrice","hash","input","nonce","timestamp","to","transactionIndex","value"])
for t in d1:
f.writerow([t["blockHash"],
t["blockNumber"],
t["from"],
t["gas"],
t["gasPrice"],
t["hash"],
t["input"],
t["nonce"],
t["timestamp"],
t["to"],
t["transactionIndex"],
t["value"]
])
#Print time duration
print("Done in --- %s seconds ---" % (time.time() - start_time)) |