Created
November 7, 2015 14:58
-
-
Save hitecherik/5e5cc1778fb906cdcae6 to your computer and use it in GitHub Desktop.
Retrieve a UK postcode and return a constituency.
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
import urllib.request | |
import json | |
postcode = input("Please enter your postcode: ") | |
url = "http://uk-postcodes.com/postcode/" + postcode + ".json" | |
request = urllib.request.Request(url, headers={"User-Agent": "I'm not a bot"}) | |
content = urllib.request.urlopen(request).read().decode() | |
results = json.loads(content) | |
print(results["administrative"]["constituency"]["title"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment