Skip to main content

Calling CHAPS REST API to get information about public transit in CZ

Project description

CzPubTran

A Python package to rertrieve realtime information about public transit in CZ by calling CHAPS REST API.

Main purpose at the moment is to feed a sensor in Home-Assistant

Install

pip install czpubtran

Example usage

import asyncio
import logging
import aiohttp
from datetime import datetime, time
from czpubtran.api import czpubtran

logging.basicConfig(level=logging.ERROR)

async def test():
    session = aiohttp.ClientSession(raise_for_status=True)
    bus = czpubtran(session, '')

    timetables = await bus.async_list_combination_ids()
    print("Listing available timetables (Combination IDs)")
    print(timetables)

    print('------------------------------------------------')

    await bus.async_find_connection('Namesti Republiky', 'Chodov', 'ABCz')
    print(f'First connection from {bus.origin} to {bus.destination} using timetable {bus.combination_id}:')
    print(f'Departure: {bus.departure} line {bus.line}')
    print(f'Duration: {bus.duration}')
    print('Connections:')
    for i, description in [(0, '1st connection'), (1, '2nd connection')]:
        print(f'{description}:')
        for detail in bus.connection_detail[i]:
            print(
                f"line {detail['line']} "
                f"at {detail['depTime']} "
                f"from {detail['depStation']} "
                f"-> {detail['arrStation']} "
                f"{detail['arrTime']} "
                f"(delay: {detail['delay']} min)")

    print('------------------------------------------------')

    await bus.async_find_connection('Namesti Republiky', 'Chodov', 'ABCz', '23:20')
    print(f'Scheduled connection from {bus.origin} to {bus.destination} at {bus.start_time}:')
    print(f'Departure: {bus.departure} line {bus.line}')
    print(f'Duration: {bus.duration}')
    print('Connections:')
    for i, description in [(0, '1st connection'), (1, '2nd connection')]:
        print(f'{description}:')
        for detail in bus.connection_detail[i]:
            print(
                f"line {detail['line']} "
                f"at {detail['depTime']} "
                f"from {detail['depStation']} "
                f"-> {detail['arrStation']} "
                f"{detail['arrTime']} "
                f"(delay: {detail['delay']} min)")

    await session.close()

asyncio.run(test())

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

czpubtran-0.2.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

czpubtran-0.2.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file czpubtran-0.2.1.tar.gz.

File metadata

  • Download URL: czpubtran-0.2.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for czpubtran-0.2.1.tar.gz
Algorithm Hash digest
SHA256 47fd7c6895821b81f97f5a6e0f18467eedbb42b2f50c500a55bd91e5e5c5d9fb
MD5 e8918210655ca22986ccc3b8968bb2e5
BLAKE2b-256 ff0a2914ff988d6293d9068892f92ddd263666f985def20fcda3e05d3d231fb0

See more details on using hashes here.

File details

Details for the file czpubtran-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: czpubtran-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for czpubtran-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e77b65f5867467503d13af4d6901e9969ec204349bac4698d1bc61f7c431956
MD5 46eacea6cddbc2ea7062d36ebb7c5d7b
BLAKE2b-256 790ca8d6a769edc83ddf01e9c9118e9ca5677ab77919d3a6d5b658f0bf7913e9

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