Beginning to build the great schools API wrapper.
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
21
main/great_schools.py
Normal file
21
main/great_schools.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# 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",
|
||||||
|
'page': "45"
|
||||||
|
}
|
||||||
|
headers = {
|
||||||
|
"x-api-key": key
|
||||||
|
}
|
||||||
|
r = requests.get(url=url, params=params, headers=headers)
|
||||||
|
print(r.text)
|
||||||
|
return
|
||||||
21
main/run.py
Normal file
21
main/run.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from great_schools import get_nearby_schools
|
||||||
|
|
||||||
|
def get_file_contents(filename):
|
||||||
|
""" Given a filename,
|
||||||
|
return the contents of that file
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
# It's assumed our file contains a single line,
|
||||||
|
# with our API key
|
||||||
|
return f.read().strip()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("'%s' file not found" % filename)
|
||||||
|
|
||||||
|
api_key_file = '../keys/api.key'
|
||||||
|
api_key = get_file_contents(api_key_file)
|
||||||
|
|
||||||
|
|
||||||
|
get_nearby_schools(api_key)
|
||||||
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
certifi==2021.10.8
|
||||||
|
charset-normalizer==2.0.12
|
||||||
|
idna==3.3
|
||||||
|
requests==2.27.1
|
||||||
|
urllib3==1.26.9
|
||||||
Reference in New Issue
Block a user