onboardapis.train

Package for trains

Operator ID

The operator ID for trains is different depending on the region.

For Europe, the operator ID is the VKM register code.


Contains the following countries:


  1"""
  2Package for trains
  3
  4## Operator ID
  5
  6The operator ID for trains is different depending on the region.
  7
  8For Europe, the operator ID is the [VKM register code](https://www.era.europa.eu/domains/registers/vkm_en).
  9
 10---
 11
 12Contains the following countries:
 13
 14- ``onboardapis.train.at`` - Austria
 15- ``onboardapis.train.cz`` - Czechia
 16- ``onboardapis.train.de`` - Germany
 17- ``onboardapis.train.fr`` - France
 18- ``onboardapis.train.it`` - Italy
 19
 20---
 21"""
 22from __future__ import annotations
 23
 24import logging
 25
 26from abc import ABCMeta
 27from dataclasses import dataclass
 28from typing import cast
 29
 30from .. import Vehicle, Station, ConnectingVehicle
 31from ..data import ScheduledEvent
 32
 33# noinspection PyUnresolvedReferences
 34from typing import Iterable  # for associations while generating docs
 35# noinspection PyUnresolvedReferences
 36from ..data import ID, Position  # noqa: F401  # for associations while generating docs
 37# noinspection PyUnresolvedReferences
 38from datetime import datetime  # noqa: F401  # for associations while generating docs
 39
 40logger = logging.getLogger(__name__)
 41
 42
 43__all__ = [
 44    "at",
 45    "cz",
 46    "de",
 47    "fr",
 48    "it",
 49    "third_party",
 50    "TrainStation",
 51    "Train",
 52    "ConnectingTrain",
 53]
 54
 55
 56@dataclass
 57class TrainStation(Station):
 58    """
 59    An `onboardapis.Station` with the additional information of a platform
 60    """
 61    _connections: Iterable[ConnectingTrain]
 62
 63    platform: ScheduledEvent[str] | None
 64    """The platform where the train arrives."""
 65
 66    @property
 67    def connections(self) -> list[ConnectingTrain]:
 68        return cast(list[ConnectingTrain], super().connections)  # maybe force type instead of casting?
 69
 70
 71class Train(Vehicle, metaclass=ABCMeta):
 72    """
 73    Base class for all train implementations.
 74    """
 75
 76    def __repr__(self) -> str:
 77        return f"<{self.__class__.__name__}>"
 78
 79    @property
 80    def type(self) -> str:
 81        """
 82        :return: The abbreviated train type
 83        :raises DataInvalidError: If the train type could not be fetched from the server
 84        """
 85        return 'undefined'
 86
 87    @property
 88    def line_number(self) -> str:
 89        """
 90        :return: The line number
 91        :raises DataInvalidError: If the line number could not be fetched from the server
 92        """
 93        return 'undefined'
 94
 95
 96@dataclass
 97class ConnectingTrain(ConnectingVehicle):
 98    """
 99    A connecting train is a train that is not part of the main trip but of a connecting service
100
101    It may only have limited information available
102    """
103
104    platform: ScheduledEvent[str] | None
105    """
106    The platform where the train will depart from
107    """
@dataclass
class TrainStation(onboardapis.Station):
57@dataclass
58class TrainStation(Station):
59    """
60    An `onboardapis.Station` with the additional information of a platform
61    """
62    _connections: Iterable[ConnectingTrain]
63
64    platform: ScheduledEvent[str] | None
65    """The platform where the train arrives."""
66
67    @property
68    def connections(self) -> list[ConnectingTrain]:
69        return cast(list[ConnectingTrain], super().connections)  # maybe force type instead of casting?

An onboardapis.Station with the additional information of a platform

TrainStation( id: ~ID, name: str, arrival: Optional[onboardapis.data.ScheduledEvent[datetime.datetime]], departure: Optional[onboardapis.data.ScheduledEvent[datetime.datetime]], position: onboardapis.data.Position | None, distance: float | None, _connections: Iterable[ConnectingTrain], platform: Optional[onboardapis.data.ScheduledEvent[str]])
platform: Optional[onboardapis.data.ScheduledEvent[str]]

The platform where the train arrives.

connections: list[ConnectingTrain]
67    @property
68    def connections(self) -> list[ConnectingTrain]:
69        return cast(list[ConnectingTrain], super().connections)  # maybe force type instead of casting?

The connecting services departing from this station.

class Train(onboardapis.Vehicle):
72class Train(Vehicle, metaclass=ABCMeta):
73    """
74    Base class for all train implementations.
75    """
76
77    def __repr__(self) -> str:
78        return f"<{self.__class__.__name__}>"
79
80    @property
81    def type(self) -> str:
82        """
83        :return: The abbreviated train type
84        :raises DataInvalidError: If the train type could not be fetched from the server
85        """
86        return 'undefined'
87
88    @property
89    def line_number(self) -> str:
90        """
91        :return: The line number
92        :raises DataInvalidError: If the line number could not be fetched from the server
93        """
94        return 'undefined'

Base class for all train implementations.

type: str
80    @property
81    def type(self) -> str:
82        """
83        :return: The abbreviated train type
84        :raises DataInvalidError: If the train type could not be fetched from the server
85        """
86        return 'undefined'
Returns

The abbreviated train type

Raises
  • DataInvalidError: If the train type could not be fetched from the server
line_number: str
88    @property
89    def line_number(self) -> str:
90        """
91        :return: The line number
92        :raises DataInvalidError: If the line number could not be fetched from the server
93        """
94        return 'undefined'
Returns

The line number

Raises
  • DataInvalidError: If the line number could not be fetched from the server
Inherited Members
onboardapis.Vehicle
init
shutdown
now
id
@dataclass
class ConnectingTrain(onboardapis.ConnectingVehicle):
 97@dataclass
 98class ConnectingTrain(ConnectingVehicle):
 99    """
100    A connecting train is a train that is not part of the main trip but of a connecting service
101
102    It may only have limited information available
103    """
104
105    platform: ScheduledEvent[str] | None
106    """
107    The platform where the train will depart from
108    """

A connecting train is a train that is not part of the main trip but of a connecting service

It may only have limited information available

ConnectingTrain( vehicle_type: str | None, line_number: str | None, departure: Optional[onboardapis.data.ScheduledEvent[datetime.datetime]], destination: str | None, platform: Optional[onboardapis.data.ScheduledEvent[str]])
platform: Optional[onboardapis.data.ScheduledEvent[str]]

The platform where the train will depart from