Last active
June 12, 2019 17:31
-
-
Save RussellSenior/82555b8fca4827965f375d04d06df11a to your computer and use it in GitHub Desktop.
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
(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