├── README.md ├── getDepartureBoardExample.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | OpenLDBWS Python Example 2 | ======================== 3 | 4 | This repository contains examples of how to use the National Rail Live 5 | Departure Boards Web Service (OpenLDBWS), located at the following URL: 6 | 7 | * https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ 8 | 9 | To use the service, you will need a token which is available by 10 | signing up at the following URL: 11 | 12 | * https://realtime.nationalrail.co.uk/OpenLDBWSRegistration/ 13 | 14 | Edit `getDepartureBoardExample.py` and set `LDB_TOKEN` to your own token. 15 | 16 | Install dependencies using `pip`: 17 | 18 | `pip install -r requirements.txt` 19 | 20 | Running `getDepartureBoardExample.py` will show you departures for 21 | London Euston. 22 | 23 | Updating the WSDL 24 | ----------------- 25 | 26 | Periodically, a new version of the WSDL will be released at: 27 | 28 | * https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ 29 | 30 | This code is written for version 2021-11-01. To update it to use a 31 | later version, edit `getDepartureBoardExample.py` and change the `WSDL` 32 | variable. 33 | 34 | Support 35 | ------- 36 | 37 | This code has been tested on Python 3.12.1. 38 | 39 | For support and questions with using the OpenLDBWS, please use the 40 | forum at the following URL: 41 | 42 | * https://groups.google.com/group/openraildata-talk -------------------------------------------------------------------------------- /getDepartureBoardExample.py: -------------------------------------------------------------------------------- 1 | # 2 | # Open Live Departure Boards Web Service (OpenLDBWS) API Demonstrator 3 | # Copyright (C)2018-2024 OpenTrainTimes Ltd. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | from zeep import Client, Settings, xsd 20 | from zeep.plugins import HistoryPlugin 21 | 22 | LDB_TOKEN = '' 23 | WSDL = 'http://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2021-11-01' 24 | 25 | if LDB_TOKEN == '': 26 | raise Exception("Please configure your OpenLDBWS token in getDepartureBoardExample!") 27 | 28 | settings = Settings(strict=False) 29 | 30 | history = HistoryPlugin() 31 | 32 | client = Client(wsdl=WSDL, settings=settings, plugins=[history]) 33 | 34 | header = xsd.Element( 35 | '{http://thalesgroup.com/RTTI/2013-11-28/Token/types}AccessToken', 36 | xsd.ComplexType([ 37 | xsd.Element( 38 | '{http://thalesgroup.com/RTTI/2013-11-28/Token/types}TokenValue', 39 | xsd.String()), 40 | ]) 41 | ) 42 | header_value = header(TokenValue=LDB_TOKEN) 43 | 44 | res = client.service.GetDepartureBoard(numRows=10, crs='EUS', _soapheaders=[header_value]) 45 | 46 | print("Trains at " + res.locationName) 47 | print("===============================================================================") 48 | 49 | services = res.trainServices.service 50 | 51 | i = 0 52 | while i < len(services): 53 | t = services[i] 54 | print(t.std + " to " + t.destination.location[0].locationName + " - " + t.etd) 55 | i += 1 56 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | zeep>=4.2.0 --------------------------------------------------------------------------------