Skip to content

Instantly share code, notes, and snippets.

@jmdfm
Created November 27, 2010 15:43
Show Gist options
  • Save jmdfm/717990 to your computer and use it in GitHub Desktop.
Save jmdfm/717990 to your computer and use it in GitHub Desktop.
Parses the UK National Rail Enquiries JSON data feed for live departures
echo "Trains from HYN to GLQ" && curl --silent \
--user-agent "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7" \
--referer "http://ojp.nationalrail.co.uk/en/s/ldbboard/dep/HYN/GLQ/To" \
"http://ojp.nationalrail.co.uk/en/s/ldb/liveTrainsJson?departing=true&liveTrainsFrom=Hyndland&liveTrainsTo=Glasgow+Queen+Street&serviceId=" \
| sed -e 's/[{"&;/"}]/''/g' | sed -e 's/ltbrgt/-''/g' | \
awk '{n=split($0,a,","); for (i=6; i<=n-2; i++) { printf("%s %-25s %-20s\n",a[i+0],a[i+1],a[i+2]); i+=5}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment