idfm_api package
Submodules
idfm_api.dataset module
- class idfm_api.dataset.Dataset
Bases:
objectClass used to generate the lines and stops listings
The data is fetched only once per execution, the result is then cached as this process takes multiple seconds
To find a list of all the stops we need to use multiple datasets: LINES -> get line ID -> STOP_AND_LINES -> get corresponding stops areas for trains (ZdAId) OR get corresponding stops points for other modes (ArRId) -> STOP_RELATIONS -> map the ArRid to ZdAId AND map the ZdAId to the exchange area (ZdCId) -> EXCHANGE_AREAS -> get the exchange area data
So the process looks like this: LineID -> ZdAId -> ZdCId OR LineID -> ArId -> ZdAId -> ZdCId
- async static fetch_data(session)
Fetch and process the data from IDFM datasets
- Parameters:
session (
ClientSession) – the aiohttp session
- async static get_lines(session)
Fetch the latest data from IDFM (if needed) and returns the available lines
- Parameters:
session (
ClientSession) – aiohttp session- Returns:
a map of the TransportType to a list of lines (Name:ID)
- Return type:
dict[str,list[dict]]
- async static get_stops(session)
Fetch the latest data from IDFM (if needed) and returns the available stops
- Parameters:
session (
ClientSession) – aiohttp session- Returns:
a map of the line id to a list of stops
- Return type:
dict[str, list[dict]]
- lines = None
- stops = None
idfm_api.models module
- class idfm_api.models.InfoData(id, name, message, start_time, end_time, severity, type)
Bases:
objectRepresents a traffic information fragment
-
end_time:
datetime
- static from_json(data)
-
id:
str
-
message:
str
-
name:
str
-
severity:
int
-
start_time:
datetime
-
type:
str
-
end_time:
- class idfm_api.models.LineData(name, id, type)
Bases:
objectRepresents a line of a transport
-
id:
str
-
name:
str
-
type:
TransportType
-
id:
- class idfm_api.models.ReportData(id, name, message, periods, severity, effect, category, cause, type)
Bases:
objectRepresents a traffic information fragment (navitia version)
-
category:
str
-
cause:
str
-
effect:
str
- static from_json(data)
-
id:
str
-
message:
str
-
name:
str
-
periods:
list[datetime,datetime]
-
severity:
int
-
type:
str
-
category:
- class idfm_api.models.StopData(name, stop_id, x, y, zip_code, city, exchange_area_id, exchange_area_name)
Bases:
objectRepresents a stop area of a line
-
city:
str
-
exchange_area_id:
str
-
exchange_area_name:
str
- static from_json(data)
-
name:
str
-
stop_id:
str
-
x:
float
-
y:
float
-
zip_code:
str
-
city:
- class idfm_api.models.TrafficData(line_id, note, destination_name, destination_id, direction, schedule, retarted, at_stop, platform, status)
Bases:
objectRepresents a schedule for a specific path
-
at_stop:
bool
-
destination_id:
str
-
destination_name:
str
-
direction:
str
- static from_json(data)
-
line_id:
str
-
note:
str
-
platform:
str
-
retarted:
bool
-
schedule:
datetime
-
status:
str
-
at_stop:
- class idfm_api.models.TransportStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
str,EnumRepresents the status of a transport
- ARRIVED = 'arrived'
- CANCELLED = 'cancelled'
- DELAYED = 'delayed'
- EARLY = 'early'
- MISSED = 'missed'
- NOT_EXPECTED = 'notExpected'
- NO_REPORT = 'noReport'
- ON_TIME = 'onTime'
- UNKNOWN = 'unknown'
idfm_api.utils module
- class idfm_api.utils.MLStripper
Bases:
HTMLParserClass used to remove HTML tags from a string
- get_data()
- handle_data(d)
- idfm_api.utils.strip_html(html)
Removes HTML tags from the specified string :type html: :param html: the string that contains the HTML tags to remove
- Returns:
The specified string without the HTML tags
Module contents
- class idfm_api.IDFMApi(session, apikey, timeout=60)
Bases:
object- async get_destinations(stop_id, direction_name=None, line_id=None)
Returns the available destinations for a specified line
- Parameters:
stop_id (
str) – A string indicating the id of the depart stop areadirection_name (
Optional[str]) – The direction of a trainline_id (
Optional[str]) – A string indicating id of a line (if not specified, all destinations for this stop will be returned regardless of the line)
- Return type:
List[str]- Returns:
A list of string representing the stations names
- async get_directions(stop_id, line_id=None)
Returns the available directions for a specified line
- Parameters:
stop_id (
str) – A string indicating the id of the depart stop arealine_id (
Optional[str]) – A string indicating id of a line (if not specified, all directions for this stop will be returned regardless of the line)
- Return type:
List[str]- Returns:
A list of string representing the stations names
- async get_infos(line_id)
Returns the traffic informations (usually the current/planned perturbations) for the specified line
Warning: DEPRECATED in favor of get_line_reports
- Parameters:
line_id (
str) – A string indicating the id of a line- Return type:
List[InfoData]- Returns:
A list of InfoData objects, the list is empty if no perturbations are registered
- async get_line_reports(line_id, exclude_elevator=True)
Return the traffic informations (usually the current/planned perturbations) for the specified line
- Parameters:
line_id (
str) – A string indicating the id of a lineexclude_elevator (
bool) – if the elevator failures perturbations should be ignored
- Return type:
List[ReportData]- Returns:
A list of InfoData objects, the list is empty if no perturbations are registered
- async get_lines(transport=None)
Returns the available lines by transport type
- Parameters:
transport (
Optional[TransportType]) – the transport type, all of them are returned if this is omitted- Return type:
List[LineData]- Returns:
A list of LineData objects
- async get_stops(line_id)
Return a list of stop areas corresponding to the specified line :type line_id:
str:param line_id: A string indicating id of a line- Return type:
List[StopData]- Returns:
A list of StopData objects
- async get_traffic(stop_id, destination_name=None, direction_name=None, line_id=None)
Returns the next schedules in a line for a specified depart area to an optional destination
- Parameters:
stop_id (
str) – A string indicating the id of the depart stop areadestination_name (
Optional[str]) – A string indicating the final destination (I.E. the station name returned by get_directions), the schedules for all the available destinations are returned if not specifieddirection_name (
Optional[str]) – A boolean indicating the direction of a train, ignored if not specifiedline_id (
Optional[str]) – A string indicating id of a line (if not specified, all schedules for this stop/direction will be returned regardless of the line)
- Return type:
List[TrafficData]- Returns:
A list of TrafficData objects
- exception idfm_api.UnknownIdentifierException
Bases:
ExceptionException raised when the identifier (MonitoringRef/LineRef) is unknown