Skip to content

Instantly share code, notes, and snippets.

@RussellSenior
Last active June 12, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RussellSenior/82555b8fca4827965f375d04d06df11a to your computer and use it in GitHub Desktop.
Save RussellSenior/82555b8fca4827965f375d04d06df11a to your computer and use it in GitHub Desktop.
(function() {
return {name: "russelltemp"}
})
function go(msg){
if (msg.method == "irc.privmsg") {
var epoch_match = /^!russelltemp(\s+(\S+))$/.exec(msg.params.message)
if(epoch_match) {
var sensor_id = epoch_match[2]
var rows = russelltemp(sensor_id)
var lastrow = rows[rows.length-2]
var datetemp = lastrow.split(' ')
var tempdate = new Date(parseInt(datetemp[0])*1000)
var ago = agowords(tempdate)
var temp = datetemp[1]
bot.say(msg.params.channel, "russell "+sensor_id+" "+ago+" "+temp+"C (from "+JSON.stringify(lastrow)+")")
}
}
}
function russelltemp(id) {
var now = Math.floor(new Date()/1000)
var epoch_today = now - (now % 86400)
var url = "https://klickitat.com/data/"+id+"/"+epoch_today+".log"
bot.say(bot.admin_channel, url)
var rows = http.get(url).split('\n')
return rows
}
function agowords(date) {
var parts = []
var min_ago = (new Date() - date)/1000/60
parts.push(min_ago.toFixed(1))
parts.push('min ago')
return parts.join(' ')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment