Skip to content

Instantly share code, notes, and snippets.

@donlovett
Created September 25, 2016 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donlovett/dd85ea10de428986aee19ecb86d58df1 to your computer and use it in GitHub Desktop.
Save donlovett/dd85ea10de428986aee19ecb86d58df1 to your computer and use it in GitHub Desktop.
Final Assignment Week 6 Geojson
import urllib
import json
serviceurl = 'http://python-data.dr-chuck.net/geojson?'
while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break
url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
print 'Retrieving', url
uh = urllib.urlopen(url)
data = uh.read()
print 'Retrieved',len(data),'characters'
try: js = json.loads(str(data))
except: js = None
if 'status' not in js or js['status'] != 'OK':
print '==== Failure To Retrieve ===='
print data
continue
#print json.dumps(js, indent=4)
faddress = js["results"][0]["formatted_address"]
placeid = js["results"][0]["place_id"]
print 'Formatted Address: ',faddress,'Place ID: ',placeid
location = js['results'][0]['formatted_address']
print location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment