inky_pi.train.train_base module

Base class and helper functions for train model

class inky_pi.train.train_base.TrainBase[source]

Bases: ABC

Abstract base class for all train models

_abc_impl = <_abc._abc_data object>
_validate_number(num: int) None[source]

Check if train number is valid

Parameters:

num (int) – Train number to check

Raises:

ValueError – Invalid train number

abstract fetch_train(num: int) str[source]

Return requested train data

Parameters:

num (int) – Desired train number

Returns:

Train data

Return type:

str

static format_error_msg(error_msg: str, num: int) str[source]

Format error message by line wrapping over each line

Parameters:
  • error_msg (str) – Error message

  • num (int) – Train number

Returns:

Formatted error message

Return type:

str

static format_train_string(arrival_t: str, platform: str, dest_stn: str, status: str) str[source]

Takes in a train’s arrival time, platform, destination station, and status, and returns a string with the train’s information in a display format.

Parameters:
  • arrival_t (str) – The time the train is due to arrive at the station.

  • platform (str) – The platform number the train is arriving at.

  • dest_stn (str) – The destination station of the train.

  • status (str) – The status of the train.

Returns:

Formatted string

Return type:

str

abstract retrieve_data(protocol: Any, train_object: TrainObject) None[source]

Retrieves train data from API; must be called after constructor

Parameters:
  • protocol – HTTP data protocol (e.g. requests or zeep)

  • train_object – Train object

class inky_pi.train.train_base.TrainModel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum of train models

HUXLEY2 = 'HUXLEY2'
OPEN_LIVE = 'OPEN_LIVE'
class inky_pi.train.train_base.TrainObject(model: TrainModel, station_from: str, station_to: str, number: int, url: str = '', token: str = '')[source]

Bases: object

Train object

model: TrainModel
number: int
station_from: str
station_to: str
token: str = ''
url: str = ''
inky_pi.train.train_base.abbreviate_stn_name(station_name: str) str[source]

Helper function to abbreviate station name by shortening words

Parameters:

station_name (str) – Station name

Returns:

Abbreviated station name

Return type:

str