Skip to content

Instantly share code, notes, and snippets.

@psychemedia
Created March 21, 2010 10:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save psychemedia/339219 to your computer and use it in GitHub Desktop.
Save psychemedia/339219 to your computer and use it in GitHub Desktop.
import simplejson
import csv
import os
f2=open(f2name,"wb+")
csv_file = csv.writer(f2)
csv_file.writerow([ "file",'timestamp','NGPSLatitude','NGPSLongitude', 'NGear','nEngine','rThrottlePedal','pBrakeF','gLat','gLong','sLap','vCar' ])
##data is in files named numerically
for i in range(1268569874,1268574286):
f=PATH+`i`
if os.path.isfile(f):
f=open(f)
f.seek(0)
txt=f.read()
f.close()
## tidy the data so we just get a JSON blob
txt=txt.replace('Dashboard.jsonCallback(\'','')
txt=txt.replace('\\','')
txt=txt.replace('\');','')
##parse the json into a Python data structure
data=simplejson.loads(txt)
##parse the data at a more meanigful level and create a CSV output
if 'drivers' in data:
if 'HAM' in data['drivers']:
if 'telemetry' in data['drivers']['HAM']:
d=data['drivers']['HAM']['telemetry']
csv_file.writerow([ i,d['timestamp'],d['NGPSLatitude'],d['NGPSLongitude'], d['NGear'],d['nEngine'],d['rThrottlePedal'],d['pBrakeF'],d['gLat'],d['gLong'],d['sLap'],d['vCar'] ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment