Skip to content

Instantly share code, notes, and snippets.

@kimsterv
Created August 11, 2011 16:55
Show Gist options
  • Save kimsterv/1140170 to your computer and use it in GitHub Desktop.
Save kimsterv/1140170 to your computer and use it in GitHub Desktop.
Split out lat/lon
import simplejson as json
import sys
import re
load = open('/dev/stdin', 'r')
buf = ''
for line in load:
buf += line
if line.strip().endswith('}'):
try:
place = json.loads(buf)
for key in place.keys():
if key.startswith('kv_'):
place[key[3:]] = place[key]
del place[key]
try:
(lat, lon) = place['location'].split(',')
place['latitude'] = float(lat)
place['longitude'] = float(lon)
del place['location']
except Exception, e:
pass
print json.dumps(place)
except Exception, e:
pass
buf = ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment