Skip to content

Instantly share code, notes, and snippets.

@andycochrane
Created July 18, 2018 18:51
Show Gist options
  • Save andycochrane/9ea5a024a539803f4f7413d8ea2db457 to your computer and use it in GitHub Desktop.
Save andycochrane/9ea5a024a539803f4f7413d8ea2db457 to your computer and use it in GitHub Desktop.
Open National Rail train times in your default browser.
#!/bin/sh
# I would recommend saving this function in your .bash_profile file or wherever you keep your custom functions.
# Alternatively you could save this in a shell script file.
# The function takes up to 4 arguments. FROM, TO, TIME & DATE. Change the defaults below to whatever suits you.
# With no arguments passed this will get you the next trains between the default (Leeds and Kings Cross) stations.
# This works in a bash shell on Mac OSX. If you are not a Mac user, replace the "open" command with whichever one works on your platform.
# To find the station codes for your station run this:
#####################################################################################################
# curl -s http://www.nationalrail.co.uk/static/documents/content/station_codes.csv | grep '<PLACE>' #
#####################################################################################################
# Example usage with all 4 arguments passed:
##############################
# trains LVC MAN 0728 211015 #
##############################
function trains() {
FROM=${1:-LDS};
TO=${2:-KGX};
TIME=${3:-$(date +%H%M)};
DATE=${4:-today};
URL=http://ojp.nationalrail.co.uk/service/timesandfares/$FROM/$TO/$DATE/$TIME/dep;
open $URL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment