Created
April 11, 2012 16:10
-
-
Save jmccartie/2360281 to your computer and use it in GitHub Desktop.
Lunchme hubot script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Where we gonna go for lunch? | |
# | |
# lunch me <zipcode> - get a random lunch result based on your zipcode | |
module.exports = (robot) -> | |
robot.respond /lunch me( (\d+))/i, (msg) -> | |
zipcode = msg.match[2] | |
msg.http("http://lunchme.herokuapp.com/?zipcode=" + zipcode) | |
.get() (err, res, body) -> | |
if body == "" | |
msg.send "Uh oh. There was an error getting results." | |
return false | |
if body | |
picks = JSON.parse(body) | |
if picks.length > 0 | |
pick = picks[Math.floor(Math.random() * picks.length)] | |
msg.send "#{pick.name} (#{pick.rating} stars) #{pick.url}" | |
location = "#{pick.address} #{zipcode}" | |
mapUrl = "http://maps.google.com/maps/api/staticmap?markers=" + | |
escape(location) + | |
"&size=400x400&maptype=roadmap" + | |
"&sensor=false" + | |
"&format=png" # So campfire knows it's an image | |
msg.send mapUrl | |
else | |
msg.send "Can't find anything :(" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment