Last active
May 23, 2023 03:21
-
-
Save donpdonp/4a57f7bd1a1fd87d2d951409694874d9 to your computer and use it in GitHub Desktop.
gluon ecoli report
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: "ecoli"} | |
}) | |
var dbkey = "ecoli" | |
var url = 'https://www.portlandoregon.gov/bes/waterquality/results.cfm?location_id=7132' | |
var state | |
function setup() { | |
db.get(dbkey, function(json) { | |
try { | |
state = JSON.parse(json) | |
bot.say(bot.admin_channel, "ecoli loaded. count "+state.count) | |
} catch(e) { | |
bot.say(bot.admin_channel, "ecoli decode failed. resetting") | |
state = {count: 0, date: 0} | |
save() | |
} | |
}) | |
} | |
function save() { | |
db.set(dbkey, JSON.stringify(state), function(result){ | |
if (!result) { | |
bot.say(bot.admin_channel, "ecoli state save err: "+e) | |
} | |
}) | |
} | |
function go(msg) { | |
if (msg.method == "clocktower") { | |
var time = new Date(Date.parse(msg.params.time)) | |
if (time.getMinutes() % 10 == 0) { | |
//clock_watches() | |
} | |
} | |
if (msg.method == "irc.privmsg") { | |
var cmd_match = /!ecoli/.exec(msg.params.message) | |
if (cmd_match) { | |
var words = report(msg) | |
if (!words) { | |
words = "no data found. check "+url | |
} | |
bot.say(msg.params.channel, words) | |
} | |
} | |
} | |
function report(msg) { | |
var html = http.get(url) | |
var bluecell = /td class=\"bluecell[^>]+\>\s+(\d+\/\d+\/\d+)\D+(\d+\.\d*)\D+(\d+)/.exec(html) | |
if (bluecell) { | |
return "Willamette at Riverplace Marina "+bluecell[1]+" "+bluecell[2]+"F "+bluecell[3]+" ecoli organisms per 100ml" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment