Skip to content

Commit

Permalink
Update example, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu committed Apr 22, 2024
1 parent cead80d commit 684d3ee
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
[![GitHub Release][releases-shield]][releases]
[![PyPI][pypi-releases-shield]][pypi-releases]
[![PyPI - Downloads][pypi-downloads]][pypi-statistics]
[![PayPal_Me][paypal-me-shield]][paypal-me]

# imgw-pib
Python wrapper for IMGW-PIB API

Python async wrapper for IMGW-PIB API.


## How to use package

```python
"""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"


async def main() -> None:
"""Run main function."""
async with ClientSession() as websession:
try:
imgwpib = await ImgwPib.create(websession, WEATHER_STATION_ID)
weather_data = await imgwpib.get_weather_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(imgwpib.weather_stations)
print(weather_data)


loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()

```

[releases]: https://github.com/bieniu/imgw-pib/releases
[releases-shield]: https://img.shields.io/github/release/bieniu/imgw-pib.svg?style=popout
[pypi-releases]: https://pypi.org/project/imgw-pib/
[pypi-statistics]: https://pepy.tech/project/imgw-pib
[pypi-releases-shield]: https://img.shields.io/pypi/v/imgw-pib
[pypi-downloads]: https://pepy.tech/badge/imgw-pib/month
[paypal-me-shield]: https://img.shields.io/static/v1.svg?label=%20&message=PayPal.Me&logo=paypal
[paypal-me]: https://www.paypal.me/bieniu79
10 changes: 6 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import logging

from aiohttp import ClientConnectorError, ClientSession
from aiohttp import ClientError, ClientSession

from imgw_pib import ApiError, ImgwPib

Expand All @@ -20,10 +20,12 @@ async def main() -> None:
weather_data = await imgwpib.get_weather_data()
except ApiError as error:
print(f"API Error: {error.status}")
except ClientConnectorError as error:
print(f"ClientConnectorError: {error}")
except ClientError as error:
print(f"ClientError: {error}")
except TimeoutError as error:
print(f"TimeoutError: {error}")
else:
print(imgwpib.stations)
print(imgwpib.weather_stations)
print(weather_data)


Expand Down
6 changes: 3 additions & 3 deletions imgw_pib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async def create(
return instance

@property
def stations(self: Self) -> dict[str, str]:
"""Return list of stations."""
def weather_stations(self: Self) -> dict[str, str]:
"""Return list of weather stations."""
return self._station_list

async def initialize(self: Self) -> None:
Expand All @@ -68,7 +68,7 @@ async def initialize(self: Self) -> None:

if (
self.weather_station_id is not None
and self.weather_station_id not in self._station_list
and self.weather_station_id not in self.weather_stations
):
msg = f"Invalid weather station ID: {self.weather_station_id}"
raise ApiError(msg)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def test_weather_stations(

await session.close()

assert imgwpib.stations == snapshot
assert imgwpib.weather_stations == snapshot


@pytest.mark.asyncio()
Expand Down

0 comments on commit 684d3ee

Please sign in to comment.