ProfileInterface¶
Contents
-
class
pyhafas.profile.interfaces.
ProfileInterface
[source]¶ Bases:
pyhafas.profile.interfaces.helper.request.RequestHelperInterface
,pyhafas.profile.interfaces.helper.format_products_filter.FormatProductsFilterHelperInterface
,pyhafas.profile.interfaces.helper.parse_lid.ParseLidHelperInterface
,pyhafas.profile.interfaces.helper.date_time.DateTimeHelperInterface
,pyhafas.profile.interfaces.helper.parse_leg.ParseLegHelperInterface
,pyhafas.profile.interfaces.helper.parse_remark.ParseRemarkHelperInterface
,pyhafas.profile.interfaces.requests.location.LocationRequestInterface
,pyhafas.profile.interfaces.requests.journey.JourneyRequestInterface
,pyhafas.profile.interfaces.requests.journeys.JourneysRequestInterface
,pyhafas.profile.interfaces.requests.station_board.StationBoardRequestInterface
,pyhafas.profile.interfaces.requests.trip.TripRequestInterface
,abc.ABC
The profile interface is the abstract class of a profile.
It inherits all interfaces, so it has all methods a normal profile has available as abstract methods. Therefore it can be used as type hint for self in methods which are inherited by profiles.
-
addChecksum
: bool¶ Whether the checksum authentication method should be activated. Exclusive with addMicMac
-
addMicMac
: bool¶ Whether the mic-mac authentication method should be activated. Exclusive with addChecksum
-
availableProducts
: Dict[str, List[int]]¶ Should contain all products available in HaFAS. The key is the name the end-user will use, the value is a list of bitmasks (numbers) needed for the product. In most cases, this is only one number. This bitmasks will be add up to generate the final bitmask.
-
baseUrl
: str¶ Complete http(s) URL to mgate.exe of the HaFAS deployment. Other endpoints are (currently) incompatible with pyHaFAS
-
defaultProducts
: List[str]¶ List of products (item must be a key in availableProducts) which should be activated by default
-
defaultUserAgent
: str¶ (optional) User-Agent in header when connecting to HaFAS. Defaults to pyhafas. A good option would be the app ones. Can be overwritten by the user.
-
requestBody
: dict¶ Static part of the request body sent to HaFAS. Normally contains informations about the client and another authentication
-
salt
: str¶ (required if addMicMac or addChecksum is true). The salt for calculating the checksum or mic-mac
-
timezone
: datetime.tzinfo¶ Timezone HaFAS lives in. Should be a pytz timezone object
-
Helper¶
format_products_filter¶
date_time¶
-
class
pyhafas.profile.interfaces.helper.date_time.
DateTimeHelperInterface
[source]¶ Bases:
abc.ABC
-
abstract
parse_datetime
(time_string, date)[source]¶ Parses the time format HaFAS returns and combines it with a date
-
abstract
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 :rtype:timedelta
:return: Parsed time as timedelta object
-
abstract
parse_leg¶
-
class
pyhafas.profile.interfaces.helper.parse_leg.
ParseLegHelperInterface
[source]¶ Bases:
abc.ABC
-
abstract
parse_leg
(journey, common, departure, arrival, date, jny_type='JNY', gis=None)[source]¶ Parses Leg HaFAS returns into Leg object
- 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.
- Return type
- Returns
Parsed Leg object
-
abstract
parse_lid¶
-
class
pyhafas.profile.interfaces.helper.parse_lid.
ParseLidHelperInterface
[source]¶ Bases:
abc.ABC
-
abstract
parse_lid
(lid)[source]¶ Converts the LID given by HaFAS. Splits the LID in multiple elements
-
abstract
request¶
-
class
pyhafas.profile.interfaces.helper.request.
RequestHelperInterface
[source]¶ Bases:
abc.ABC
-
abstract
calculate_checksum
(data)[source]¶ Calculates the checksum of the request (required for most profiles)
-
abstract
calculate_mic_mac
(data)[source]¶ Calculates the mic-mac for the request (required for some profiles)
-
abstract
Requests¶
journey¶
-
class
pyhafas.profile.interfaces.requests.journey.
JourneyRequestInterface
[source]¶ Bases:
abc.ABC
-
abstract
format_journey_request
(journey)[source]¶ Creates the HaFAS request body for a journey request
-
abstract
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
-
abstract
journeys¶
-
class
pyhafas.profile.interfaces.requests.journeys.
JourneysRequestInterface
[source]¶ Bases:
abc.ABC
-
abstract
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
-
abstract
format_search_from_leg_request
(origin, destination, via, min_change_time, max_changes, products)[source]¶ Creates the HaFAS request body for a search from leg request
- Parameters
- Return type
- Returns
Request body for HaFAS
-
abstract
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
-
abstract
location¶
-
class
pyhafas.profile.interfaces.requests.location.
LocationRequestInterface
[source]¶ Bases:
abc.ABC
-
abstract
format_location_request
(term, rtype='S')[source]¶ Creates the HaFAS request body for a location search request.
-
abstract
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
-
abstract
station_board¶
-
class
pyhafas.profile.interfaces.requests.station_board.
StationBoardRequestInterface
[source]¶ Bases:
abc.ABC
-
format_station_board_request
(station, request_type, date, max_trips, duration, products, direction)[source]¶ Creates the HaFAS request for Station Board (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 returnedproducts (
Dict
[str
,bool
]) – Allowed products (a product is a mean of transport like ICE,IC)duration (
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
- Return type
- Returns
List of StationBoardLeg objects
-
trip¶
-
class
pyhafas.profile.interfaces.requests.trip.
TripRequestInterface
[source]¶ Bases:
abc.ABC
-
abstract
parse_trip_request
(data)[source]¶ Parses the HaFAS data for a trip request
- Parameters
data (
HafasResponse
) – Formatted HaFAS response- Return type
- Returns
Leg objects
-
abstract