diff --git a/main/great_schools.py b/main/great_schools.py index 0553187..64af012 100644 --- a/main/great_schools.py +++ b/main/great_schools.py @@ -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 \ No newline at end of file + + # 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 \ No newline at end of file