-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_endpoints.py
42 lines (33 loc) · 1.21 KB
/
get_endpoints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import json
from dotenv import load_dotenv
import utils as utils
import logging
def get_endpoints():
'''Get endpoints from NOAA API, cache endpoints in a blob'''
# Load environment variables
load_dotenv()
locations = json.loads(os.getenv("LOCATIONS"))
PURPOSE = os.getenv("PURPOSE")
EMAIL = os.getenv("EMAIL")
# API url for location metadata, header for requests
metadata_url = 'https://api.weather.gov/points/'
header = {'User-Agent' : (f'{PURPOSE}, {EMAIL}')}
# Forecast type:
forecast_type = 'forecastGridData'
# Paths and filenames
container_name = 'skiforcast'
blob_name = 'noaa_api_endpoints.json'
# Get endpoints
try:
cache = utils.APIEndpoints(locations, metadata_url, header, forecast_type, container_name, blob_name)
endpoints = cache.get_endpoints()
# Handle missed endpoints
if len(endpoints) != len(locations):
for key in (locations.keys() - endpoints.keys()):
if key in locations.keys():
del locations[key]
except Exception as e:
logging.info(f'\n\nError in get_endpoints: \n{e}\n\n')
endpoints = None
return endpoints