Have you ever wondered if the Deutsche Bahn (DB) train you're about to book is usually late or on time? Unfortunately, Deutsche Bahn does not offer any way to check the historical delay statistics for a specific train. This is where Zugspaet comes in.
ZugspΓ€t tracks and analyzes Deutsche Bahn train delays using live data from the DB API. On a webapp, you can then enter your train and see how often it was late or on time in the past!
Check it out: https://zugspaet.de/
2025-03-01.03-06-46.trimmed.mp4
- π Historical delay statistics and visualizations
- πΊοΈ Support for all major German train stations
- π± Responsive web interface
- π Daily data updates
- π Toot toot!
Zu[g]spΓ€t (a play on "Zug" [train] and "spΓ€t" [late]) is a data collection and visualization tool that helps understand Deutsche Bahn train delays:
- Data Collection: Uses the Deutsche Bahn API to periodically fetch real-time train data
- Storage: Stores raw data as XML files and processed data in PostgreSQL
- Processing: Runs nightly jobs to analyze and aggregate delay statistics
- Visualization: Presents the data through an interactive web interface
- Frontend: TypeScript, React, Tailwind CSS
- Backend: Python, Flask
- Database: PostgreSQL
- Infrastructure: Deployed via Dokploy on a Hetzner VM
- Data Processing: Custom Python scripts (forked from deutsche-bahn-data)
- Python 3.11 or higher
- Node.js 20 or higher
- PostgreSQL 16
- Docker and Docker Compose (optional)
- Deutsche Bahn API credentials (API key and Client ID)
-
Clone the repository:
git clone https://github.com/AlexW00/zugspaet.git cd zugspaet -
Create a
.envfile with the following variables:API_KEY=your_db_api_key # Deutsche Bahn API key; requires Timetables & StaDa access CLIENT_ID=your_db_client_id # Deutsche Bahn Client ID PRIVATE_API_KEY=your_private_api_key # Secret used by the backend POSTGRES_PASSWORD=your_db_password BASE_URL=http://localhost:5000 # Optional: Ackee Analytics ACKEE_SERVER_URL=https://your-ackee-server.com ACKEE_DOMAIN_ID=your-domain-id
See ENVIRONMENT.md for a complete list of environment variables.
The easiest way to get started is using Docker Compose:
docker-compose upThis will start all necessary services.
-
Set up the Python environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Set up and build the frontend:
cd frontend npm install npm run build -
Start the development server:
python server.py
-
Initialize the database:
curl -X POST http://localhost:5000/private/api/import \ -H "X-Private-Api-Key: $PRIVATE_API_KEY"
The application will be available at http://localhost:5000.
βββ frontend/ # frontend application
βββ data/ # Raw XML data storage
βββ migrations/ # Database migration scripts
βββ server.py # Main server
βββ fetch_data.py # Data collection script
βββ db_utils.py # Database utilities
βββ docker-compose.yaml # Docker configuration
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
Forked from deutsche-bahn-data by piebro - a collection of Python scripts to fetch and store Deutsche Bahn train data. Without this project, ZugspΓ€t would not be possible!