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 aiohttp
from czpubtran.api import czpubtran
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('------------------------------------------------')
t = datetime.strptime("23:20","%H:%M").time()
await bus.async_find_connection('Namesti Republiky','Chodov','ABCz',t)
print(f'Scheduled connection from {bus.origin} to {bus.destination} at {t}:')
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
Release history Release notifications | RSS feed
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.1.16.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for czpubtran-0.1.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 569536335169bbb502649a09de1a031596b7376f31e309eaecc50b15825aa451 |
|
MD5 | e4c1c00cbd5b4306f30f4a8d7d228cd7 |
|
BLAKE2b-256 | af0589339f849c8cdc805c4761f57649bcf0b61f2764274c12685a6ddb782272 |