From 557c7103b49701d7efdda921912a1c7af654d9a9 Mon Sep 17 00:00:00 2001 From: Shaun Setlock Date: Sun, 3 Apr 2022 16:53:43 -0400 Subject: [PATCH] Complete wrapper and collator for nearby_schools API call. --- main/great_schools.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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