Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
script used to feed cartodb with the redbull stratos mission info
import time
import urllib2
import json
from cartodb import CartoDBAPIKey, CartoDBException
from secret import API_KEY
URL = ''
cl = CartoDBAPIKey(API_KEY, 'javi')
positions = {}
while True:
data = json.loads(urllib2.urlopen(URL).read())
telemetry = data['Telemetry']
if telemetry:
telemetry.sort(lambda x, y: x['Id'] - y['Id'])
for t in telemetry:
if t['Id'] not in positions:
positions[t['Id']] = t
t['the_geom'] = "ST_GeomFromText('POINT(%s %s)', 4326)" % (t['Longitude'], t['Latitude'])
del t['Latitude']
del t['Longitude']
del t['CompassDirection']
cl.sql("insert into stratos (%s) values (%s)" % (
','.join(map(str, t.keys())),
','.join(map(str, t.values()))
except Exception,e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment