This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
/
truckstopsf.coffee
51 lines (43 loc) · 1.98 KB
/
truckstopsf.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
48
49
50
51
# Description:
# Find out what food trucks are at Truck Stop SF today
# See http://truckstopsf.com
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot truckstopsf - get just the names of the food trucks today
# hubot truckstopsf details|deets - get food truck names and details
# hubot truckstopsf! - get food truck names and details
#
# Author:
# chris
module.exports = (robot) ->
robot.respond /truckstopsf\s?(!|details|deets)?/i, (res) ->
d = new Date()
utc = d.getTime() + (d.getTimezoneOffset() * 60000)
pstDate = new Date(utc + (3600000*-8));
today = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][pstDate.getDay()]
if today is 'Sunday' or today is 'Saturday'
res.send "Sorry, the trucks aren't there on weekend"
else
res.http("http://www.truckstopsf.com/").get() (err, _, body) ->
return res.send "Sorry, the trucks are out of gas or something." if err
if body.match("There are no events")
return res.send "Seems there may be no trucks today - check http://www.truckstopsf.com/"
show_details = res.match[1]?
matches = if show_details
body.match("<h3>#{today}<\/h3>[^]+?<p><strong>(.+)<\/strong> - (.+)<\/p>[^]+?<p><strong>(.+)<\/strong> - (.+)<\/p>[^]+?<p><strong>(.+)<\/strong> - (.+)<\/p>")
else
body.match("<h3>#{today}<\/h3>[^]+?<p><strong>(.+)<\/strong>[^]+?<p><strong>(.+)<\/strong>[^]+?<p><strong>(.+)<\/strong>")
if matches?.length > 3
trucks = (match.replace("'", "'").replace("&", "&") for match in matches.slice(1))
if show_details
res.send "Today's trucks:\n* #{trucks[0]}: #{trucks[1]}\n* #{trucks[2]}: #{trucks[3]}\n* #{trucks[4]}: #{trucks[5]}"
else
res.send "Today's trucks: #{trucks[0]}, #{trucks[1]}, and #{trucks[2]}"
else
res.send "Hmm, couldn't parse the trucks web page - try http://www.truckstopsf.com/"