FahrplanDatenGarten / pyhafas

A python client for the HAFAS (HaCon Fahrplan Auskunfts System)
https://pyhafas.readthedocs.io
MIT License
46 stars 19 forks source link

Missing key 'dirTxt' #48

Open Avonik opened 2 weeks ago

Avonik commented 2 weeks ago

import datetime, csv import time

import pytz # Ensure you have pytz installed from pyhafas import HafasClient from pyhafas.profile import DBProfile, VSNProfile

client = HafasClient(DBProfile(), debug=True)

    departures = client.departures(
        station=client.locations("Lüneburg")[0],
        date=datetime.datetime(2024, 10, 14, 13, 41),
        max_trips=2,
        products={
            'long_distance_express': False,
            'regional_express': False,
            'regional': True,
            'suburban': False,
            'bus': False,
            'ferry': False,
            'subway': False,
            'tram': False,
            'taxi': False,

        }
    )

Trying to get the departures generates a Key Error in this specific case when encountering this substitution for a canceled train:

image

Avonik commented 2 weeks ago

"dixTxt" seems to be used to determine the "direction" of the train. Since I dont use it for my case I fixed it by adding a check in the pard_station_board_request method

            try:
                direction = raw_leg['dirTxt']
            except KeyError:
                raw_leg['dirTxt'] = "Unknown Direction"