Created
December 13, 2018 23:34
-
-
Save heaversm/000417a06ef8d9e907a7f6684d08f185 to your computer and use it in GitHub Desktop.
Query the Portland Oregon Trimet Arrivals by Stop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $arrivals = $('.arrivals'); | |
let arrivalInterval; | |
window.onload = function(){ | |
getArrivals(); | |
pollForArrivals(); | |
} | |
pollForArrivals = function(){ | |
arrivalInterval = setInterval(getArrivals,60000); | |
} | |
getArrivals = function(){ | |
$arrivals.empty(); | |
$.ajax({ | |
url: "https://developer.trimet.org/ws/V1/arrivals/locIDs/5901/appID/[YOUR_APP_ID]?json=true", | |
}).done(function(data) { | |
// console.log(data); | |
const arrivals = data.documentElement.getElementsByTagName('arrival'); | |
//console.log(arrivals); | |
for (let i=0;i<arrivals.length;i++){ | |
const arrival = arrivals[i]; | |
const estimatedArrivalTime = arrival.attributes.estimated.value; | |
const m = moment(parseInt(estimatedArrivalTime)).format("HH:mm"); | |
console.log(m); | |
const $arrival = `<div class='arrival'>${m}</div>`; | |
$('.arrivals').append($arrival); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment