#!/usr/bin/env python3 import requests import json # Helper file to facilitate calls to the greatschools.org API # Endpoint: nearby-schools def get_nearby_schools(key: str): url = 'https://gs-api.greatschools.org/nearby-schools' params = { 'lat': "42.3", 'lon': "-71.2", 'school_type': "public", 'distance': "50", } headers = { "x-api-key": key } # Construct loop to collate pages schools = {} count = 0 request_limit = 50 non_empty = True while count <= request_limit and non_empty: params['page'] = str(count) r = requests.get(url=url, params=params, headers=headers).json() print(r) if len(r['schools']) == 0: non_empty = False else: schools.update(r) count = count + 1 return r