Skip to content

Commit

Permalink
valid station with null data
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Sep 22, 2022
1 parent 63147d5 commit 294e7f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyipma/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Python library for http://api.ipma.pt."""
__version__ = "3.0.4"
__version__ = "3.0.5"

class IPMAException(Exception):
pass
Expand Down
9 changes: 5 additions & 4 deletions pyipma/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

LOGGER = logging.getLogger(__name__) # pylint: disable=invalid-name


class Location:
"""Represents a Location (district)."""

Expand Down Expand Up @@ -125,14 +124,16 @@ async def observation(self, api):
observations = []
for station in self.observation_stations[:10]:
try:
LOGGER.debug("Get Observation for %s", station.idEstacao)
observations = await obs.get(station.idEstacao)
break
if len(observations) and observations[0] is not None:
return observations[0]
except Exception as err:
LOGGER.warning(
"Could not retrieve obsertation for %s: %s", station, err
)

return observations[0] if len(observations) else None
LOGGER.error("Could not retrieve a valid observation for %s", self.name)
return None

async def sea_forecast(self, api):
"""Retrieve today's sea forecast for closest sea location."""
Expand Down

0 comments on commit 294e7f8

Please sign in to comment.