/
ubereats.coffee
47 lines (40 loc) · 1.16 KB
/
ubereats.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Description:
# Hubot tells you what Ubereats.es is serving today.
#
# Dependencies:
# lodash, request, cheerio
#
# Configuration:
# None
#
# Commands:
# hubot ubereats [lunch|dinner] - Hubot shows you the menu
#
# Author:
# github.com/philipbattle
#
_ = require 'lodash'
cheerio = require('cheerio')
module.exports = (robot) ->
upcoming = []
robot.http("http://www.ubereats.es/menu?format=json")
.header('Accept', 'application/json')
.get() (err, res, body) ->
if not err
upcoming = JSON.parse(body).upcoming
return robot.respond(/ubereats\s?(lunch|dinner)?/i, (msg) ->
match = msg.match[1];
if upcoming.length
today = new Date().toDateString()
_.each upcoming, (meal) ->
if new Date(meal.startDate).toDateString() == today
mealType = meal.tags[0]
if !match || match is mealType
msg.send mealType
msg.send cheerio.load(meal.body)('p').text();
msg.send meal.title
msg.send cheerio.load(meal.excerpt)('p span').first().text();
msg.send meal.assetUrl.slice(0, -1) + '.png'
else
msg.send "Reading data from Ubereats.es"
)