Archived
1
0

Modularize nearby_schools wrapper and pull data for Boston and Buffalo.

This commit is contained in:
Shaun Setlock
2022-04-09 14:55:44 -04:00
parent 557c7103b4
commit 6a6fa834f3
6 changed files with 2201 additions and 21 deletions

32
main/run.py Normal file → Executable file
View File

@@ -1,21 +1,27 @@
#!/usr/bin/env python3
from secret import get_key
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)
import numpy as np
import pandas as pd
# Get secret.
api_key_file = '../keys/api.key'
api_key = get_file_contents(api_key_file)
api_key = get_key(api_key_file)
# Grab data for Boston.
refresh = False
if refresh:
boston_nearby_schools_file = '../data/nearby_schools/boston.csv'
boston_schools = get_nearby_schools(api_key,"42.3","-71.2","50")
boston_df = pd.DataFrame.from_dict(boston_schools)
boston_df.to_csv(boston_nearby_schools_file)
get_nearby_schools(api_key)
# Grab data for Buffalo.
refresh = True
if refresh:
buffalo_nearby_schools_file = '../data/nearby_schools/buffalo.csv'
buffalo_schools = get_nearby_schools(api_key,"42.9625","-78.7425","50")
buffalo_df = pd.DataFrame.from_dict(buffalo_schools)
buffalo_df.to_csv(buffalo_nearby_schools_file)