Since every HaFAS deployment is different we have the concept of profiles <profile>
G for managing the differences between them.
For a "standard" HaFAS we have the BaseProfile <pyhafas.profile.base>
which contains code working for most HaFAS deployments. This profile inherits the methods of all classes living in the folder of the profile. That classes all have an interface that defines the abstract methods of the class.
Most methods are instance methods, so they have a self parameter. Since the class using the method is the profile we use as type hint for self ProfileInterface <pyhafas.profile.interface>
. This interface defines the variables and methods a profile has.
- You need to know how to authenticate to the HaFAS deployment. In most cases, you need to know if the authentication is via mic-mac or checksum+salt and you need the salt. The salt can get out of the source code of official apps of the transport provider or you can look if other HaFAS libraries already support the transport provider and get the salt from them
- You need the general requests body. You can get this best with mitmproxy on the official app of the transport provider or of other libraries as in the other requirement
One good source for both requirements is hafas-client in the specific profile folder.
- Read the API of a profile. See
below <api>
. - Have a look at the already existing profiles and the
ProfileInterface <pyhafas.profile.interface>
to get the structure of a profile. - Create a new product folder with an __init__.py file containing the profile class
- Fill the required variables
- Add your profile to /pyhafas/profile/__init__.py
- Test if everything works
- Yes? Perfect, add your profile in the documentation and create a pull request! No? Go on with step 8.
- Log the request pyHaFAS sends and compare this request with the one the official app sends. Is the difference only in one specific request type or in all? If it is only in one go on stop step 8a otherwise step 8b.
- You could create a new class overwriting the format-method of the request. An example where this is done is in the VSNProfile the
format_journey_request
method in thepyhafas.profile.vsn.requests.journey.VSNJourneyRequest
class.- Please make sure the requestBody in your profile is correct. If it is, please
contact </development/introduction>
us or try to find the method causing the error yourself.
If you need help with any of that you can contact </development/introduction>
us always!
Here are the minimum required variables of a profile (generated from ProfileInterface <pyhafas.profile.interface>
):
pyhafas.profile.interfaces.ProfileInterface