Debian Codegraph @

examples/get-town-forecast-hourly.py

raw
1 """Get AEMET OpenData town hourly forecast example."""
2
3 import asyncio
4 import timeit
5
6 from _common import json_dumps
7 from _secrets import AEMET_OPTIONS, AEMET_TOWN
8 import aiohttp
9
10 from aemet_opendata.exceptions import AuthError
11 from aemet_opendata.interface import AEMET
12
13
14 async def main():
15 """AEMET OpenData client example."""
16
17 async with aiohttp.ClientSession() as aiohttp_session:
18 client = AEMET(aiohttp_session, AEMET_OPTIONS)
19
20 try:
21 get_forecast_start = timeit.default_timer()
22 forecast = await client.get_specific_forecast_town_hourly(AEMET_TOWN)
23 get_forecast_end = timeit.default_timer()
24 print(json_dumps(forecast))
25 print(f"Get forecast time: {get_forecast_end - get_forecast_start}")
26 except AuthError:
27 print("API authentication error.")
28
29
30 if __name__ == "__main__":
31 asyncio.run(main())