Skip to content

Extract, store and present the current GPS position and train speed (in km/h) of DB IC/ICE trains

License

Notifications You must be signed in to change notification settings

maehw/db-ice-localizer-speedometer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

The Python script extract.py extracts the current GPS position and train speed (in km/h) from the map publicly accessible in Deutsche Bahn's ICE Portal, hence the name of the repository. It works when being connected to the train's WiFi but independent of your device's position sensor. The data is parsed periodically (every 10 seconds) and stored to a CSV file for further analysis.

ICE Portal Karte

⬇️

CSV snippet

To improve precision of GPS coordinates, zoom to the maximum zoom level by pressing the magnifying glass symbol.

Zoom level widget

You can also run the second Python script serve.py using Flask in addition. It will serve the extracted data on your own website from the latest logged CSV data. Please note that it must be started using flask --app serve run (python serve.py would immediately finish execution and return).

$ flask --app serve run
 * Serving Flask app 'serve'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
...

Use your favorite web browser and go to the URL listed in the console output: http://127.0.0.1:5000

Flask server

How does it work?

This script automatically opens the Firefox web browser at https://iceportal.de/Karte_neu and automatically scrapes the train's speed and GPS position. Deutsche Bahn uses OpenStreetMap in the background. The same URL slippy map tilenames format is used for the tile URLs:

Comparison of maps

The GPS coordinates as latitude and longitude in degrees are re-calculated from the dynamically loaded map tiles' URLs. There's no overhead in communication added by this script - so no additional queries, just using the available data from the browser.

The scraping is done using Selenium WebDriver for Firefox. The elements are specified using XPath syntax (and is subject to change as soon as Deutsche Bahn decides to change their content layout).

The script also stores some 3D transformation positions that could be used to add precision to the GPS coordinates by using the extracted values for correction.

Prerequisites

  • Working Python3 environment with the Selenium module installed.
  • Have Firefox web browser installed (script can likely be rewritten for other web browsers).
  • Be on a Deutsche Bahn ICE or Intercity (long-distance) train on your way across Germany.
  • Manually connect to WiFi with "WIFIonICE" and browse to "ICEportal.de" in your web browser.

Future ideas

You could also ...

  • extract and store internet connectivity status and forecast along your journey.
  • extract and store shown delays in scheduled arrival times along your journey.
  • add a quick check-in function for Träwelling.