Skip to main content

Python library to retrieve data from Grand Lyon open data platform, for Home Assistant.

Project description

data_grand_lyon_ha

Python library to retrieve data from the Grand Lyon open data platform.

Intended for use as a Home Assistant integration backend.

Installation

pip install data-grand-lyon-ha

Or with uv:

uv add data-grand-lyon-ha

Usage

import asyncio
from datetime import datetime
import aiohttp
from data_grand_lyon_ha import (
    DataGrandLyonClient,
    extract_tcl_pictogram_from_zip,
    filter_tcl_alerts_by_line,
    filter_tcl_passages_by_line,
    filter_tcl_passages_by_stop,
    find_tcl_line_pictogram_by_code,
    find_tcl_park_and_ride_by_id,
    find_tcl_stop_by_id,
    find_velov_station_by_id,
    sort_tcl_alerts_by_relevance,
    sort_tcl_passages_by_time,
)

async def main():
    async with aiohttp.ClientSession() as session:
        client = DataGrandLyonClient(session)
        # Or with authentication (required for real-time TCL passages):
        # client = DataGrandLyonClient(session, username="user", password="pass")

        # TCL passages: fetch all, then filter and sort client-side
        all_passages = await client.get_tcl_passages()
        passages = filter_tcl_passages_by_stop(
            filter_tcl_passages_by_line(all_passages, "A"), 30101
        )
        for p in sort_tcl_passages_by_time(passages):
            print(f"{p.ligne}{p.direction} in {p.delai_passage} [{p.type}]")

        # TCL stops: fetch all, then look one up by ID
        stops = await client.get_tcl_stops()
        stop = find_tcl_stop_by_id(stops, 1041)
        if stop:
            print(f"{stop.nom} ({stop.commune}) — lines: {stop.desserte}")

        # Vélo'v stations: fetch all, then look one up by ID
        stations = await client.get_velov_stations()
        station = find_velov_station_by_id(stations, 10044)
        if station:
            print(
                f"{station.name}: {station.available_bikes}/{station.bike_stands} bikes"
            )

        # TCL park-and-rides (P+R): fetch all, then look one up by ID
        parks = await client.get_tcl_park_and_rides()
        park = find_tcl_park_and_ride_by_id(parks, "VAI2")
        if park:
            print(
                f"{park.nom}: {park.nb_tot_place_dispo}/{park.capacite} places"
            )

        # TCL traffic alerts: fetch all, filter by line, then sort most-relevant-first
        # (ongoing or starting today come before later days; ended alerts last).
        all_alerts = await client.get_tcl_alerts()
        alerts = filter_tcl_alerts_by_line(all_alerts, "27")
        for a in sort_tcl_alerts_by_relevance(alerts, datetime.now()):
            print(f"[{a.type}] {a.titre} ({a.debut:%d/%m %H:%M}{a.fin:%d/%m %H:%M})")

        # TCL line pictograms: list lines, then extract one line's SVG as bytes
        # (e.g. for a Home Assistant image entity).
        lines = await client.get_tcl_line_pictograms()
        line = find_tcl_line_pictogram_by_code(lines, "10")
        if line:
            zip_bytes = await client.get_tcl_line_pictograms_zip()
            svg = extract_tcl_pictogram_from_zip(zip_bytes, line.picto_complet)
            if svg:
                print(f"Pictogram for line 10: {len(svg)} bytes")

asyncio.run(main())

Development

This project uses uv for dependency management.

# Run tests
uv run pytest

# Build the package
uv build

License

MIT

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

data_grand_lyon_ha-0.9.0rc1.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

data_grand_lyon_ha-0.9.0rc1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file data_grand_lyon_ha-0.9.0rc1.tar.gz.

File metadata

  • Download URL: data_grand_lyon_ha-0.9.0rc1.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for data_grand_lyon_ha-0.9.0rc1.tar.gz
Algorithm Hash digest
SHA256 ea7c9351eb45fb1e5deff9e18d4cf293cfc040da2356478453b5841ad642b79b
MD5 5948e9a50acffc9409e0d6af46b60bd8
BLAKE2b-256 2a9e7039eca716f2be391e7f0bf9a5dc8a5ea0a7e453fd7014baa743c8e21ae7

See more details on using hashes here.

File details

Details for the file data_grand_lyon_ha-0.9.0rc1-py3-none-any.whl.

File metadata

  • Download URL: data_grand_lyon_ha-0.9.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for data_grand_lyon_ha-0.9.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 d948ce17dc7b645e57e65566cb66b1d44ed936d53882ec6847d5abb09c1ff1f0
MD5 d9c8e993777763d84c94c912dfada856
BLAKE2b-256 4d31d154a07b22fd8114e1197022483c54077e177576217dff45a88b8efa127d

See more details on using hashes here.

Supported by

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