Source Code
UK Trains
Query National Rail Darwin API for live train departures and arrivals.
Setup
Requires free Darwin API token:
- Register at https://realtime.nationalrail.co.uk/OpenLDBWSRegistration/
- Set
NATIONAL_RAIL_TOKENin environment (or configure in skills.entries.uk-trains.apiKey)
Commands
# Departures
./scripts/trains.py departures PAD
./scripts/trains.py departures PAD to OXF --rows 5
# Arrivals
./scripts/trains.py arrivals MAN
./scripts/trains.py arrivals MAN from EUS
# Station search
./scripts/trains.py search paddington
./scripts/trains.py search kings
Station Codes
Use 3-letter CRS codes:
PAD= London PaddingtonEUS= London EustonKGX= London Kings CrossVIC= London VictoriaWAT= London WaterlooMAN= Manchester PiccadillyBHM= Birmingham New StreetEDB= Edinburgh WaverleyGLC= Glasgow CentralBRI= Bristol Temple MeadsLDS= LeedsLIV= Liverpool Lime StreetRDG= ReadingOXF= OxfordCBG= Cambridge
Response Format
JSON with:
locationName,crs- Station infomessages[]- Service alertstrainServices[]- List of trains:std/sta- Scheduled departure/arrival timeetd/eta- Expected time ("On time", "Delayed", or actual time)platform- Platform numberoperator- Train operating companydestination[].name- Final destinationisCancelled,cancelReason,delayReason- Disruption info
Message Template
Use this compact format for WhatsApp/chat responses:
๐ {Origin} โ {Destination}
*{dep} โ {arr}* โ๐{platform} โ ๐ {coaches}
{status}
*{dep} โ {arr}* โ๐{platform} โ ๐ {coaches}
{status}
Elements
- Header: ๐ emoji + origin โ destination
- Time: Bold, departure โ arrival times
- Platform: ๐ + number (or "TBC" if unknown)
- Coaches: ๐ + space + number
- Status:
- โ On time
- โ ๏ธ Delayed (exp {time})
- โ Cancelled โ {reason}
- ๐ Starts here
Example
๐ Hemel Hempstead โ Euston
*20:18 โ 20:55* โ๐4 โ ๐ 4
โ
On time
*20:55 โ 21:30* โ๐4 โ ๐ 12
โ
On time
*21:11 โ 21:41* โ๐4 โ ๐ 8
โ
On time
Getting Arrival Times
To show arrival times, make two API calls:
departures {origin} to {dest}โ get departure times + service IDsarrivals {dest} from {origin}โ get arrival times
Match services by the numeric prefix in serviceID (e.g., 4748110HEMLHMP_ matches 4748110EUSTON__).
Notes
- Separate each service with a blank line
- Omit coaches if formation data unavailable
- For delays, show expected time:
โ ๏ธ Delayed (exp 20:35)