-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.py
47 lines (31 loc) · 1.47 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import asyncio
import pprint
import aiohttp
from pyipma.api import IPMA_API
from pyipma.location import Location
LAT, LON = 37.1460511137383, -8.541564345359804 #Portimao
#LAT, LON = 39.663396, -8.813334 Leiria
LAT, LON = 41.221894, -8.541423
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
async def main():
async with aiohttp.ClientSession() as session:
api = IPMA_API(session)
location = await Location.get(api, LAT, LON, sea_stations=True)
print("Forecast for {}".format(location.name))
print("Nearest station is {}".format(location.station))
print("Nearest sea station is {}".format(location.sea_station_name))
obs = await location.observation(api)
print("Current Weather based on observation: {}".format(obs))
forecasts = await location.forecast(api, 1)
print("Current Weather based on forecast data for the next hour: {}".format(forecasts[0]))
print("UTCI if available: ", forecasts[0].utci)
forecasts = await location.forecast(api, 24)
print("Current Weather based on forecast data for the next days: {}".format(forecasts[0]))
print("UTCI if available: ", forecasts[0].utci)
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())