Skip to content
The codebase used for Imports bus timetable data from traveline into a database format which allows efficient queries, including a GeoJSON API endpoint and Leaflet map.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Traveline Data Viewer

This project assists you to display bus timetable data on a map, and is used by

This project:

  • dsecribes where to find the data you need
  • has scripts which put that data in a database
  • has code to provide that data in GeoJSON format over an API
  • has code for the front-end

What to do

Set up the server

apt-get install \
	git \
	apache2 libapache2-mod-wsgi-py3 dehydrated \
	postgresql \
	python3 python3-psycopg2 python3-flask python3-lxml
adduser --system --shell=/bin/bash --disabled-password travelinedata

Make an apache config, see example_apache.conf

Set up Lets Encrypt: vim /etc/dehydrated/domains.txt and dehydrated -c

Make a new database:

sudo -u postgres createuser "travelinedata"
sudo -u postgres createdb travelinedata -O "travelinedata"
sudo -u postgres psql travelinedata -c 'CREATE SCHEMA travelinedata;'
sudo -u postgres psql travelinedata -c "GRANT ALL ON SCHEMA travelinedata TO travelinedata;"
sudo -u postgres psql travelinedata -c "ALTER USER travelinedata SET search_path TO 'travelinedata';"

Importing data from fresh

Delete all old data and create a new schema

python3 -m tlparser --destroy_create_tables

Add location of bus stops, by adding files to naptandata/ and

python3 -m tlparser --naptan

Add location about postcodes, see postcodes/

Add timetable data, by adding files to travelinedata/ and

python3 -m tlparser --process

Transactions are committed after every xml file, so killing --process with Ctrl+C is fine.

Calculate or re-calculate data tabes which are calculated from these values by

python3 -m tlparser --generate --matview

Run the server (which uses flask, so you should probably deploy that properly like a normal flask site):



Copyright (C) 2018 David Batley

This file is part of Foobar.

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
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 <>.

A copy of the source code is available at

You can’t perform that action at this time.