Skip to content

Instantly share code, notes, and snippets.

@Mekajiki
Created February 24, 2015 13:09
Show Gist options
  • Save Mekajiki/c313348710a1753d6a4f to your computer and use it in GitHub Desktop.
Save Mekajiki/c313348710a1753d6a4f to your computer and use it in GitHub Desktop.
# Description:
# A way to retrieve shop information of ネオ屋台村
#
# Commands:
# hubot yatai - answer today's yatai-village menu
# hubot yatai <village name> - search village and list today's yatai-village menu
request = require 'request'
cheerio = require 'cheerio'
cron = require('cron').CronJob
module.exports = (robot) ->
new cron '0 0 11 * * 1-5', () =>
searchVillages '東大本郷', (message) ->
robot.send {room: "#meshi"}, message, null, true, "Asia/Tokyo"
robot.hear /yatai$/, (msg) ->
parseUrl 'http://www.w-tokyodo.com/neostall/space/u-tokyo-hongo-3', (message) ->
msg.send message
robot.hear /yatai (.*)/i, (msg) ->
searchVillages msg.match[1], (message) ->
msg.send message
this.searchVillages = (query, callback) ->
request 'http://www.w-tokyodo.com/neostall/space', (error, response, body) ->
$ = cheerio.load body
for villageLink in $('.listPlace a') when $(villageLink).text().indexOf(query) >= 0
do ->
villageName = $(villageLink).text()
parseUrl $(villageLink).attr('href'), (message) ->
callback("#{villageName} #{message}")
this.parseUrl = (url, callback) ->
request url, (error, response, body) ->
$ = cheerio.load body
if $('#tabContentSpace .comment').first().find('del').length > 0
callback '今日はお休みです'
else
messages = []
messages.push $('#tabContentSpace .comment h3').first().text()
messages.push $('#tabContentSpace .comment p').first().text()
for element in $('#tabContentSpace .shop .photo').first().find('img')
do ->
messages.push $(element).attr('src')
callback messages.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment