Timetables or Web snippets

Does anyone know how to I would go about setting up a Siri Shortcut to show me a snippet of a timetable from the below link? I would either like to use scriptable to either show the timetable or for Siri to read it to me. I thought I had a basic understanding but, I can’t work it out?

http://m.nationalrail.co.uk/pj/ldbboard/dep/DSY/MCV/TO

You might actually want to look at Scriptable for this. The “is Slack down” example shows part of the slack status webpage which is what you want :slight_smile:

Thanks Rosemary, I will play around with it a bit😎

The National Rail site is dynamically generating the page and for me, if I try just try to grab the content of the URL in Shortcuts with a GET, then I get a submission form page structure rather than a results page.

If I do a similar thing with Scriptable using the following, I unsurprisingly get a rather similar result.

//Request the URL
let req = new Request("http://m.nationalrail.co.uk/pj/ldbboard/dep/DSY/MCV/TO");
let retHTML = await req.loadString();

//Now we'll put that output in a few places so we can review it...

//Show the result of what we returned (not the live URL)
WebView.loadHTML(retHTML)
//Put the result in the console log
console.log(retHTML);
//For convenience also save it to a file so we can review in a file editor
const consolePath = "/var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/console_output.txt";
let fmLocal = FileManager.local();
let result = fmLocal.writeString(consolePath, retHTML);

I did a search of the text file in Textastic just to be sure the data wasn’t in there somewhere, but found no instances of “Daisy” or “Manchester”.

Perhaps there’s a way to force it to return the processed page, but if it relies upon evaluating any of the numerous JavaScript instances on the page then that would be an issue. As Simon noted on another thread, “Scriptable doesn’t run JavaScript n the context of a website”.

However, National Rail’s data is taken predominantly from the Darwin engine which has an API and in fact there are many APIs around UK transport. To that end I’ve put together a quick example that might get you most of if not all the way to what you need using Shortcuts. You could certainly reproduce this in Scriptable.

First of all, go and make yourself a free account over at transportapi.com. You are going to need your own app ID and app API key. These codes should be entered into the dictionary object at the start of the custom shortcut.

The API uses CRS (Computer Reservation System) codes as unique identifiers for rail stations. crs_board is where you plan to board and crs_alight is where you plan to alight/disembark. I’ve pre-populated these with your stations in the example,but you can get a list of all current CRS codes here in case other codes would be useful.

There are a couple of other dictionary keys to note. The darwin key is simply set to true as a flag to the API we would like to use the latest information available fro Darwin. The offset key is set to have a 45 minute window (hh:mm:ss) for departures. You can amend that to be whatever you like.

You can see in the text entry above how the URL is constructed using parameters/placeholders taken from the dictionary.

The remainder of the custom shortcut processes the JSON that is returned. It is processed as a dictionary but the results are a couple of levels deep. Each output set is then constructed from the results.

Each set is then either shown as results, and/or are spoken by Siri depending upon how you invoke it.

All that remains is to share the custom shortcut - Shortcut - UK Rail Station Departures.

Hope something in that helps.

1 Like

I just noted that those results don’t actually show any platforms on them, but just to prove that bit does work if the platform info is available, here’s Manchester Victoria to York just now…

1 Like

You went to town on this one! Very much appreciated indeed. I will have a go at this shortly when I get in and let you know how I get on😎

This is a very old thread but it’s a great shortcut. I’ve got it working, but the API key from transportapi seems to be a 30 day trial only. Anyone know whether it will stop working after the 30 days or if there’s another way to get small-scale (personal) use from this service as it’s really useful!

Thanks.

See their blog post on the change.

https://www.transportapi.com/blog/2021/08/transportapi-evolves-the-free-offer/