Debian Codegraph @

examples/get-town-by-id.py

raw
1 """Get AEMET OpenData town data by ID 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_town_start = timeit.default_timer()
22 town = await client.get_town(town=AEMET_TOWN)
23 get_town_end = timeit.default_timer()
24 print(json_dumps(town))
25 print(f"Get Town time: {get_town_end - get_town_start}")
26 except AuthError:
27 print("API authentication error.")
28
29
30 if __name__ == "__main__":
31 asyncio.run(main())