Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor changes to TomDoc and output

  • Loading branch information...
commit eb0289fec951d2e1c5d17742b34263c460f91049 1 parent 9a80493
@mjw56 authored
Showing with 10 additions and 6 deletions.
  1. +10 −6 src/scripts/espn.coffee
View
16 src/scripts/espn.coffee
@@ -2,10 +2,10 @@
# Grab a headline from ESPN
#
# Dependencies:
-# ESPN API Key
+# None
#
# Configuration:
-# Insert your ESPN API Key into the URL
+# HUBOT_ESPN_ACCOUNT_KEY
#
# Commands:
# hubot espn - Displays a random headline from ESPN.com
@@ -13,20 +13,24 @@
# Author:
# mjw56
+espnApiKey = process.env.HUBOT_ESPN_ACCOUNT_KEY
+unless espnApiKey
+ throw "You must enter your HUBOT_ESPN_ACCOUNT_KEY in your environment variables"
+
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>')
+ search = escape(msg.match[2])
+ msg.http('http://api.espn.com/v1/sports/news/headlines?apikey=' + espnApiKey)
.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]
Please sign in to comment.
Something went wrong with that request. Please try again.