Skip to content

Commit

Permalink
feature: Add warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Dec 26, 2024
1 parent f4f3cf4 commit 81818b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
LAT, LON = 37.1460511137383, -8.541564345359804 #Portimao

#LAT, LON = 39.663396, -8.813334 Leiria
#LAT, LON = 41.221894, -8.541423
LAT, LON = 41.221894, -8.541423

import logging
logging.basicConfig()
Expand All @@ -33,5 +33,9 @@ async def main():
sea_forecasts = await location.sea_forecast(api)
print("Sea forecast for today {}".format(sea_forecasts[0]))

warnings = await location.warnings(api)

print("Warnings for the area: ", warnings)


asyncio.run(main())
28 changes: 28 additions & 0 deletions pyipma/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .sea_forecast import SeaForecasts
from .rcm import RCM_day
from .uv import UV_risks
from .warnings import Warnings

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

Expand Down Expand Up @@ -197,3 +198,30 @@ async def uv_risk(self, api):
)

return None

async def warnings(self, api):
"""Retrieve Warnings for the current location."""

warnings = Warnings(api)

try:
districts = await self.get_districts(api)
area_id = districts[0].idAreaAviso

if area_id:
r = await warnings.get(area_id)
import pprint
pprint.pprint(r)
return r

except Exception as err:
LOGGER.warning(
"Could not retrieve Warnings for %s: %s",
area_id,
err,
)

return None



0 comments on commit 81818b1

Please sign in to comment.