Created
July 16, 2016 16:12
-
-
Save jargnar/0b477d3b476930591e1f784ad8849e0e to your computer and use it in GitHub Desktop.
Querying a district_code to state_code lookup service
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 json | |
import requests | |
def get_state_for_district(district_code): | |
''' | |
Queries a hypothetical URL endpoint of the following form: | |
/lookup?level=district&parent=state&district=<district_code> | |
and retrieves a state_code for the given district_code | |
''' | |
params = {'level': 'district', 'parent': 'state', 'district': district_code} | |
res = requests.get('http://localhost:9500/lookup', params=params) | |
res = json.loads(res.text) | |
return res['state'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment