Tutorialwork / deutsche_bahn_api

This is a package to interact with the Deutsche Bahn timetables api
https://pypi.org/project/deutsche-bahn-api
GNU General Public License v3.0
9 stars 9 forks source link

Feature Request: allow passing of date to `get_timetable` #2

Closed jaecktec closed 1 year ago

jaecktec commented 1 year ago

It would be nice to specify a day. So the code could be changed to something like this:

 def get_timetable_xml(self, hour: Optional[int] = None, date: Optional[datetime] = datetime.now()) -> str:
        hour_date: datetime = date
        if hour:
            hour_date = datetime.strptime(str(hour), "%H")
        date: str = datetime.now().strftime("%y%m%d")
        hour: str = hour_date.strftime("%H")
        response = requests.get(
            f"https://apis.deutschebahn.com/db-api-marketplace/apis/timetables/v1"
            f"/plan/{self.station.EVA_NR}/{date}/{hour}",
            headers=self.api_authentication.get_headers()
        )
        return response.text

    def get_timetable(self, hour: Optional[int] = None,  date: date: Optional[datetime] = None) -> list[Train]:
        train_list: list[Train] = []
        trains = elementTree.fromstringlist(self.get_timetable_xml(hour, date))
jaecktec commented 1 year ago

Just noticed, this api has no historic data :(