Skip to content

Instantly share code, notes, and snippets.

@bkeating
Created September 2, 2014 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeating/37f46c39aae1f6151ef2 to your computer and use it in GitHub Desktop.
Save bkeating/37f46c39aae1f6151ef2 to your computer and use it in GitHub Desktop.
East Troy's 2894 On Main cafe [food] menu for Hubot.
# Description:
# East Troy's 2894 On Main cafe [Food] menu for Hubot.
#
# Dependencies:
# "cheerio: "0.7.0"
#
# Configuration:
# None
#
# Commands:
# hubot (breakfast|lunch|full) menu - displays this weeks menu
#
# Author:
# bkeating
cheerio = require('cheerio')
module.exports = (robot) ->
robot.hear /(breakfast|lunch|full) menu/i, (msg) ->
name = msg.match[1].trim()
menu(msg, name)
menu = (msg, name) ->
msg
.http("https://s3.amazonaws.com/bpk-disk/2894Menu.html")
.header("Mozilla/1.22 (compatible; MSIE 2.0; Windows 3.1)")
.get() (err, res, body) ->
msg.send "#{getMenu body,name}"
getMenu = (body, name) ->
$ = cheerio.load(body, {ignoreWhitespace: false })
weekOf = $('h2').text()
# Count how many items each menu has
breakfastCount = $('#breakfast').children().length
lunchCount = $('#lunch').children().length
if name == "breakfast"
itemArray = $('#breakfast').find('tr')
else if name == "lunch"
itemArray = $('#lunch').find('tr')
else if name == "full"
itemArray = $('body').find('table tr')
# Slack will beautify lines prepended with a greater-than symbol
menuResult = itemArray.text().replace(/(.+)/g, "> $1")
"Cafe menu for the #{weekOf}: \n#{menuResult}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment