Skip to main content

Get realtime info on stop passages of STIB/MIVB (opendata-api.stib-mivb.be)

Project description

pystibmivb GitHub version Build Status PyPI version Buy me a beer!

A Python package to retrieve realtime data of passages at stops of STIB/MIVB, the public transport company of Brussels (Belgium)

Main purpose at the moment is to feed a sensor in Home-Assistant (see: https://github.com/Emilv2/home-assistant/tree/stib-mivb/homeassistant/components/stib_mivb )

Important note: a developer account needs to be created at https://opendata.stib-mivb.be/ to generate a subscription key for the api's.

Install

pip install pystibmivb

Example usage

"""Example usage of pystibmivb."""
import asyncio

import aiohttp

from pystibmivb import STIBAPIClient, STIBStop, STIBAPIAuthClient
from pystibmivb import STIBService
from pystibmivb import ShapefileService

CLIENT_ID = ''  # Put your openapi client ID here
CLIENT_SECRET = ''  # Put your openapi client secret here


async def go(LOOP):
    stop_name = "Scherdemael"
    lines_filter = [(46, "Glibert")]
    custom_session = aiohttp.ClientSession()
    APIClient = STIBAPIClient(LOOP, custom_session, STIBAPIAuthClient(custom_session, CLIENT_ID, CLIENT_SECRET))
    service = STIBService(APIClient)

    stop = STIBStop(service, stop_name, lines_filter, 3)
    print(await stop.get_passages())

    shapefile_service = ShapefileService(APIClient)

    scherdemael = await shapefile_service.get_stop_infos(stop_name)
    print(scherdemael.get_lines())
    # doesn't really make sense to specify a filter but hey... you can
    print(scherdemael.get_lines(lines_filter))
    print(scherdemael.get_lines_with_destinations(lines_filter))

    await custom_session.close()


if __name__ == '__main__':
    LOOP = asyncio.get_event_loop()
    LOOP.run_until_complete(go(LOOP))

Old repository: https://github.com/helldog136/pystibmvib Initial inspiration came from : https://github.com/bollewolle/pydelijn

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

pystibmivb-1.8.0.tar.gz (17.5 kB view details)

Uploaded Source

File details

Details for the file pystibmivb-1.8.0.tar.gz.

File metadata

  • Download URL: pystibmivb-1.8.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.1

File hashes

Hashes for pystibmivb-1.8.0.tar.gz
Algorithm Hash digest
SHA256 4026ca74d59338412bb3cb2cdc808be8483a790a36ce1f587a31f5f53a8802c6
MD5 be390edc6a7b2b026f6017d4daa3d039
BLAKE2b-256 c9bd50c1bf98cb9e735e8f1ee838f851d5d6fc265b6aac7fe16fbc9781d37676

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