yahoo_sports 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -0
- data/VERSION +1 -1
- data/lib/yahoo_sports/base.rb +99 -33
- data/lib/yahoo_sports/mlb.rb +38 -0
- data/lib/yahoo_sports/nba.rb +39 -1
- data/lib/yahoo_sports/nfl.rb +39 -1
- data/lib/yahoo_sports/nhl.rb +38 -0
- data/yahoo_sports.gemspec +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/yahoo_sports/base.rb
CHANGED
@@ -15,12 +15,29 @@ require 'htmlentities'
|
|
15
15
|
|
16
16
|
module YahooSports
|
17
17
|
|
18
|
-
#
|
18
|
+
# Fetches the given URL and returns the body
|
19
|
+
#
|
20
|
+
# @param [String] URL
|
21
|
+
# @return [String] contents of response body
|
19
22
|
def self.fetchurl(url)
|
20
23
|
#puts "FETCHING #{url}"
|
21
24
|
return Net::HTTP.get_response(URI.parse(URI.escape(url))).body
|
22
25
|
end
|
23
26
|
|
27
|
+
# Strip HTML tags from the given string. Also performs some common entity
|
28
|
+
# substitutions.
|
29
|
+
#
|
30
|
+
# List of entity codes:
|
31
|
+
# *
|
32
|
+
# * &
|
33
|
+
# * "
|
34
|
+
# * <
|
35
|
+
# * >
|
36
|
+
# * &ellip;
|
37
|
+
# * '
|
38
|
+
#
|
39
|
+
# @param [String] html text to be filtered
|
40
|
+
# @return [String] original string with HTML tags filtered out and entities replaced
|
24
41
|
def self.strip_tags(html)
|
25
42
|
|
26
43
|
HTMLEntities.new.decode(
|
@@ -39,7 +56,28 @@ end
|
|
39
56
|
|
40
57
|
class Base
|
41
58
|
|
42
|
-
|
59
|
+
# Get the scoreboard games for the given sport. Includes recently completed,
|
60
|
+
# live and upcoming games.
|
61
|
+
#
|
62
|
+
# Source: http://sports.yahoo.com/<sport>
|
63
|
+
#
|
64
|
+
# Game struct has the following keys:
|
65
|
+
# game.date # date of game; includes time if preview
|
66
|
+
# game.team1 # visiting team
|
67
|
+
# game.team2 # home team
|
68
|
+
# game.score1 # team1's score, if live or final
|
69
|
+
# game.score2 # team2's score, if live or final
|
70
|
+
# game.state # live, final or preview
|
71
|
+
# game.tv # TV station showing the game, if preview and available
|
72
|
+
#
|
73
|
+
# Example:
|
74
|
+
# #<OpenStruct state="final", score1="34", date=Thu Nov 26 00:00:00 -0500 2009, score2="12", team1="Green Bay", team2="Detroit">
|
75
|
+
#
|
76
|
+
#
|
77
|
+
# @param [String] sport sport to list, can be one of ["mlb", "nba", "nfl", "nhl"]
|
78
|
+
# @param [String] state Optionally filter for the given state ("live", "final", or "preview")
|
79
|
+
# @return [Array<OpenStruct>] list of games
|
80
|
+
def self.get_homepage_games(sport, state = "")
|
43
81
|
|
44
82
|
sport.downcase!
|
45
83
|
if sport !~ /^(nba|nhl|nfl|mlb)$/ then
|
@@ -94,25 +132,27 @@ class Base
|
|
94
132
|
games_temp.each { |g|
|
95
133
|
|
96
134
|
gm = OpenStruct.new
|
97
|
-
gm.status = g.status.strip if g.status
|
98
135
|
gm.team1 = g.teams[0].strip if g.teams[0]
|
99
136
|
gm.team2 = g.teams[1].strip if g.teams[1]
|
100
137
|
gm.score1 = g.scores[0].strip if g.scores[0]
|
101
138
|
gm.score2 = g.scores[1].strip if g.scores[1]
|
102
|
-
|
103
|
-
if sport == 'mlb' then
|
104
|
-
gm.date = Time.parse(Time.new.strftime('%Y') + g.date_src[2,4])
|
105
|
-
else
|
106
|
-
gm.date = Time.parse(g.date_src[0,8])
|
107
|
-
end
|
108
|
-
|
139
|
+
|
109
140
|
if g.class_src.include? ' ' then
|
110
141
|
gm.state = g.class_src[ g.class_src.index(' ')+1, g.class_src.length ].strip
|
111
142
|
else
|
112
143
|
gm.state = g.class_src.strip
|
113
144
|
end
|
114
145
|
|
115
|
-
gm.
|
146
|
+
gm.tv = $1 if g.extra_src =~ /TV: (.*)/
|
147
|
+
|
148
|
+
status = g.status.strip if g.status
|
149
|
+
time_str = (gm.state == "preview" ? " #{status}" : "")
|
150
|
+
|
151
|
+
if sport == 'mlb' then
|
152
|
+
gm.date = Time.parse(Time.new.strftime('%Y') + g.date_src[2,4] + time_str)
|
153
|
+
else
|
154
|
+
gm.date = Time.parse(g.date_src[0,8] + time_str)
|
155
|
+
end
|
116
156
|
|
117
157
|
next if not state.empty? and state != gm.state
|
118
158
|
games << gm
|
@@ -123,6 +163,28 @@ class Base
|
|
123
163
|
|
124
164
|
end
|
125
165
|
|
166
|
+
# Retrieves team information for the team in the given sport
|
167
|
+
#
|
168
|
+
# Source: http://sports.yahoo.com/<sport>/teams/<team>
|
169
|
+
#
|
170
|
+
# Team struct has the following keys:
|
171
|
+
# team.name # full team name
|
172
|
+
# team.standing # current standing
|
173
|
+
# team.position # position in the conference
|
174
|
+
# team.last5 # previous games results
|
175
|
+
# team.next5 # upcoming scheduled games
|
176
|
+
# team.live # struct describing in-progress game, if available
|
177
|
+
#
|
178
|
+
#
|
179
|
+
# Games in the last5 and next5 lists have the following keys:
|
180
|
+
# game.date # date of game
|
181
|
+
# game.team # full team name
|
182
|
+
# game.status # score for completed games (e.g. "L 20 - 23") or "preview"
|
183
|
+
# game.away # boolean value indicating an away game
|
184
|
+
#
|
185
|
+
# @param [String] sport sport to list, can be one of ["mlb", "nba", "nfl", "nhl"]
|
186
|
+
# @param [String] str 3-letter team code or partial team name
|
187
|
+
# @return [OpenStruct] team info
|
126
188
|
def self.get_team_stats(sport, str)
|
127
189
|
|
128
190
|
sport.downcase!
|
@@ -173,8 +235,7 @@ class Base
|
|
173
235
|
info.position = info_temp.position
|
174
236
|
return info
|
175
237
|
end
|
176
|
-
|
177
|
-
|
238
|
+
|
178
239
|
def self.get_scores_and_schedule(html)
|
179
240
|
|
180
241
|
last5 = []
|
@@ -197,13 +258,15 @@ class Base
|
|
197
258
|
return [last5, next5] if games_temp.nil?
|
198
259
|
|
199
260
|
bye = false # bye week support for nfl
|
261
|
+
bye_added = false # help us put it in the right place (hopefully)
|
200
262
|
|
201
263
|
games_temp.games.each_index { |i|
|
202
264
|
|
203
265
|
info = games_temp.games[i].split("\n").slice(1, 3)
|
204
266
|
if info[0] == "Bye"
|
267
|
+
# team is in a bye week
|
205
268
|
bye = true
|
206
|
-
|
269
|
+
next
|
207
270
|
else
|
208
271
|
t = (bye ? i - 1 : i)
|
209
272
|
team = games_temp.teams[t].strip
|
@@ -211,32 +274,35 @@ class Base
|
|
211
274
|
|
212
275
|
gm = OpenStruct.new
|
213
276
|
|
214
|
-
if bye then
|
215
|
-
# team is in a bye week
|
216
|
-
gm.bye = true
|
217
|
-
next5 << gm
|
218
|
-
next
|
219
|
-
end
|
220
|
-
|
221
|
-
date = Time.parse(info[0])
|
222
277
|
info[1] =~ /(\([\d-]+\))/
|
223
278
|
record = $1
|
224
279
|
status = info[2]
|
225
280
|
|
226
|
-
|
227
|
-
|
228
|
-
gm.
|
281
|
+
preview = (status !~ /^(W|L)/)
|
282
|
+
date_str = (preview ? "#{info[0]} #{status}" : info[0])
|
283
|
+
gm.date = Time.parse(date_str)
|
284
|
+
|
285
|
+
gm.team = "#{team} #{record}".strip
|
286
|
+
gm.status = (preview ? "preview" : status)
|
229
287
|
|
230
|
-
|
231
|
-
gm.away = 1
|
232
|
-
else
|
233
|
-
gm.away = 0
|
234
|
-
end
|
288
|
+
gm.away = (info[1] =~ / at / ? true : false)
|
235
289
|
|
236
|
-
if
|
237
|
-
|
290
|
+
if preview then
|
291
|
+
if bye and not bye_added then
|
292
|
+
gmb = OpenStruct.new
|
293
|
+
gmb.bye = true
|
294
|
+
next5 << gmb
|
295
|
+
bye_added = true
|
296
|
+
end
|
297
|
+
next5 << gm
|
238
298
|
else
|
239
|
-
|
299
|
+
if bye and not bye_added then
|
300
|
+
gmb = OpenStruct.new
|
301
|
+
gmb.bye = true
|
302
|
+
last5 << gmb
|
303
|
+
bye_added = true
|
304
|
+
end
|
305
|
+
last5 << gm
|
240
306
|
end
|
241
307
|
|
242
308
|
}
|
data/lib/yahoo_sports/mlb.rb
CHANGED
@@ -3,10 +3,48 @@ module YahooSports
|
|
3
3
|
|
4
4
|
class MLB < Base
|
5
5
|
|
6
|
+
# Get the MLB scoreboard games. Includes recently completed,
|
7
|
+
# live and upcoming games.
|
8
|
+
#
|
9
|
+
# Source: http://sports.yahoo.com/mlb
|
10
|
+
#
|
11
|
+
# Game struct has the following keys:
|
12
|
+
# game.date # date of game; includes time if preview
|
13
|
+
# game.team1 # visiting team
|
14
|
+
# game.team2 # home team
|
15
|
+
# game.score1 # team1's score, if live or final
|
16
|
+
# game.score2 # team2's score, if live or final
|
17
|
+
# game.state # live, final or preview
|
18
|
+
# game.tv # TV station showing the game, if preview and available
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @param [String] state Optionally filter for the given state ("live", "final", or "preview")
|
22
|
+
# @return [Array<OpenStruct>] list of games
|
6
23
|
def self.get_homepage_games(state = "")
|
7
24
|
super("mlb", state)
|
8
25
|
end
|
9
26
|
|
27
|
+
# Retrieves team information for the team
|
28
|
+
#
|
29
|
+
# Source: http://sports.yahoo.com/mlb/teams/<team>
|
30
|
+
#
|
31
|
+
# Team struct has the following keys:
|
32
|
+
# team.name # full team name
|
33
|
+
# team.standing # current standing
|
34
|
+
# team.position # position in the conference
|
35
|
+
# team.last5 # previous games results
|
36
|
+
# team.next5 # upcoming scheduled games
|
37
|
+
# team.live # struct describing in-progress game, if available
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Games in the last5 and next5 lists have the following keys:
|
41
|
+
# game.date # date of game
|
42
|
+
# game.team # full team name
|
43
|
+
# game.status # score for completed games (e.g. "L 20 - 23")
|
44
|
+
# game.away # boolean value indicating an away game
|
45
|
+
#
|
46
|
+
# @param [String] str 3-letter team code or partial team name
|
47
|
+
# @return [OpenStruct] team info
|
10
48
|
def self.get_team_stats(str)
|
11
49
|
super("mlb", str)
|
12
50
|
end
|
data/lib/yahoo_sports/nba.rb
CHANGED
@@ -2,11 +2,49 @@
|
|
2
2
|
module YahooSports
|
3
3
|
|
4
4
|
class NBA < Base
|
5
|
-
|
5
|
+
|
6
|
+
# Get the NBA scoreboard games. Includes recently completed,
|
7
|
+
# live and upcoming games.
|
8
|
+
#
|
9
|
+
# Source: http://sports.yahoo.com/nba
|
10
|
+
#
|
11
|
+
# Game struct has the following keys:
|
12
|
+
# game.date # date of game; includes time if preview
|
13
|
+
# game.team1 # visiting team
|
14
|
+
# game.team2 # home team
|
15
|
+
# game.score1 # team1's score, if live or final
|
16
|
+
# game.score2 # team2's score, if live or final
|
17
|
+
# game.state # live, final or preview
|
18
|
+
# game.tv # TV station showing the game, if preview and available
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @param [String] state Optionally filter for the given state ("live", "final", or "preview")
|
22
|
+
# @return [Array<OpenStruct>] list of games
|
6
23
|
def self.get_homepage_games(state = "")
|
7
24
|
super("nba", state)
|
8
25
|
end
|
9
26
|
|
27
|
+
# Retrieves team information for the team
|
28
|
+
#
|
29
|
+
# Source: http://sports.yahoo.com/nba/teams/<team>
|
30
|
+
#
|
31
|
+
# Team struct has the following keys:
|
32
|
+
# team.name # full team name
|
33
|
+
# team.standing # current standing
|
34
|
+
# team.position # position in the conference
|
35
|
+
# team.last5 # previous games results
|
36
|
+
# team.next5 # upcoming scheduled games
|
37
|
+
# team.live # struct describing in-progress game, if available
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Games in the last5 and next5 lists have the following keys:
|
41
|
+
# game.date # date of game
|
42
|
+
# game.team # full team name
|
43
|
+
# game.status # score for completed games (e.g. "L 20 - 23")
|
44
|
+
# game.away # boolean value indicating an away game
|
45
|
+
#
|
46
|
+
# @param [String] str 3-letter team code or partial team name
|
47
|
+
# @return [OpenStruct] team info
|
10
48
|
def self.get_team_stats(str)
|
11
49
|
super("nba", str)
|
12
50
|
end
|
data/lib/yahoo_sports/nfl.rb
CHANGED
@@ -3,10 +3,48 @@ module YahooSports
|
|
3
3
|
|
4
4
|
class NFL < Base
|
5
5
|
|
6
|
+
# Get the NFL scoreboard games. Includes recently completed,
|
7
|
+
# live and upcoming games.
|
8
|
+
#
|
9
|
+
# Source: http://sports.yahoo.com/nfl
|
10
|
+
#
|
11
|
+
# Game struct has the following keys:
|
12
|
+
# game.date # date of game; includes time if preview
|
13
|
+
# game.team1 # visiting team
|
14
|
+
# game.team2 # home team
|
15
|
+
# game.score1 # team1's score, if live or final
|
16
|
+
# game.score2 # team2's score, if live or final
|
17
|
+
# game.state # live, final or preview
|
18
|
+
# game.tv # TV station showing the game, if preview and available
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @param [String] state Optionally filter for the given state ("live", "final", or "preview")
|
22
|
+
# @return [Array<OpenStruct>] list of games
|
6
23
|
def self.get_homepage_games(state = "")
|
7
|
-
|
24
|
+
super("nfl", state)
|
8
25
|
end
|
9
26
|
|
27
|
+
# Retrieves team information for the team
|
28
|
+
#
|
29
|
+
# Source: http://sports.yahoo.com/nfl/teams/<team>
|
30
|
+
#
|
31
|
+
# Team struct has the following keys:
|
32
|
+
# team.name # full team name
|
33
|
+
# team.standing # current standing
|
34
|
+
# team.position # position in the conference
|
35
|
+
# team.last5 # previous games results
|
36
|
+
# team.next5 # upcoming scheduled games
|
37
|
+
# team.live # struct describing in-progress game, if available
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Games in the last5 and next5 lists have the following keys:
|
41
|
+
# game.date # date of game
|
42
|
+
# game.team # full team name
|
43
|
+
# game.status # score for completed games (e.g. "L 20 - 23")
|
44
|
+
# game.away # boolean value indicating an away game
|
45
|
+
#
|
46
|
+
# @param [String] str 3-letter team code or partial team name
|
47
|
+
# @return [OpenStruct] team info
|
10
48
|
def self.get_team_stats(str)
|
11
49
|
super("nfl", str)
|
12
50
|
end
|
data/lib/yahoo_sports/nhl.rb
CHANGED
@@ -3,10 +3,48 @@ module YahooSports
|
|
3
3
|
|
4
4
|
class NHL < Base
|
5
5
|
|
6
|
+
# Get the NHL scoreboard games. Includes recently completed,
|
7
|
+
# live and upcoming games.
|
8
|
+
#
|
9
|
+
# Source: http://sports.yahoo.com/nhl
|
10
|
+
#
|
11
|
+
# Game struct has the following keys:
|
12
|
+
# game.date # date of game; includes time if preview
|
13
|
+
# game.team1 # visiting team
|
14
|
+
# game.team2 # home team
|
15
|
+
# game.score1 # team1's score, if live or final
|
16
|
+
# game.score2 # team2's score, if live or final
|
17
|
+
# game.state # live, final or preview
|
18
|
+
# game.tv # TV station showing the game, if preview and available
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# @param [String] state Optionally filter for the given state ("live", "final", or "preview")
|
22
|
+
# @return [Array<OpenStruct>] list of games
|
6
23
|
def self.get_homepage_games(state = "")
|
7
24
|
super("nhl", state)
|
8
25
|
end
|
9
26
|
|
27
|
+
# Retrieves team information for the team
|
28
|
+
#
|
29
|
+
# Source: http://sports.yahoo.com/nhl/teams/<team>
|
30
|
+
#
|
31
|
+
# Team struct has the following keys:
|
32
|
+
# team.name # full team name
|
33
|
+
# team.standing # current standing
|
34
|
+
# team.position # position in the conference
|
35
|
+
# team.last5 # previous games results
|
36
|
+
# team.next5 # upcoming scheduled games
|
37
|
+
# team.live # struct describing in-progress game, if available
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Games in the last5 and next5 lists have the following keys:
|
41
|
+
# game.date # date of game
|
42
|
+
# game.team # full team name
|
43
|
+
# game.status # score for completed games (e.g. "L 20 - 23")
|
44
|
+
# game.away # boolean value indicating an away game
|
45
|
+
#
|
46
|
+
# @param [String] str 3-letter team code or partial team name
|
47
|
+
# @return [OpenStruct] team info
|
10
48
|
def self.get_team_stats(str)
|
11
49
|
super("nhl", str)
|
12
50
|
end
|
data/yahoo_sports.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{yahoo_sports}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chetan Sarva"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-30}
|
13
13
|
s.description = %q{Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info.}
|
14
14
|
s.email = %q{chetan@pixelcop.net}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_sports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chetan Sarva
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|