Skip to content
This repository has been archived by the owner on Jul 13, 2019. It is now read-only.

rijdendetreinen/rdt-serviceinfo

Repository files navigation

This project has been abandonded, switch to GoTrain

This project has been abandonded, as AR-NU has been discontinued as a data source by NS. Please switch to GoTrain for a modern implementation in Go which processes InfoPlus data

RDT Serviceinfo

GitHub release Build Status codecov.io Code Climate Scrutinizer Code Quality

RDT Serviceinfo is a tool for parsing and distributing information about transport services, both scheduled information and real-time information.

This tool is developed for open data provided by the Dutch Railways (NS). RDT Serviceinfo has the following features:

  • Provides HTTP interface to query the actual transport schedule
  • Load a schedule into Redis
  • Parse real-time service updates
  • Support for complex service types (combined trains)

RDT Serviceinfo can be used as a source for feeding departure boards, to provide additional information about train services, to fill historical archives, and more.

Status

RDT Serviceinfo is used by Rijden de Treinen.nl to supplement real-time departure information with additional information. It is being used by thousands of travellers each day and running in production since July 2015.

The current release of RDT Serviceinfo is stable.

Installation

This software is tested on Debian and Ubuntu Linux, but it should work on any Linux distribution.

You'll need a MySQL server and a Redis instance (not necessarily installed on the same machine). A MySQL database is used to store the complete schedule (called the IFF dataset). The Redis instance is used to lookup today's schedule and to store real-time updates about train services.

To install, run through the following steps:

  1. Install the required Python modules. For Debian and Ubuntu, run:
    apt-get install python-argparse python-bottle python-isodate python-lxml python-mysqldb python-redis python-tz python-zmq
  2. Download or clone this repository to a directory of your choice, git clone git@github.com:geertw/rdt-serviceinfo.git.
  3. Copy the .dist files in the config directory and edit them to match your details. At least, you need to configure the MySQL and Redis connection details.
  4. Download the IFF files and unpack them, the default folder in the converter script is cache/dataset
  5. Convert the IFF files by running iff-converter.py
  6. Create the database and import the IFF dataset by running iff-loader.py --create_tables
  7. Load the current schedule by running scheduler.py.
  8. Receive status updates by running arnu-listener.py (in the background, if working correctly).
  9. Provide an HTTP interface by running http-server.py (for testing/debugging usage), or by configuring a WSGI server like uWSGI (for production usage). Set it up to serve http.wsgi.

Keeping the schedule up-to-date

  1. Set up cronjobs to run cleanup.py and scheduler.py regularly. Both should run once a day.
    • cleanup.py removes old schedules from your Redis database.
    • scheduler.py loads the schedule for today in your Redis database.
  2. Refresh your IFF dataset at least weekly.
    • Make sure the MySQL user in your configuration file has permissions to truncate tables and insert data.
    • Use the script in contrib/ndov/new-iff.sh to download and process IFF datasets from NDOVloket.
    • The script automatically updates your MySQL database when a new IFF dataset is detected.

Access to static and realtime schedules

Note that you'll need access to both the static schedule and a ZeroMQ server distributing service updates. You can get a free subscription by signing up with NDOVloket.

From NDOVloket, you need:

  • The NS IFF dataset, which contains the (static) train schedule for the whole year.
    NDOVloket provides the IFF dataset as a zip file containing all required source files.
  • AR-NU Ritinfo. AR-NU provides you with realtime updates about delayed trains, cancelled trains, etc.
    NDOVloket provides the AR-NU message feed via ZeroMQ.

It is recommended to not connect directly to NDOVloket's ZeroMQ server, but use some middleware instead called universal-sub-pubsub.

License

Copyright (c) 2015-2016 Geert Wirken

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.