Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added the espn script to scripts

  • Loading branch information...
commit 8fc5cce26d34be12e4f0be525ec56ca658e4c0c3 1 parent de4993b
@mjw56 authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 src/scripts/espn.coffee
View
32 src/scripts/espn.coffee
@@ -0,0 +1,32 @@
+# Description:
+# Grab a headline from ESPN
+#
+# Dependencies:
+# ESPN API Key
+#
+# Configuration:
+# Insert your ESPN API Key into the URL
+#
+# Commands:
+# hubot espn - Displays a random headline from ESPN.com
+#
+# Author:
+# mjw56
+
+module.exports = (robot) ->
+ robot.respond /espn/i, (msg) ->
+ search = escape(msg.match[1])
+ msg.http('http://api.espn.com/v1/sports/news/headlines?apikey=<YOUR ESPN API KEY>')
+ .get() (err, res, body) ->
+ result = JSON.parse(body)
+
+ if result.headlines.count <= 0
+ msg.send "Couldn't find any headlines"
+ return
+
+ urls = [ ]
+ for child in result.headlines
+ urls.push(child.headline + ": " + child.links.web.href)
+
+ rnd = Math.floor(Math.random()*urls.length)
+ msg.send urls[rnd]

0 comments on commit 8fc5cce

Please sign in to comment.
Something went wrong with that request. Please try again.