Last active
February 10, 2022 21:05
-
-
Save donpdonp/75fec4b24d2abb367090e12b58cfadbb to your computer and use it in GitHub Desktop.
gluon oregon state executive orders
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() { | |
setup() | |
return { | |
name: "oregonorders" | |
} | |
}) | |
var alert_channel = "#portlandor" | |
var orders = [] | |
function setup() { | |
register_freshen(bot.admin_channel) | |
} | |
function go(msg) { | |
if(msg.method == "irc.privmsg") { | |
var cmd = /^\!oo(\s+(.+))?$/ | |
var match = cmd.exec(msg.params.message) | |
if(match){ | |
register_freshen(msg.channel) | |
report(msg.params, match[2]) | |
} | |
} | |
if(msg.method == "clocktower" && (new Date(msg.params.time)).getMinutes() == 0){ | |
register_freshen(alert_channel) | |
} | |
} | |
function report(params) { | |
var order = orders[0] | |
bot.say(params.channel, "last Oregon executive order: "+ | |
"#"+order.number + " " + order.title) | |
bot.say(params.channel, order.url) | |
} | |
function register_freshen(channel) { | |
/* | |
<li class="gov-category-2020" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"> | |
<a class="or-rte-noIcon" href="/gov/Documents/executive_orders/eo_20-12.pdf">Executive Order 20-12</a> | |
Stay Home, Save Lives: Ordering Oregonians to Stay at Home, Closing Specified Retail Businesses, Requiring Social Distancing Measures for Other Public and Private Facilities, and Imposing Requirements for Outdoor Areas and Licensed Childcare Facilities | |
</li> | |
*/ | |
var url = 'https://www.oregon.gov/gov/admin/Pages/executive-orders.aspx' | |
try { | |
var html = http.get(url).replace(/\n/g,"").replace(/\r/g,"") | |
var parts = html.split('li class="gov-category') | |
var new_orders = parts.slice(1,parts.length).map(function(part){ | |
var data = {} | |
var oo = /a[^>]+href=\"([^"]+?([-\d]+)[^"]+?)\".*\/a>([^<]+)</.exec(part) | |
if (oo) { | |
data.url = 'https://www.oregon.gov'+oo[1] | |
data.number = oo[2] | |
data.title = oo[3] | |
} | |
return data | |
}) | |
if (orders.length > 0) { | |
if (new_orders.length > 0) { | |
var newest = orders[0].number | |
var newester = new_orders[0].number | |
if (newester > newest) { | |
bot.say(channel, "new Oregon excutive order #"+new_orders[0].number+": "+new_orders[0].title) | |
bot.say(channel, new_orders[0].url) | |
} | |
orders = new_orders | |
} else { | |
//bot.say(bot.admin_channel, "oregon executive order found 0 ") | |
} | |
} else { | |
bot.say(channel, "Oregon orders count "+new_orders.length+" initialized "+JSON.stringify(new_orders[0])) | |
orders = new_orders | |
} | |
} catch(e) { | |
bot.say(bot.admin_channel, "oregon executive order query failed "+e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment