-
-
Save evaristorivi/768be8b7f9e758ea649cdf1437ceebda to your computer and use it in GitHub Desktop.
Mini hubot-script for hubot talk in tijuana.js
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
# Description: | |
# Ask hubot about the recent earthquakes in the last (hour, day, week or month). | |
# | |
# Dependencies: | |
# None | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# hubot quakes (intensity|all|significant) (period) [limit] | |
# | |
# Author: | |
# EnriqueVidal | |
lookup_site = "http://earthquake.usgs.gov" | |
module.exports = (robot)-> | |
robot.respond /quakes (([12](\.[05])?)|all|significant)? (hour|day|week|month)( \d+)?$/i, (message)-> | |
check_for_rapture message, message.match[1], message.match[4], parseInt( message.match[5] ) | |
check_for_rapture = (message, intensity, period, limit)-> | |
rapture_url = [ lookup_site, "earthquakes", "feed", "geojson", intensity, period ].join '/' | |
message.http( rapture_url ).get() (error, response, body)-> | |
return message.send 'Sorry, something went wrong' if error | |
list = JSON.parse( body ).features | |
count = 0 | |
for quake in list | |
count++ | |
quake = quake.properties | |
time = build_time quake | |
url = [ lookup_site, quake.url ].join '' | |
message.send "Magnitude: #{ quake.mag }, Location: #{ quake.place }, Time: #{ time } - #{ url }" | |
break if count is limit | |
build_time = ( object )-> | |
time = new Date object.time * 1000 | |
[ time.getHours(), time.getMinutes(), time.getSeconds() ].join ':' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment