Async Python client for the public waste collection calendars published by Junker.
It fetches the calendar page of a municipality (and optionally one of its areas) and returns the scheduled collections.
pip install junker-apiimport asyncio
from aiohttp import ClientSession
from junker_api import AreaRequired, JunkerClient, JunkerConnectionError, JunkerError
async def main() -> None:
async with ClientSession() as session:
client = JunkerClient(session, "Milano")
try:
collections = await client.async_get_collections()
except AreaRequired as err:
# The municipality has several areas: pick one and retry.
area = err.areas[0]
client = JunkerClient(session, "Milano", str(area.id))
collections = await client.async_get_collections()
except JunkerConnectionError:
print("Junker is not reachable")
return
except JunkerError:
print("No calendar found for this municipality")
return
for collection in collections:
print(collection.date, collection.waste_type)
asyncio.run(main())JunkerClient(session, municipality, area_id=None): client bound to a municipality and an optional area ID.await client.async_get_collections(): returns a list ofCollection(date, waste_type)sorted by date.slugify_municipality(name): converts a municipality name into the slug used in Junker URLs.
JunkerError: base error, also raised when the calendar does not exist or cannot be parsed.JunkerConnectionError: network failure, timeout or HTTP 5xx response.AreaRequired: the municipality requires an area; the availableArea(id, name)items are inerr.areas.
pip install -e ".[test]"
python -m pytest --cov=junker_api --cov-report=term-missingThis project is not affiliated with Junker. It relies on Junker's public web pages, which may change without notice.
Apache-2.0