Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Last active August 29, 2015 14:09
Show Gist options
  • Save donpdonp/7e706d1cc92502fa6859 to your computer and use it in GitHub Desktop.
Save donpdonp/7e706d1cc92502fa6859 to your computer and use it in GitHub Desktop.
neuronbot trimet
function(payload) {
var override = false
if(payload.type == "emessage") {
var match = payload.message.match(/^trimet ([1-9a-z]+)/)
if (match){
var url = 'http://developer.trimet.org/ws/V1/arrivals?locIDs='+match[1]+'&appID='+db.get('trimet:key')
var xml = http.get(url)
var msg = xmlparse(xml)
return "StopID "+match[1]+" #"+msg
}
}
function xmlparse(xml) {
var arrival = xml.match(/<arrival ([^>]+)>/m)[1]
var fullSign = arrival.match(/fullSign=\"([^"]+)\"/)[1]
var estimated = arrival.match(/estimated=\"([^"]+)\"/)
if(estimated) {
fullSign = fullSign + '. '+new Date(parseInt(estimated[1]))
} else {
fullSign = fullSign + '. No next-arrival estimate currently available.'
}
return fullSign
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment