โ† Back to Transportation
Transportation by @jabbslad

uk-trains

Query UK National Rail live departure boards, arrivals, delays

0
Source Code

UK Trains

Query National Rail Darwin API for live train departures and arrivals.

Setup

Requires free Darwin API token:

  1. Register at https://realtime.nationalrail.co.uk/OpenLDBWSRegistration/
  2. Set NATIONAL_RAIL_TOKEN in 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 Paddington
  • EUS = London Euston
  • KGX = London Kings Cross
  • VIC = London Victoria
  • WAT = London Waterloo
  • MAN = Manchester Piccadilly
  • BHM = Birmingham New Street
  • EDB = Edinburgh Waverley
  • GLC = Glasgow Central
  • BRI = Bristol Temple Meads
  • LDS = Leeds
  • LIV = Liverpool Lime Street
  • RDG = Reading
  • OXF = Oxford
  • CBG = Cambridge

Response Format

JSON with:

  • locationName, crs - Station info
  • messages[] - Service alerts
  • trainServices[] - List of trains:
    • std/sta - Scheduled departure/arrival time
    • etd/eta - Expected time ("On time", "Delayed", or actual time)
    • platform - Platform number
    • operator - Train operating company
    • destination[].name - Final destination
    • isCancelled, 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:

  1. departures {origin} to {dest} โ€” get departure times + service IDs
  2. arrivals {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)