Last active
March 13, 2019 12:22
-
-
Save stephenkeable-allies/a6451121b19047be36ad to your computer and use it in GitHub Desktop.
Example code for using Postcoder Web in Python. For more information on Postcoder Web visit http://www.alliescomputing.com/products/postcoder-web-api
This file contains 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
# PostCoder Web Service V3 example | |
# Allies Computing Ltd 2014 | |
# | |
# This demo shows how to perform an address lookup in Python. | |
# | |
import json | |
import urllib | |
searchkey = 'PCW45-12345-12345-1234X'; # Test search key, replace with your | |
searchterm = 'NR14 7PZ'; # string to use for an address search | |
print ("PostCoder Web V3 Python Client Snippet\n\n") | |
url = 'http://ws.postcoder.com/pcw/' + searchkey + '/address/UK/' | |
# for other uri options see https://developers.alliescomputing.com/postcoder-web-api/address-lookup/premise | |
try: | |
# For Python 3.0 and later | |
from urllib.request import urlopen | |
url = url + urllib.parse.quote(searchterm) | |
response = urlopen(url).readall().decode('utf-8') | |
except ImportError: | |
# Fall back to Python 2 | |
from urllib import urlopen | |
url = url + urllib.quote(searchterm) | |
response = urlopen(url).read() | |
structure = json.loads(response) | |
print(json.dumps(structure, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment