-
Notifications
You must be signed in to change notification settings - Fork 14
Description
I don't understand how information from get_timetable() and get_timetable_changes() is related. The code example refers to a fairly small station with few connections, even though it is currently part of the Hamburg-Berlin diversion route.
import sys
from deutsche_bahn_api.api_authentication import ApiAuthentication
from deutsche_bahn_api.station_helper import StationHelper
from deutsche_bahn_api.timetable_helper import TimetableHelper
from deutsche_bahn_api.train import Train
from deutsche_bahn_api.train_changes import TrainChanges
client_id = "MyClientID"
API_Key = "MyApiKey"
api = ApiAuthentication(client_id, API_Key)
station_helper = StationHelper()
def list_connections(station):
found_stations_by_name = station_helper.find_stations_by_name(station)
#print(found_stations_by_name)
station = found_stations_by_name[0]
timetable_helper = TimetableHelper(station, api)
trains_in_this_hour = timetable_helper.get_timetable() #List of train objects
print("Scheduled connections:")
for train in trains_in_this_hour:
if hasattr(train, 'departure'): train_departure = train.departure
else: train_departure = "No information"
if hasattr(train, 'arrival'): train_arrival = train.arrival
else: train_arrival = "No information"
if hasattr(train, 'platform'): train_platform = train.platform
else: train_platform = "No information"
print("Ankunft: " + train_arrival + ", Abfahrt: " + train_departure +\
", Bahnsteig: " + train_platform)
print("End of scheduled connections \n\nCurrent plan changes:")
changes = timetable_helper.get_timetable_changes(trains_in_this_hour)
for train in changes:
if hasattr(train, 'departure'): train_departure = train.departure
else: train_departure = "No information"
if hasattr(train, 'arrival'): train_arrival = train.arrival
else: train_arrival = "No information"
if hasattr(train, 'platform'): train_platform = train.platform
else: train_platform = "No information"
print("Ankunft: " + train_arrival + \
", Abfahrt: " + train_departure + \
", Bahnsteig: " + train_platform)
if train.train_changes.messages:
print("Current messages:")
for message in train.train_changes.messages:
print("id: " + message.id + ", message: " + str(message.message) + ", code: " + message.code + ", time: " + message.time)
station = "Salzwedel"
list_connections(station)
Here's the result:
(db) jz@jz-desktop:~$ python /home/jz/Skripte/python/API/bahn_09.py
Scheduled connections:
Ankunft: 2509241009, Abfahrt: 2509241010, Bahnsteig: 2
Ankunft: 2509241056, Abfahrt: 2509241057, Bahnsteig: 2
Ankunft: No information, Abfahrt: 2509241033, Bahnsteig: 4
End of scheduled connections
Current plan changes:
Ankunft: 2509241056, Abfahrt: 2509241057, Bahnsteig: 2
Current messages:
id: r26698222, message: Ohne behindertengerechtes WC, code: 95, time: 2509240244
id: r26698224, message: Ohne behindertengerechtes WC, code: 95, time: 2509240244
id: r26698222, message: Ohne behindertengerechtes WC, code: 95, time: 2509240244
id: r26698224, message: Ohne behindertengerechtes WC, code: 95, time: 2509240244
Ankunft: No information, Abfahrt: 2509241033, Bahnsteig: 4
Ankunft: 2509241009, Abfahrt: 2509241010, Bahnsteig: 2
I have the following questions:
Do you know why is the order of trains different when querying scheduled connections than when querying changed connections? So, how do I know which change information refers to which scheduled connection? Only by comparison of the DB timestamps? That causes other questions, se example for "Augsburg Hbf" at the end of this post.
What does the “time” key in the ‘message’ mean? Is this the time the message was created or is it the time of the connection ('departure')?
Why are there several (always two?) identical messages for a train?
Does the absence of a value for the “arrival” key mean that the connection starts at this station?
The most important question for me is how I can establish a clear connection (unique) between the changed data and the scheduled data for the current hour (or the requested period).
However, I have also noticed that although there is a delay notice in the message, the arrival and departure times are still exactly the same as in the scheduled information. How can I then determine the extent of a delay? Here is an example from Augsburg Hbf (station = "Augsburg Hbf"):
(db) jz@jz-desktop:~$ python /home/jz/Skripte/python/API/bahn_09.py
Scheduled connections:
...
Ankunft: 2509241118, Abfahrt: 2509241122, Bahnsteig: 3
...
Current plan changes:
Ankunft: 2509241118, Abfahrt: 2509241122, Bahnsteig: 3
Current messages:
id: r26745325, message: Verspätung aus vorheriger Fahrt, code: 48, time: 2509241111
id: r26745325, message: Verspätung aus vorheriger Fahrt, code: 48, time: 2509241111
...
Does Deutsche Bahn not disclose the actual delay times?
I hope you can provide me with some information on this (or where can I find more information).