-
Notifications
You must be signed in to change notification settings - Fork 0
/
py4e_1402.py
44 lines (36 loc) · 1.08 KB
/
py4e_1402.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import urllib.request, urllib.parse
import json, ssl
# Heavily rate limited proxy of https://www.geoapify.com/ api
serviceurl = 'https://py4e-data.dr-chuck.net/opengeo?'
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
n=1
while n<=1:
address = input('Enter location: ')
if len(address) < 1: break
address = address.strip()
parms = dict()
parms['q'] = address
url = serviceurl + urllib.parse.urlencode(parms)
print('Retrieving', url)
uh = urllib.request.urlopen(url, context=ctx)
data = uh.read().decode()
print('Retrieved', len(data), 'characters', data[:20].replace('\n', ' '))
try:
js = json.loads(data)
except:
js = None
if not js or 'features' not in js:
print('==== Download error ===')
print(data)
break
if len(js['features']) == 0:
print('==== Object not found ====')
print(data)
break
#print (js)
plus_code=js['features'][0]['properties']['plus_code']
print (plus_code)
n+=1