-
Notifications
You must be signed in to change notification settings - Fork 0
/
espn.coffee
34 lines (30 loc) · 989 Bytes
/
espn.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
# Description:
# Get live sports data for MLB, NHL, NBA, NFL, and WNBA
#
# Configuration:
# None
#
# Commands:
# hubot espn <mlb, nfl, etc.> - get real-time scores for the relevant league
#
# Author:
# Detry322
querystring = require 'querystring'
format_response = (league, response) ->
data = querystring.parse(response)
count = +data["#{league}_s_count"]
if not count
return "No scores to display for #{league.toUpperCase()}"
result_string = "Scores:\n"
for i in [1..count] by 1
key = "#{league}_s_left#{i}"
result_string += "- #{data[key]}\n"
return result_string
module.exports = (robot) ->
robot.respond /espn (mlb|nhl|nba|wnba|nfl)$/i, (res) ->
league = res.match[1].toLowerCase()
robot.http("http://www.espn.com/#{league}/bottomline/scores").get() (err, result, body) ->
if err or result.statusCode isnt 200
res.send "There was a problem fetching score data :("
return
res.send format_response(league, body)