Archived
1
0
This repository has been archived on 2025-04-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
schools/main/great_schools.py

34 lines
849 B
Python

#!/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