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.4.tar.gz
(12.3 kB
view details)
Built Distribution
imgw_pib-1.0.4-py3-none-any.whl
(11.0 kB
view details)
File details
Details for the file imgw_pib-1.0.4.tar.gz
.
File metadata
- Download URL: imgw_pib-1.0.4.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91b8572c238069da185cc63eb3c947025d5ed13260c35dc89ce71dc9af9b71ba |
|
MD5 | 4cc4e2de6701b09587a0fb081c5b0c10 |
|
BLAKE2b-256 | 8940df6131e8f2601c3694836a9e8b3131669dec8a5b85470aef13d814da3400 |
File details
Details for the file imgw_pib-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: imgw_pib-1.0.4-py3-none-any.whl
- Upload date:
- Size: 11.0 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 | 78a7ceeff4a856713ee514e7c643509140b5fdce1608e50a83dd2dd429736ae5 |
|
MD5 | e38c6920ee52b7c201ccd1486828fb7e |
|
BLAKE2b-256 | 45e06b36ffc4ab4cd704353978d2188bb49df7994cbf28fcf0b7af72fd787e71 |