Skip to main content

Python wrapper for IMGW-PIB API.

Project description

GitHub Release PyPI PyPI - Downloads PayPal_Me

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


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.6.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

imgw_pib-1.0.6-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file imgw_pib-1.0.6.tar.gz.

File metadata

  • Download URL: imgw_pib-1.0.6.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for imgw_pib-1.0.6.tar.gz
Algorithm Hash digest
SHA256 b01d9ecb0a68fa82e8e393b263d43887880bfdd8c092fe3f703ca0fd116529a9
MD5 eeb2aaddf4b009ad93503fefd7e48661
BLAKE2b-256 7305ba6ef4fbb14ddedbed98a594db72fdcc1d140e268573f64753fcd678a635

See more details on using hashes here.

File details

Details for the file imgw_pib-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: imgw_pib-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for imgw_pib-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 39bde471d318218e9a093f9fc0df45ea06a2b652b90d8bd461d875ece9a77c67
MD5 a7249ef79d727b4eea933ec8ebff50ce
BLAKE2b-256 ace52cbbf0b4e651d4e5005761d2346913574d3dff3062ca5fc88c0f1e1288ea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page