TrainDelay is a Python package for tracking train delays at various stations using the Deutsche Bahn API. It collects real-time train data, processes delay information, and stores it in a MySQL database for further analysis.
- Fetches train timetable and delay data for specified stations
- Stores train data in a MySQL database
- Logs tracking operations and errors
- Get a MySQL Server running on your machine, the database and tables will be created my the module
- Register for the Deutsche Bahn API (free)
- Create an account at: https://developers.deutschebahn.com
- Create a new application using this url: https://developers.deutschebahn.com/db-api-marketplace/apis/application/new and choose a name that you want
- After that save you the client id and the client secret. You need it to interact with the api
- Navigate to all available apis page at: https://developers.deutschebahn.com/db-api-marketplace/apis/product and select the "Timetables" api
- And click the red subscribe button and select your application
- Now you are done and can start using the api
- Install train_delay using:
pip install train_delay
- import module
from train_delay import *
- Create an AuthData object and a DatabaseConfig object
auth_data = AuthData(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
database_config = DatabaseConfig(YOUR_DB_HOSTNAME, YOUR_DB_USER, YOUR_DB_PASSWORD, YOUR_DATABASE_NAME)
You can choose the YOUR_DATABASE_NAME freely. The module will create the database and necessary table where all trains will be stored.
- Now you can create a TrainDelayTracker object
train_delay_tracker = TrainDelayTracker(auth_data, database_config)
- Track your desired train stations with the track_station() Method
train_delay_tracker.track_station("Bonn")
- API to easily analyse the stored data
- Web-UI to visualize and interact with the stored train delay data
- SQLite support
- Docker Container which immediatly tracks data after startup