13.7 - Using Application Programming Interfaces
13.7 - Using Application Programming Interfaces
APIs
http://en.wikipedia.org/wiki/Web_services
PYTHON FOR
Web Services – Part 7 EVERYBODY
https://www.geoapify.com/
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
An API Proxy
• To avoid making you get an account, I have a well-hidden
web server that acts as a proxy for the Geoapify data
• This proxy does not require a password – but it does have
rate limits and is heavily cached using an edge-caching
service for performance
{ http://py4e-data.dr-chuck.net/opengeo?q=Ann+Arbor%2C+MI
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"datasource": {
"sourcename": "openstreetmap",
"attribution": "© OpenStreetMap contributors",
"license": "Open Database License",
"url": "https://www.openstreetmap.org/copyright"
},
"country": "United States",
Note, for this course, we
"country_code": "us",
operate through a proxy of the
"state": "Michigan",
geoapi data to avoid rate
"county": "Washtenaw County",
limitation and authentication.
"city": "Ann Arbor",
"lon": -83.7312291,
"lat": 42.2681569,
"state_code": "MI", opengeo.py
"result_type": "city",
"formatted": "Ann Arbor, MI, United States of America",
PYTHON FOR
Web Services – Part 7 EVERYBODY
serviceurl = 'https://py4e-data.dr-chuck.net/opengeo?'
Enter location: Ann Arbor, MI
while True: Retrieving https://py4e-data.
address = input('Enter location: ')
if len(address) < 1: break
dr-chuck.net/opengeo?q=Ann+Arbor%2C+MI
Retrieved 1319 characters {"type":"FeatureColl
address = address.strip() lat 42.2681569 lon -83.7312291
parms = dict()
parms['q'] = address Ann Arbor, MI, United States of America
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', ' '))
js = json.loads(data)
lat = js['features'][0]['properties']['lat']
lon = js['features'][0]['properties']['lon'] opengeo.py
print('lat', lat, 'lon', lon)
location = js['features'][0]['properties']['formatted']
print(location)
PYTHON FOR
Web Services – Part 7 EVERYBODY
Summary
• Service Oriented Architecture - allows an application to be
broken into parts and distributed across a network
Acknowledgements / Contributions
These slides are Copyright 2010- Charles R. Severance
...
(www.dr-chuck.com) of the University of Michigan School of
Information and open.umich.edu and made available under a
Creative Commons Attribution 4.0 License. Please maintain this
last slide in all copies of the document to comply with the
attribution requirements of the license. If you make a change,
feel free to add your name and organization to the list of
contributors on this page as you republish the materials.