Skip to content

Instantly share code, notes, and snippets.

@mchail
Created April 15, 2014 07:29
Show Gist options
  • Save mchail/10710322 to your computer and use it in GitHub Desktop.
Save mchail/10710322 to your computer and use it in GitHub Desktop.
Hubot Deliboard plugin
# Description:
# Prints today's deliboard menu
#
# Dependencies:
# "cheerio" : "https://github.com/cheeriojs/cheerio",
#
# Commands:
# deliboard menu
#
# Notes:
#
# Author:
# mchail
http = require 'http'
cheerio = require 'cheerio'
module.exports = (robot) ->
robot.hear /deliboard menu/i, (msg) ->
parseMenu = (html) ->
$ = cheerio.load html
today = $('#content > div:first-child')
menu = {
date: today.find('small').text(),
sandos: []
}
found = false
for el in today.find('.entry > p')
$el = $(el)
if found
menu.sandos.push $el.text()
if $el.text() == "sandos"
found = true
menu
formatMessage = (obj) ->
([obj.date].concat obj.sandos).join("\n")
http.get 'http://www.deliboardsf.com/the-board/', (res) ->
body = ""
res.setEncoding 'utf8'
res.on 'data', (chunk) ->
body += chunk
res.on 'end', ->
msg.send formatMessage parseMenu(body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment