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 package
"""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.0.tar.gz
(11.7 kB
view details)
Built Distribution
imgw_pib-1.0.0-py3-none-any.whl
(10.9 kB
view details)
File details
Details for the file imgw_pib-1.0.0.tar.gz
.
File metadata
- Download URL: imgw_pib-1.0.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b7db359b10716347207f187b2e55a8ca2e60b980b1cf6b830199a242e33021c |
|
MD5 | 0a6804c0e541695b791948acacd2ac9b |
|
BLAKE2b-256 | eea274a81afd75cdf1ba9e4c07a1038898cc6140e9099ca0a7727c209809e5b7 |
File details
Details for the file imgw_pib-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: imgw_pib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb59d50b85270a5eb21a8feb210eeacd00e55b943ced13da9bc5256e8731a1b3 |
|
MD5 | 035c2c91d3f68e2bdf466d90f6cd7f80 |
|
BLAKE2b-256 | 2279ae5c7112779169f6989f640a09117672b5403f8c083c0a2cbe7f6dcadc6c |