BaseProfile¶
Contents
For a documentation of the variables, please look at the documentation of ProfileInterface
-
class
pyhafas.profile.base.
BaseProfile
(ua=None)[source]¶ Bases:
pyhafas.profile.base.helper.request.BaseRequestHelper
,pyhafas.profile.base.helper.format_products_filter.BaseFormatProductsFilterHelper
,pyhafas.profile.base.helper.parse_lid.BaseParseLidHelper
,pyhafas.profile.base.helper.date_time.BaseDateTimeHelper
,pyhafas.profile.base.helper.parse_leg.BaseParseLegHelper
,pyhafas.profile.base.helper.parse_remark.BaseParseRemarkHelper
,pyhafas.profile.base.requests.location.BaseLocationRequest
,pyhafas.profile.base.requests.journey.BaseJourneyRequest
,pyhafas.profile.base.requests.journeys.BaseJourneysRequest
,pyhafas.profile.base.requests.station_board.BaseStationBoardRequest
,pyhafas.profile.base.requests.trip.BaseTripRequest
,pyhafas.profile.interfaces.ProfileInterface
Profile for a “normal” HaFAS. Only for other profiles usage as basis.
Helper¶
format_products_filter¶
-
class
pyhafas.profile.base.helper.format_products_filter.
BaseFormatProductsFilterHelper
[source]¶ Bases:
pyhafas.profile.interfaces.helper.format_products_filter.FormatProductsFilterHelperInterface
Helper for creating the products filter
date_time¶
-
class
pyhafas.profile.base.helper.date_time.
BaseDateTimeHelper
[source]¶ Bases:
pyhafas.profile.interfaces.helper.date_time.DateTimeHelperInterface
-
parse_datetime
(time_string, date)[source]¶ Parses the time format HaFAS returns and combines it with a date
-
parse_timedelta
(time_string)[source]¶ Parses the time HaFAS returns as timedelta object
Example use case is when HaFAS returns a duration of a leg :type time_string:
str
:param time_string: Time string sent by HaFAS (example for format is: 033200) :rtype:timedelta
:return: Parsed time as timedelta object
-
parse_leg¶
-
class
pyhafas.profile.base.helper.parse_leg.
BaseParseLegHelper
[source]¶ Bases:
pyhafas.profile.interfaces.helper.parse_leg.ParseLegHelperInterface
-
parse_leg
(journey, common, departure, arrival, date, jny_type='JNY', gis=None)[source]¶ Parses Leg HaFAS returns into Leg object
Different Types of HaFAS responses can be parsed into a leg object with the multiple variables
- Parameters
journey (
dict
) – Journey object given back by HaFAS (Data of the Leg to parse)common (
dict
) – Common object given back by HaFASdeparture (
dict
) – Departure object given back by HaFASarrival (
dict
) – Arrival object given back by HaFASdate (
date
) – Parsed date of Journey (Departing date)jny_type (
str
) – HaFAS Journey typegis – GIS object given back by HaFAS. Currently only used by “WALK” journey type.
- Return type
- Returns
Parsed Leg object
-
parse_lid¶
-
class
pyhafas.profile.base.helper.parse_lid.
BaseParseLidHelper
[source]¶ Bases:
pyhafas.profile.interfaces.helper.parse_lid.ParseLidHelperInterface
-
parse_lid
(lid)[source]¶ Converts the LID given by HaFAS
Splits the LID (e.g. A=1@O=Siegburg/Bonn) in multiple elements (e.g. A=1 and O=Siegburg/Bonn). These are converted into a dict where the part before the equal sign is the key and the part after the value.
-
request¶
-
class
pyhafas.profile.base.helper.request.
BaseRequestHelper
[source]¶ Bases:
pyhafas.profile.interfaces.helper.request.RequestHelperInterface
-
calculate_checksum
(data)[source]¶ Calculates the checksum of the request (required for most profiles)
-
calculate_mic_mac
(data)[source]¶ Calculates the mic-mac for the request (required for some profiles)
-
request
(body)[source]¶ Sends the request and does a basic parsing of the response and error handling
- Parameters
body – Reqeust body as dict (without the requestBody of the profile)
- Return type
- Returns
HafasRespone object or Exception when HaFAS response returns an error
-
request_session
= <requests.sessions.Session object>¶
-
Mappings¶
error_codes¶
-
class
pyhafas.profile.base.mappings.error_codes.
BaseErrorCodesMapping
(value)[source]¶ Bases:
pyhafas.profile.interfaces.mappings.error_codes.ErrorCodesMappingInterface
Mapping of the HaFAS error code to the exception class
default defines the error when the error code cannot be found in the mapping
-
AUTH
= <class 'pyhafas.types.exceptions.AuthenticationError'>¶
-
H500
= <class 'pyhafas.types.exceptions.JourneysTooManyTrainsError'>¶
-
H890
= <class 'pyhafas.types.exceptions.JourneysArrivalDepartureTooNearError'>¶
-
LOCATION
= <class 'pyhafas.types.exceptions.LocationNotFoundError'>¶
-
R5000
= <class 'pyhafas.types.exceptions.AccessDeniedError'>¶
-
SQ005
= <class 'pyhafas.types.exceptions.TripDataNotFoundError'>¶
-
TI001
= <class 'pyhafas.types.exceptions.TripDataNotFoundError'>¶
-
Requests¶
journey¶
-
class
pyhafas.profile.base.requests.journey.
BaseJourneyRequest
[source]¶ Bases:
pyhafas.profile.interfaces.requests.journey.JourneyRequestInterface
-
parse_journey_request
(data)[source]¶ Parses the HaFAS response for a journey request
- Parameters
data (
HafasResponse
) – Formatted HaFAS response- Return type
- Returns
List of Journey objects
-
journeys¶
-
class
pyhafas.profile.base.requests.journeys.
BaseJourneysRequest
[source]¶ Bases:
pyhafas.profile.interfaces.requests.journeys.JourneysRequestInterface
-
format_journeys_request
(origin, destination, via, date, min_change_time, max_changes, products, max_journeys)[source]¶ Creates the HaFAS request body for a journeys request
- Parameters
origin (
Station
) – Origin stationdestination (
Station
) – Destionation stationdate (
datetime
) – Date and time to search journeys formin_change_time (
int
) – Minimum transfer/change time at each stationmax_changes (
int
) – Maximum number of changesproducts (
Dict
[str
,bool
]) – Allowed products (a product is a mean of transport like ICE,IC)max_journeys (
int
) – Maximum number of returned journeys
- Return type
- Returns
Request body for HaFAS
-
format_search_from_leg_request
(origin, destination, via, min_change_time, max_changes, products)[source]¶ Creates the HaFAS request body for a journeys request
- Parameters
- Return type
- Returns
Request body for HaFAS
-
parse_journeys_request
(data)[source]¶ Parses the HaFAS response for a journeys request
- Parameters
data (
HafasResponse
) – Formatted HaFAS response- Return type
- Returns
List of Journey objects
-
location¶
-
class
pyhafas.profile.base.requests.location.
BaseLocationRequest
[source]¶ Bases:
pyhafas.profile.interfaces.requests.location.LocationRequestInterface
-
format_location_request
(term, rtype='S')[source]¶ Creates the HaFAS request body for a location search request.
- Parameters
term (
str
) – Search termtype – Result types. One of [‘S’ for stations, ‘ALL’ for addresses and stations]
- Returns
Request body for HaFAS
-
parse_location_request
(data)[source]¶ Parses the HaFAS response for a location request
- Parameters
data (
HafasResponse
) – Formatted HaFAS response- Return type
- Returns
List of Station objects
-
station_board¶
-
class
pyhafas.profile.base.requests.station_board.
BaseStationBoardRequest
[source]¶ Bases:
pyhafas.profile.interfaces.requests.station_board.StationBoardRequestInterface
-
format_station_board_request
(station, request_type, date, max_trips, duration, products, direction)[source]¶ Creates the HaFAS request for a station board request (departure/arrival)
- Parameters
station (
Station
) – Station to get departures/arrivals forrequest_type (
StationBoardRequestType
) – ARRIVAL or DEPARTUREdate (
datetime
) – Date and time to get departures/arrival formax_trips (
int
) – Maximum number of trips that can be returnedduration (
int
) – Time in which trips are searcheddirection (
Optional
[Station
]) – Direction (end) station of the train. If none, filter will not be applied
- Return type
- Returns
Request body for HaFAS
-
parse_station_board_request
(data, departure_arrival_prefix)[source]¶ Parses the HaFAS data for a station board request
- Parameters
data (
HafasResponse
) – Formatted HaFAS responsedeparture_arrival_prefix (
str
) – Prefix for specifying whether its for arrival or departure (either a for arrival or d for departure)
- Return type
- Returns
List of StationBoardLeg objects
-
trip¶
-
class
pyhafas.profile.base.requests.trip.
BaseTripRequest
[source]¶ Bases:
pyhafas.profile.interfaces.requests.trip.TripRequestInterface
-
parse_trip_request
(data)[source]¶ Parses the HaFAS data for a trip request
- Parameters
data (
HafasResponse
) – Formatted HaFAS response- Return type
- Returns
Leg objects
-