Skip to content

Instantly share code, notes, and snippets.

@heaversm
Created December 13, 2018 23:34
Show Gist options
  • Save heaversm/000417a06ef8d9e907a7f6684d08f185 to your computer and use it in GitHub Desktop.
Save heaversm/000417a06ef8d9e907a7f6684d08f185 to your computer and use it in GitHub Desktop.
Query the Portland Oregon Trimet Arrivals by Stop
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