HafasClient¶
The HafasClient is the interface between your program and pyhafas internal code. You need it when you’re using pyHaFAS. Below you can find the API of the client.
-
class
pyhafas.client.
HafasClient
(profile, ua='pyhafas', debug=False)[source]¶ The interface between the user’s program and pyHaFAS internal code.
- Parameters
profile (
ProfileInterface
) – Profile to be usedua (
str
) – (optional, not recommended to change) The user-agent which will be sent to HaFAS. By default “pyhafas”, but is often overwritten by profile to emulate the app.debug (
bool
) – (optional) Whether debug mode should be enabled. Defaults to False.
-
arrivals
(station, date, max_trips=- 1, duration=- 1, products={}, direction=None)[source]¶ Returns arriving trips at the specified station
To get detailed information on the trip use the trip method with the id
- Parameters
station (
Union
[Station
,str
]) – FPTF Station object or ID of stationdate (
datetime
) – Date and Time when to searchmax_trips (
int
) – (optional) Maximum number of trips to be returned. Default is “whatever HaFAS wants”duration (
int
) – (optional) Minutes after date in which is search is made. Default is “whatever HaFAS wants”products (
Dict
[str
,bool
]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.direction (
Union
[Station
,str
,None
]) – (optional) Direction (end) station of the vehicle. Default is any direction station is allowed
- Return type
- Returns
List of FPTF StationBoardLeg objects with arriving trips
-
departures
(station, date, max_trips=- 1, duration=- 1, products={}, direction=None)[source]¶ Returns departing trips at the specified station
To get detailed information on the trip use the trip method with the id
- Parameters
station (
Union
[Station
,str
]) – FPTF Station object or ID of stationdate (
datetime
) – Date and Time when to searchmax_trips (
int
) – (optional) Maximum number of trips to be returned. Default is “whatever HaFAS wants”duration (
int
) – (optional) Minutes after date in which is search is made. Default is “whatever HaFAS wants”products (
Dict
[str
,bool
]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.direction (
Union
[Station
,str
,None
]) – (optional) Direction (end) station of the vehicle. Default is any direction station is allowed
- Return type
- Returns
List of FPTF StationBoardLeg objects with departing trips
-
journey
(journey)[source]¶ Returns information about a specific journey by its ID
Useful if you want to refresh the data of the trip, e.g. the real-time data.
-
journeys
(origin, destination, date, via=[], min_change_time=0, max_changes=- 1, products={}, max_journeys=- 1)[source]¶ Returns possible journeys between two destinations
Possible journeys between two destinations are calculated by HaFAS and returned. It’s also possible to add multiple via stations.
- Parameters
origin (
Union
[Station
,str
]) – FPTF Station object or ID of origin/starting stationdestination (
Union
[Station
,str
]) – FPTF Station object or ID of destination/ending stationdate (
datetime
) – Date and Time when to searchvia (
List
[Union
[Station
,str
]]) – (optional) List of via stations. The route is calculated via all of these stations in the order of the list. The stations have to be a FPTF Station object or the ID of the station. The default is no via stations.min_change_time (
int
) – (optional) Minimum transfer/change time at each station. Default is the default that HaFAS specifies internal.max_changes (
int
) – (optional) Maximum number of changes. Default is unlimited.products (
Dict
[str
,bool
]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.max_journeys (
int
) – (optional) Maximum number of returned journeys. Default is the default that HaFAS specifies internal.
- Return type
- Returns
List of FPTF Journey objects
-
journeys_from_leg
(origin, destination, via=[], min_change_time=0, max_changes=- 1, products={})[source]¶ Returns possible journeys from a leg to a destination
Possible journeys between two destinations are calculated by HaFAS and returned. It’s also possible to add multiple via stations.
- Parameters
origin (
Leg
) – FPTF Leg object from where to searchdestination (
Union
[Station
,str
]) – FPTF Station object or ID of destination/ending stationvia (
List
[Union
[Station
,str
]]) – (optional) List of via stations. The route is calculated via all of these stations in the order of the list. The stations have to be a FPTF Station object or the ID of the station. The default is no via stations.min_change_time (
int
) – (optional) Minimum transfer/change time at each station. Default is the default that HaFAS specifies internal.max_changes (
int
) – (optional) Maximum number of changes. Default is unlimited.products (
Dict
[str
,bool
]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.
- Return type
- Returns
List of FPTF Journey objects