#RenderHack

Stuck for ideas? I opened up some data and stuck an API in front of it so you can hack on your hacks with less frustration.

Train Text

Once upon a time I made a website called https://trntxt.uk. It calls the National Rail SOAP API and gives you back departure times.

National Rail’s API is a faff, so I turned trntxt into a lovely REST API, so you can get your results back in JSON instead of English. Let’s make a chatbot or something.

GET /api/departures/{from}/{to}

The following will return a list of trains departing London Paddington that call at Oxford. The destination is optional.

$ curl https://trntxt.uk/api/departures/paddington/oxford

The response might look something like this

{
  "stations": {
    "fromStation": {
      "stationName": "London Paddington",
      "stationCode": "PAD"
    },
    "toStation": {
      "stationName": "Oxford",
      "stationCode": "OXF"
    }
  },
  "departures": [
    {
      "originStation": {
        "stationName": "London Paddington",
        "stationCode": "PAD"
      },
      "destinationStation": {
        "stationName": "Worcester Foregate Street",
        "stationCode": "WOF"
      },
      "std": "13:22",
      "etd": "On time",
      "platform": "8",
      "operator": "Great Western Railway",
      "sta": "14:17",
      "eta": "On time",
      "arrivalStation": "Oxford",
      "time": "55m"
    },
    {
      "originStation": {
        "stationName": "London Paddington",
        "stationCode": "PAD"
      },
      "destinationStation": {
        "stationName": "Oxford",
        "stationCode": "OXF"
      },
      "std": "13:50",
      "etd": "On time",
      "platform": null,
      "operator": "Great Western Railway",
      "sta": "14:47",
      "eta": "On time",
      "arrivalStation": "Oxford",
      "time": "57m"
    }
  ]
}

Some definitions

  • std: Scheduled Time of Departure
  • etd: Estimated Time of Departure. Either ‘On time’ or the time National Rail thinks it will leave the station. Could also just be ‘Delayed’ or ‘Cancelled’
  • sta: Scheduled Time of Arrival at the destination station
  • eta: Estimated Time of Arrival. Similar to ‘etd’ but for the arrival at the destination.

Something else?

I tried to make a TV schedule API but my server ran out of memory. If you really want it, I can host it through ngrok. It’ll probably be fine.

Advertisements