Created
November 8, 2014 17:38
-
-
Save rufo/4ae3dc4f9602bf3e26d1 to your computer and use it in GitHub Desktop.
Quimby's hubot script
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
cheerio = require('cheerio') | |
module.exports = (robot) -> | |
robot.respond /quimby|JBQ/i, (msg) -> | |
robot.http("http://www.jbquimbys.com/menu.php").get() (error, response, body) -> | |
$ = cheerio.load(body) | |
title = cleanText $("td#title").text() | |
body = cleanText $("td#title").parent().next().html() | |
body = body.split(/\<table[ \w\d"=%]+\>/) | |
body = body.map (item) -> cleanItem(item) | |
body = body.join("\n\n") | |
msg.send "*#{title}*#{body}" | |
cleanText = (text) -> | |
cleaned = text | |
cleaned = cleaned.replace /\$ /g, "$$" | |
cleaned = cleaned.replace /\ +/g, " " | |
cleaned = cleaned.replace / /g, "" | |
cleanItem = (item) -> | |
cleaned = cleanText(item) | |
cleaned = cleaned.replace /<b>([\w \/\$.\d-]+)<\/b>/g, "*$1* " | |
cleaned = cleaned.replace /<br ?\/>/g, "" | |
cleaned = cleaned.replace /<\/table>/g, "\n" | |
cleaned = cleaned.replace /<\/?(tr|td|img|\!)[- \w="\/.]*>/g, "" | |
cleaned = cleaned.replace "* *", "* - *" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment