Beispiel #1
0
def test_error_handling():
    with pytest.raises(ValueError):
        coops.get_data(
            begin_date="20150101",
            end_date="20150331",
            stationid="9442396",
            product="water_level",
            datum="navd88", # this is an invalid datum
            units="metric",
            time_zone="gmt")
Beispiel #2
0
    def update(self):
        """Get the latest data from NOAA Tides and Currents API."""
        from py_noaa import coops  # pylint: disable=import-error

        begin = datetime.now()
        delta = timedelta(days=2)
        end = begin + delta
        try:
            df_predictions = coops.get_data(
                begin_date=begin.strftime("%Y%m%d %H:%M"),
                end_date=end.strftime("%Y%m%d %H:%M"),
                stationid=self._station_id,
                product="predictions",
                datum="MLLW",
                interval="hilo",
                units=self._unit_system,
                time_zone=self._timezone,
            )
            self.data = df_predictions.head()
            _LOGGER.debug("Data = %s", self.data)
            _LOGGER.debug(
                "Recent Tide data queried with start time set to %s",
                begin.strftime("%m-%d-%Y %H:%M"),
            )
        except ValueError as err:
            _LOGGER.error("Check NOAA Tides and Currents: %s", err.args)
            self.data = None