Archived
1
0

Complete wrapper and collator for nearby_schools API call.

This commit is contained in:
Shaun Setlock
2022-04-03 16:53:43 -04:00
parent cf45b88823
commit 557c7103b4

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import requests
import json
# Helper file to facilitate calls to the greatschools.org API
@@ -11,11 +12,23 @@ def get_nearby_schools(key: str):
'lon': "-71.2",
'school_type': "public",
'distance': "50",
'page': "45"
}
headers = {
"x-api-key": key
}
r = requests.get(url=url, params=params, headers=headers)
print(r.text)
return
# 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