Python wrapper for IMGW-PIB API.
Project description
imgw-pib
Python async wrapper for IMGW-PIB API.
Installation
You can install the library with pip:
pip install imgw-pib
How to use the library
"""Example of usage IMGW-PIB."""
import asyncio
import logging
from aiohttp import ClientError, ClientSession
from imgw_pib import ApiError, ImgwPib
logging.basicConfig(level=logging.DEBUG)
WEATHER_STATION_ID = "12200"
HYDROLOGICAL_STATION_ID = "154190050"
async def main() -> None:
"""Run main function."""
async with ClientSession() as websession:
try:
imgwpib = await ImgwPib.create(
websession,
weather_station_id=WEATHER_STATION_ID,
hydrological_station_id=HYDROLOGICAL_STATION_ID,
)
weather_data = await imgwpib.get_weather_data()
hydrological_data = await imgwpib.get_hydrological_data()
except ApiError as error:
print(f"API Error: {error.status}")
except ClientError as error:
print(f"ClientError: {error}")
except TimeoutError as error:
print(f"TimeoutError: {error}")
else:
print(f"Weather stations: {imgwpib.weather_stations}")
print(f"Weather data: {weather_data}")
print(f"Hydrological stations: {imgwpib.hydrological_stations}")
print(f"Hydrological data: {hydrological_data}")
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()
Error handling
The library raises ApiError
when the IMGW-PIB API returns an error, ClientError
for network-related errors, and TimeoutError
when a request times out.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
imgw_pib-1.0.2.tar.gz
(12.0 kB
view details)
Built Distribution
imgw_pib-1.0.2-py3-none-any.whl
(10.9 kB
view details)
File details
Details for the file imgw_pib-1.0.2.tar.gz
.
File metadata
- Download URL: imgw_pib-1.0.2.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8847b749eb030d5c33d7e1604def3663dc74a2edf2aa558d8ca77ecda08a519 |
|
MD5 | e6061bbaf752fc1539cda16b9536460b |
|
BLAKE2b-256 | 65f94adb3236286d0f9450ca1d26c70bec75c9a570cbe59da02aecf61d62739e |
File details
Details for the file imgw_pib-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: imgw_pib-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd82fc5fc2442b524c452ea7027bb94be0edce25816ab59e770f2a4d87824dcf |
|
MD5 | d2719843e98eced0cce41671e2d681bd |
|
BLAKE2b-256 | 08db75903714705a09726a005cbc8004053d1e3e6954382aff77d39598ccf468 |