M3Works / metloom

Location Oriented Observed Meteorology
Other
16 stars 4 forks source link

Mesowest Point Data throws exception when no station is found #39

Closed micahjohnson150 closed 2 years ago

micahjohnson150 commented 2 years ago

Description

Attempting to pull a mesowest station and I misspelled the station id. This results in 'STATION is not in the response data and thus throws an exception.

What I Did

from metloom.pointdata import MesowestPointData
from dateparser import parse

pnt = pnt = MesowestPointData('NOT_REAL_CODE', 'test')
pnt.get_daily_data(parse('2 days ago'), parse('today'), [pnt.ALLOWED_VARIABLES.TEMP])

This throws

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/micah/projects/m3works/metloom/metloom/pointdata/mesowest.py", line 280, in get_daily_data
    df = self._get_data(start_date, end_date, variables, interval='D')
  File "/home/micah/projects/m3works/metloom/metloom/pointdata/mesowest.py", line 119, in _get_data
    sensor_df = self._sensor_response_to_df(
  File "/home/micah/projects/m3works/metloom/metloom/pointdata/mesowest.py", line 183, in _sensor_response_to_df
    station_response = response_data['STATION']
KeyError: 'STATION'

Note the response data is:

{'SUMMARY': {'NUMBER_OF_OBJECTS': 0, 'RESPONSE_CODE': 2, 'VERSION': 'v2.13.8', 'RESPONSE_MESSAGE': 'No stations found for this request.', 'RESPONSE_TIME': 0}}