diff --git a/.gitignore b/.gitignore index 1e77772..37646ac 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ Thumbs.db .python-version # for API keys -**/config.py +**/.env diff --git a/requirements.txt b/requirements.txt index 330e724..56e8ecb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ mock==4.0.3 plotly==4.14.3 dash_bootstrap_components==0.11.3 scikit_learn==0.24.1 +python-dotenv diff --git a/routemodel/data_retrieval/common.py b/routemodel/data_retrieval/common.py index 4e875b2..502e72d 100644 --- a/routemodel/data_retrieval/common.py +++ b/routemodel/data_retrieval/common.py @@ -1,10 +1,13 @@ import requests import sys import os.path +from dotenv import load_dotenv sys.path.append(os.path.dirname(__file__)) -from config import BASE_URL, API_KEY +load_dotenv() +BING_API_KEY = os.environ.get("BING_API_KEY") +BASE_URL = 'https://dev.virtualearth.net/REST/v1/' # common getter for all files def get_API_data(query: str): @@ -13,7 +16,7 @@ def get_API_data(query: str): #return: a JSON response from API """ url = BASE_URL + query - url += '&key={}'.format(API_KEY) + url += '&key={}'.format(BING_API_KEY) # get and return response try: response = requests.get(url) diff --git a/routemodel/data_retrieval/config_example.py b/routemodel/data_retrieval/config_example.py deleted file mode 100644 index 8a846de..0000000 --- a/routemodel/data_retrieval/config_example.py +++ /dev/null @@ -1,7 +0,0 @@ -# Instructions: Create "config.py" file in this folder -# Add API_KEY as shown -# Add BASE_URL as shown -# elevations.py, routes.py, and speedlimits.py should be passing pytest once -# done! Make sure config.py is never being pushed up. -API_KEY = '' -BASE_URL = 'https://dev.virtualearth.net/REST/v1/' \ No newline at end of file diff --git a/routemodel/data_retrieval/get_weather.py b/routemodel/data_retrieval/get_weather.py index 92a286e..65d77e6 100755 --- a/routemodel/data_retrieval/get_weather.py +++ b/routemodel/data_retrieval/get_weather.py @@ -4,8 +4,11 @@ import requests import csv import json +from dotenv import load_dotenv + +load_dotenv() +WEATHER_API_KEY = os.environ.get("WEATHER_API_KEY") -from config import WEATHER_API_KEY ONE_CALL_BASE = 'https://api.openweathermap.org/data/2.5/onecall?' PATH = os.path.join(os.path.dirname(__file__), '..', 'routes\ASC2021\ASC2021_draft.csv')