Skip to content

Commit

Permalink
FIX: Catching connection errors in case COSMOS site is down.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpu-creare committed Dec 10, 2020
1 parent f0217de commit 13174ff
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions podpac/datalib/cosmos_stations.py
Expand Up @@ -5,7 +5,6 @@
import re
import numpy as np
from dateutil import parser
import requests
import json
import logging

Expand Down Expand Up @@ -58,7 +57,11 @@ class COSMOSStation(podpac.data.DataSource):
def raw_data(self):
_logger.info("Downloading station data from {}".format(self.station_data_url))

r = requests.get(self.station_data_url)
r = _get_from_url(self.station_data_url)
if r is None:
raise ConnectionError(
"COSMOS data cannot be retrieved. Is the site {} down?".format(self.station_calibration_url)
)
return r.text

@cached_property
Expand Down Expand Up @@ -121,13 +124,22 @@ def location(self):

@cached_property(use_cache_ctrl=True)
def calibration_data(self):
cd = _get_from_url(self.station_calibration_url).json()
cd = _get_from_url(self.station_calibration_url)
if cd is None:
raise ConnectionError(
"COSMOS data cannot be retrieved. Is the site {} down?".format(self.station_calibration_url)
)
cd = cd.json()
cd["items"] = [_convert_str_to_vals(i) for i in cd["items"]]
return cd

@cached_property(use_cache_ctrl=True)
def site_properties(self):
r = _get_from_url(self.station_properties_url)
if r is None:
raise ConnectionError(
"COSMOS data cannot be retrieved. Is the site {} down?".format(self.station_properties_url)
)
soup = bs4.BeautifulSoup(r.text, "lxml")
regex = re.compile("Soil Organic Carbon")
loc = soup.body.findAll(text=regex)[0].parent.parent
Expand All @@ -154,6 +166,9 @@ def _interpolation_default(self):
def _stations_data_raw(self):
url = self.url + self.stations_url
r = _get_from_url(url)
if r is None:
raise ConnectionError("COSMOS data cannot be retrieved. Is the site {} down?".format(url))

t = r.text

# Fix the JSON
Expand Down

0 comments on commit 13174ff

Please sign in to comment.