Skip to content

Instantly share code, notes, and snippets.

@rufo
Created November 8, 2014 17:38
Show Gist options
  • Save rufo/4ae3dc4f9602bf3e26d1 to your computer and use it in GitHub Desktop.
Save rufo/4ae3dc4f9602bf3e26d1 to your computer and use it in GitHub Desktop.
Quimby's hubot script
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 /&nbsp;/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