Skip to content

Instantly share code, notes, and snippets.

@jargnar
Created July 16, 2016 16:12
Show Gist options
  • Save jargnar/0b477d3b476930591e1f784ad8849e0e to your computer and use it in GitHub Desktop.
Save jargnar/0b477d3b476930591e1f784ad8849e0e to your computer and use it in GitHub Desktop.
Querying a district_code to state_code lookup service
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