Created
August 11, 2011 16:55
-
-
Save kimsterv/1140170 to your computer and use it in GitHub Desktop.
Split out lat/lon
This file contains hidden or 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 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