Created
September 10, 2013 21:00
-
-
Save spro/6515624 to your computer and use it in GitHub Desktop.
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
http = require 'http' | |
fs = require 'fs' | |
util = require 'util' | |
qs = require 'querystring' | |
get_score_data = -> | |
http.get 'http://sports.espn.go.com/nfl/bottomline/scores', (res) -> | |
data = '' | |
res.on 'data', (chunk) -> | |
data += chunk | |
res.on 'end', -> | |
parse_score_data qs.parse data | |
load_score_data = -> parse_score_data qs.parse (fs.readFileSync 'scores.data').toString() | |
parse_score_data = (score_data) -> | |
for i in [1..score_data['nfl_s_count']] | |
score_line = score_data["nfl_s_left#{ i }"] | |
score_status = (score_line.match /\(.*\)/)[0] | |
score_line = (score_line.replace /\(.*\)/, '').trim() | |
score_line_parts = score_line.split(' ') | |
if score_status == '(FINAL)' | |
away_parts = score_line_parts[0].match /^\^?(.+) (\d+)/ | |
away_team = away_parts[1] | |
away_score = away_parts[2] | |
home_parts = score_line_parts[1].match /^\^?(.+) (\d+)/ | |
home_team = home_parts[1] | |
home_score = home_parts[2] | |
console.log 'Completed game:' | |
console.log "\t#{ away_team } @ #{ home_team }" | |
console.log "\t#{ away_score } : #{ home_score }" | |
else | |
console.log 'Upcoming game: ' + score_line_parts[0] | |
get_score_data() | |
#load_score_data() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment