Created
July 12, 2011 01:54
-
-
Save mager/1077242 to your computer and use it in GitHub Desktop.
Parse plancast firehose and import to SimpleGeo Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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