Tue, 24 Jul 07

Train times by SMS (or, improving national rail enquiries)

This service is no longer running. Please see this post if you’re interested to find out why.

I was in need of finding some train times at the weekend. I usually use the national rail enquiries website but was without Internet access at the time. Instead, I found myself waiting for about 10 minutes in a telephone queue just to spend about 30 seconds getting the information I was after. This played on my mind a bit so last night I started playing around with automating the national rail timetable search. That was relatively painless so I moved on to integrating with twitter in order to provide an SMS interface to the service. Within a couple of hours I had a twitterbot that receives timetable requests, looks up the times and sends them back to you.

It’s actually currently all up and running. Just follow natrailenq on twitter and I’ll follow you right back1 (this seems to be necessary in order to send direct messages between each other). A timetable request must be of the format ‘origin_station (3 letter short code) destination_station (3 letter short code) depart_date (dd-mmmm) depart_time (hh:mm)’. So, if we wanted to get times of trains from London Victoria (VIC) to Clapham Junction (CLJ) tomorrow midday, we’d send a message like so:

d natrailenq vic clj 25-july 12:00

In this instance, we get the following response back.

natrailenq  11:55->12:02, 12:02->12:07, 12:03->12:09, 12:05->12:11, 12:06->12:11

Cool huh.

The code is nasty. You can see just how nasty it in the repository. It feels as though this could go somewhere – unless I’m violating some terms and conditions that I haven’t read… I make no guarantees as to how long the service will stay live, and I will certainly (probably) remove it if asked to.

1 Well, just as soon as I can at least – it’s not automated at the moment.