Skip to content

Instantly share code, notes, and snippets.

@mager
Created July 12, 2011 01:54
Show Gist options
  • Save mager/1077242 to your computer and use it in GitHub Desktop.
Save mager/1077242 to your computer and use it in GitHub Desktop.
Parse plancast firehose and import to SimpleGeo Storage
import json, requests, simplegeo
from simplegeo.models import Record
client = simplegeo.Client('your-key', 'your-secret')
firehose = 'http://api.plancast.com/02/plans/firehose.json?extensions=place'
resp = requests.get(url=firehose)
data = json.load(resp)
plans = data['plans']
for plan in plans:
if plan['place']:
record = {}
record['lat'] = plan['place']['latitude']
record['lon'] = plan['place']['longitude']
record['id'] = plan['plan_id']
record['created'] = plan['plan_created_at']
record['layer'] = 'co.mager.test'
del plan['place']['latitude']
del plan['place']['longitude']
del plan['plan_id']
del plan['plan_created_at']
for k,v in plan.items():
record[k] = plan[k]
print record['id']
record = Record(**record)
client.add_record(record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment