def get_district_id(state, district): cowin = CoWinAPI() states = cowin.get_states() state = [i for i in states["states"] if state in i["state_name"].lower()] districts = cowin.get_districts(state[0]["state_id"]) district = [ i for i in districts["districts"] if district in i["district_name"].lower() ] district_id = str(district[0]["district_id"]) return district_id
from cowin_api import CoWinAPI cowin = CoWinAPI() states = cowin.get_states() print(states) # get the state id from above add it here state_id = '12' cowin = CoWinAPI() districts = cowin.get_districts(state_id) print(districts)
def test_get_districts(): cowin = CoWinAPI() districts = cowin.get_districts("21") assert isinstance(districts, dict) assert districts.get('districts')[0].get('district_id') == 391