Last active
June 12, 2019 18:40
-
-
Save donpdonp/0aeb4b7e96d84b0aa98dbcf7a27da3d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 epoch_secs = Date.UTC()/1000 | |
var remainder = epoch_secs % 86400 | |
var epoch_today = epoch_secs - remainder // utc midnight | |
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