LUAS REST Access


Short version – Wrote 2 Powershell commands for finding LUAS times; They can be found on GITHUB. They use 2 web sources., One scrapes https://www.luas.ie/index.php and the other makes REST calls to https://data.dublinked.ie.

More words version with pictures

When we first moved Dublin and started relying on the LUAS for transportation we started checking the times when trains were leaving our stop to work out when to leave the house. Opening a webpage, and clicking on things is like oh my gosh way too much work. I wanted to write a script to run in loop and display times on the Kitchen computer. First time I wrote this I used Fiddler to workout how the Luas.ie page was calling the times and wrote a one liner. The oneline is below broken at the semicolons

$a=1;
do{cls;
write-host -ForegroundColor yellow "Last run" (get-date -Format HH:mm:ss);
$I =Invoke-WebRequest -uri "https://www.luas.ie/index.php?id=346&get=The+Gallops&direction=Inbound";
($i.ParsedHtml.childNodes | select innerText).innertext;
write-host -ForegroundColor red "Next run" (get-date (get-date).AddSeconds(30) -Format HH:mm:ss);
start-sleep -seconds 30}while ($a=1)

luasstops1.JPG

A month or two later I finally found a REST endpoint for BUS and LUAS train data. I used the REST source to write a powershell command around calling https://data.dublinked.ie. The powershell command made the oneliner to loop a bit shorter

$a=1;
do{cls;
write-host -ForegroundColor yellow "Last run" (get-date -Format HH:mm:ss);
Get-LuasTimes -StopID LUAS38 |  ? {$_.origin -like "*brid*"} | fl destination,duetime;
start-sleep -seconds 30}while ($a=1)

luasstops.JPG
When the new stops opened up on the green line in December of 2017 sadly the stops did not show up at my REST data source – https://data.dublinked.ie.

Today is a slow day around the house; I figured I’d add another powershell command to extract the stop information from LUAS.IE in addion to dublinked.  The php webpage at luas.ie requires case sensitive properly spaced stop name. I scraped all of the stop names from the website vis fiddler and built a JSON blob The Blog has short names and long names in it. The command takes short names and converts them to the properly formated long name in the URL request.

luasstops2.JPG

I checked both commands into GITHUB feel free to use them.

Leave a Reply