Examples - realtime-trains-lang/realtime-trains-py GitHub Wiki
[!TIP]
For different example data, head over to the main branch on the repository and head to the
/examples
folder.In this folder, you'll be able to find a whole range of example code you can run and play with to your heart's desire.
A few examples are provided here:
Advanced (Prettier)
# Import the package
from realtime_trains_py import RealtimeTrainsPy
# Configure the package
rtt = RealtimeTrainsPy(
username="<your_username>"
password="<your_password>"
complexity="a.p"
)
# Get the departures
rtt.get_departures(tiploc = "KNGX")
Example Output
The above command was run at 18:12 (UTC) on 10/01/2025 and provided the following output:
╭──────────────────┬────────────────────┬──────────────────────┬────────────┬──────────────────┬───────────────╮
│ Booked Arrival │ Destination │ Origin │ Platform │ Actual Arrival │ Service UID │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:00 │ London Kings Cross │ Leeds │ 0 │ Exp 18:13 │ C71246 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:02 │ London Kings Cross │ Ely │ 10 │ Exp 18:13 │ W23374 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:05 │ London Kings Cross │ Bradford Interchange │ 1R │ Exp 18:15 │ G26250 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:22 │ London Kings Cross │ York │ 2 │ On time │ C71632 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:21 │ London Kings Cross │ Cambridge │ 8 │ Exp 18:27 │ W23573 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:30 │ London Kings Cross │ Harrogate │ 7 │ Exp 18:31 │ C71248 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:32 │ London Kings Cross │ Kings Lynn │ 10 │ On time │ W23380 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:41 │ London Kings Cross │ Edinburgh │ 6 │ Exp 18:39 │ C71442 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:48 │ London Kings Cross │ Edinburgh │ 5 │ Exp 18:44 │ C71445 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:51 │ London Kings Cross │ Cambridge │ 8 │ Exp 18:50 │ W23578 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:00 │ London Kings Cross │ Leeds │ 3 │ Exp 18:57 │ C71251 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:02 │ London Kings Cross │ Kings Lynn │ 9 │ Exp 19:01 │ W23385 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:06 │ London Kings Cross │ Sunderland │ 1F │ On time │ G26248 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:22 │ London Kings Cross │ Lincoln Central │ 0 │ Exp 19:19 │ C71302 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:23 │ London Kings Cross │ Welwyn Garden City │ 9 │ On time │ W23581 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:30 │ London Kings Cross │ Leeds │ 4 │ Exp 19:28 │ C71254 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:32 │ London Kings Cross │ Kings Lynn │ 10 │ Exp 19:31 │ W23392 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:38 │ London Kings Cross │ Edinburgh │ 2 │ Exp 19:36 │ C71448 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:44 │ London Kings Cross │ Hull │ 5 │ Exp 19:43 │ N35973 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:49 │ London Kings Cross │ Edinburgh │ 3 │ Exp 19:51 │ C71451 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:50 │ London Kings Cross │ Cambridge │ 9 │ Exp 19:49 │ W23585 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:01 │ London Kings Cross │ Leeds │ 6 │ Exp 20:03 │ C71257 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:02 │ London Kings Cross │ Kings Lynn │ 10 │ Exp 20:01 │ W23398 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:20 │ London Kings Cross │ Cambridge │ 9 │ Exp 20:19 │ W23588 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:22 │ London Kings Cross │ York │ 7 │ Exp 20:21 │ C71634 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:28 │ London Kings Cross │ Harrogate │ 4 │ Exp 20:25 │ C71260 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:32 │ London Kings Cross │ Kings Lynn │ 10 │ Exp 20:31 │ W23404 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:38 │ London Kings Cross │ Edinburgh │ 1 │ Exp 20:35 │ C71454 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:44 │ London Kings Cross │ Edinburgh │ 5 │ Exp 20:43 │ G26167 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:50 │ London Kings Cross │ Cambridge │ 9 │ Exp 20:49 │ W23592 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:53 │ London Kings Cross │ Edinburgh │ 0 │ Exp 20:50 │ C71457 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 20:59 │ London Kings Cross │ Leeds │ 2 │ Exp 20:57 │ C71263 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:02 │ London Kings Cross │ Kings Lynn │ 10 │ Exp 21:01 │ W23408 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:06 │ London Kings Cross │ Sunderland │ 6 │ Exp 21:05 │ G26253 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:20 │ London Kings Cross │ Cambridge │ 9 │ Exp 21:19 │ W23595 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:29 │ London Kings Cross │ Leeds │ 1 │ Exp 21:26 │ C71266 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:32 │ London Kings Cross │ Kings Lynn │ 8 │ Exp 21:31 │ W23414 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:39 │ London Kings Cross │ Edinburgh │ 2 │ Exp 21:36 │ C71460 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:47 │ London Kings Cross │ Hull │ 4 │ Exp 21:46 │ C45779 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 21:50 │ London Kings Cross │ Cambridge │ 10 │ Exp 21:49 │ W23599 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 22:00 │ London Kings Cross │ Leeds │ 6 │ Exp 21:57 │ C71270 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 22:02 │ London Kings Cross │ Kings Lynn │ 9 │ Exp 22:01 │ W23418 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 22:08 │ London Kings Cross │ Aberdeen │ 0 │ Exp 22:05 │ C71463 │
╰──────────────────┴────────────────────┴──────────────────────┴────────────┴──────────────────┴───────────────╯
Simple (Normal)
# Import the package
from realtime_trains_py import RealtimeTrainsPy
# Configure the package
rtt = RealtimeTrainsPy(
username="<your_username>"
password="<your_password>"
complexity="s.n"
)
# Get the arrivals
arrivals = rtt.get_arrivals(tiploc = "LEEDS", date = "2025/01/10")
for arrival in arrivals:
# Print the details
print(f"{arrival.service_uid} | {arrival.gbtt_arrival} | {arrival.origin} to {arrival.terminus}")
Example Output
The above command was run at 18:15 (UTC) on 10/01/2025 and provided the following output:
W47683 | 23:54 | York to Leeds
W45825 | 00:03 | Blackpool North to Leeds
P13154 | 23:57 | Redcar Central to Manchester Victoria
W46174 | 00:09 | Manchester Victoria to Leeds
C71394 | 00:12 | London Kings Cross to Leeds
P13844 | 00:15 | Huddersfield to York
W47230 | 00:22 | Doncaster to Leeds
P13842 | 00:22 | Selby to Leeds
P13055 | 00:15 | Scarborough to Manchester Piccadilly
P13837 | 00:24 | Huddersfield to Leeds
W49477 | 00:27 | Sheffield to Leeds
C58575 | 00:32 | Leeds Bradford Airport to Leeds
P13162 | 00:15 | Manchester Airport to York
N36168 | 00:39 | Bradford Interchange to Leeds
W52371 | 00:41 | Selby to Leeds
W46021 | 00:45 | Manchester Victoria to Leeds
W52379 | 00:50 | York to Leeds
C71475 | 00:57 | Aberdeen to Leeds
N36171 | 01:15 | Halifax to Leeds
P13839 | 01:24 | Huddersfield to Leeds
P13166 | 01:19 | Manchester Airport to York
C71397 | 02:17 | London Kings Cross to Leeds
P12947 | 02:08 | York to Manchester Victoria
P12942 | 02:05 | Manchester Victoria to York
P12954 | 03:13 | York to Manchester Airport
P12950 | 04:13 | Manchester Piccadilly to York
C58453 | 05:37 | Leeds Bradford Airport to Leeds
P13060 | 05:40 | York to Manchester Victoria
P12957 | 05:50 | Manchester Victoria to Scarborough
C58459 | 06:07 | Leeds Bradford Airport to Leeds
P13064 | 06:11 | Manchester Victoria to Redcar Central
P12959 | 06:11 | York to Manchester Victoria
W49794 | 06:24 | Bradford Forster Square to Leeds
W48419 | 06:27 | Skipton to Leeds
W48937 | 06:24 | Selby to Halifax
P13233 | 06:30 | Huddersfield to Leeds
P13747 | 06:22 | Newcastle to Liverpool Lime Street
W49277 | 06:31 | Sheffield to Leeds
P12799 | 06:22 | Manchester Victoria to Hull
W50611 | 06:33 | Ilkley to Leeds
W49210 | 06:40 | Sheffield to Leeds
W48405 | 06:39 | Hebden Bridge to Leeds
C58462 | 06:40 | Leeds Bradford Airport to Leeds
[... *some output data has been removed due to size*]