yahoo_sports 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +17 -0
- data/README.rdoc +65 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/lib/yahoo_sports.rb +12 -0
- data/lib/yahoo_sports/base.rb +371 -0
- data/lib/yahoo_sports/mlb.rb +16 -0
- data/lib/yahoo_sports/nba.rb +16 -0
- data/lib/yahoo_sports/nfl.rb +16 -0
- data/lib/yahoo_sports/nhl.rb +16 -0
- data/test/test_helper.rb +12 -0
- data/test/yahoo_sports/base_test.rb +17 -0
- data/test/yahoo_sports/mlb_test.rb +30 -0
- data/test/yahoo_sports/nba_test.rb +30 -0
- data/test/yahoo_sports/nfl_test.rb +30 -0
- data/test/yahoo_sports/nhl_test.rb +30 -0
- data/test/yahoo_sports_test.rb +14 -0
- data/yahoo_sports.gemspec +70 -0
- metadata +98 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
lib/yahoo_sports.rb
|
6
|
+
lib/yahoo_sports/base.rb
|
7
|
+
lib/yahoo_sports/mlb.rb
|
8
|
+
lib/yahoo_sports/nba.rb
|
9
|
+
lib/yahoo_sports/nfl.rb
|
10
|
+
lib/yahoo_sports/nhl.rb
|
11
|
+
test/test_helper.rb
|
12
|
+
test/yahoo_sports/base_test.rb
|
13
|
+
test/yahoo_sports/mlb_test.rb
|
14
|
+
test/yahoo_sports/nba_test.rb
|
15
|
+
test/yahoo_sports/nfl_test.rb
|
16
|
+
test/yahoo_sports/nhl_test.rb
|
17
|
+
test/yahoo_sports_test.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= yahoo_sports
|
2
|
+
|
3
|
+
* http://github.com/chetan/yahoo_sports
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Ruby library for parsing stats from Yahoo! Sports pages. Currently supports
|
8
|
+
MLB, NBA, NFL and NHL stats and info.
|
9
|
+
|
10
|
+
== FEATURES:
|
11
|
+
|
12
|
+
* Pull previous day and current days games for each sport
|
13
|
+
* Pull specific team information (full name, standing, game schedule)
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
require "yahoo_sports"
|
18
|
+
team = YahooSports::NHL.get_team_stats("nyr")
|
19
|
+
team.name # => "New York Rangers"
|
20
|
+
team.standing # => "11-9-1"
|
21
|
+
team.position # => "4th Atlantic"
|
22
|
+
team.last5[0].team # => "Edmonton Oilers (7-7-1)"
|
23
|
+
team.last5[0].status # => "W 4 - 2"
|
24
|
+
|
25
|
+
== REQUIREMENTS:
|
26
|
+
|
27
|
+
* tzinfo
|
28
|
+
* scrapi
|
29
|
+
|
30
|
+
== INSTALL:
|
31
|
+
|
32
|
+
With gemcutter:
|
33
|
+
|
34
|
+
sudo gem install yahoo_sports
|
35
|
+
|
36
|
+
Without gemcutter:
|
37
|
+
|
38
|
+
git clone git://github.com/chetan/yahoo_sports.git
|
39
|
+
cd yahoo_sports
|
40
|
+
sudo rake install
|
41
|
+
|
42
|
+
== LICENSE:
|
43
|
+
|
44
|
+
(The MIT License)
|
45
|
+
|
46
|
+
Copyright (c) 2009 Pixelcop Resarch, Inc.
|
47
|
+
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
49
|
+
a copy of this software and associated documentation files (the
|
50
|
+
'Software'), to deal in the Software without restriction, including
|
51
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
52
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
53
|
+
permit persons to whom the Software is furnished to do so, subject to
|
54
|
+
the following conditions:
|
55
|
+
|
56
|
+
The above copyright notice and this permission notice shall be
|
57
|
+
included in all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
60
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
61
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
62
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
63
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
64
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
65
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require 'rubygems'
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gemspec|
|
6
|
+
gemspec.name = "yahoo_sports"
|
7
|
+
gemspec.summary = "Ruby library for parsing stats from Yahoo! Sports pages"
|
8
|
+
gemspec.description = "Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info."
|
9
|
+
gemspec.email = "chetan@pixelcop.net"
|
10
|
+
gemspec.homepage = "http://github.com/chetan/yahoo_sports"
|
11
|
+
gemspec.authors = ["Chetan Sarva"]
|
12
|
+
gemspec.add_dependency('scrapi', '>= 1.2.0')
|
13
|
+
gemspec.add_dependency('tzinfo', '>= 0.3.15')
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require "rake/testtask"
|
21
|
+
desc "Run unit tests"
|
22
|
+
Rake::TestTask.new("test") { |t|
|
23
|
+
#t.libs << "test"
|
24
|
+
t.ruby_opts << "-rubygems"
|
25
|
+
t.pattern = "test/**/*_test.rb"
|
26
|
+
t.verbose = false
|
27
|
+
t.warning = false
|
28
|
+
}
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/yahoo_sports.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
module YahooSports
|
5
|
+
|
6
|
+
autoload :Base, "yahoo_sports/base"
|
7
|
+
autoload :MLB, "yahoo_sports/mlb"
|
8
|
+
autoload :NBA, "yahoo_sports/nba"
|
9
|
+
autoload :NFL, "yahoo_sports/nfl"
|
10
|
+
autoload :NHL, "yahoo_sports/nhl"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'tzinfo'
|
4
|
+
|
5
|
+
if RUBY_PLATFORM =~ /darwin/ then
|
6
|
+
# fix for scrapi on Mac OS X
|
7
|
+
require "tidy"
|
8
|
+
Tidy.path = "/usr/lib/libtidy.dylib"
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'net/http'
|
12
|
+
require 'scrapi'
|
13
|
+
require 'ostruct'
|
14
|
+
require 'htmlentities'
|
15
|
+
|
16
|
+
module YahooSports
|
17
|
+
|
18
|
+
# little helper method i wrote to retry the fetch a few times
|
19
|
+
def self.fetchurl(url)
|
20
|
+
#puts "FETCHING #{url}"
|
21
|
+
return Net::HTTP.get_response(URI.parse(URI.escape(url))).body
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.strip_tags(html)
|
25
|
+
|
26
|
+
HTMLEntities.new.decode(
|
27
|
+
html.gsub(/<.+?>/,'').
|
28
|
+
gsub(/ /,' ').
|
29
|
+
gsub(/&/,'&').
|
30
|
+
gsub(/"/,'"').
|
31
|
+
gsub(/</,'<').
|
32
|
+
gsub(/>/,'>').
|
33
|
+
gsub(/&ellip;/,'...').
|
34
|
+
gsub(/'/, "'").
|
35
|
+
gsub(/<br *\/>/m, '')
|
36
|
+
).strip
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Base
|
41
|
+
|
42
|
+
def self.get_homepage_games(sport, state = '')
|
43
|
+
|
44
|
+
sport.downcase!
|
45
|
+
if sport !~ /^(nba|nhl|nfl|mlb)$/ then
|
46
|
+
raise sprintf("Invalid param for 'sport' = '%s'", sport)
|
47
|
+
end
|
48
|
+
|
49
|
+
state.downcase! if not state.empty?
|
50
|
+
if not state.empty? and state !~ /^(live|final|preview)$/ then
|
51
|
+
raise sprintf("Invalid param for 'state' = '%s'", state)
|
52
|
+
end
|
53
|
+
|
54
|
+
html = YahooSports.fetchurl('http://sports.yahoo.com/' + sport)
|
55
|
+
if not html then
|
56
|
+
raise 'Error fetching url'
|
57
|
+
end
|
58
|
+
|
59
|
+
sports_game = Scraper.define do
|
60
|
+
|
61
|
+
array :teams
|
62
|
+
array :scores
|
63
|
+
|
64
|
+
process "li.odd, li.even, li.live", :date_src => "@id"
|
65
|
+
process "li.odd, li.even, li.live", :class_src => "@class"
|
66
|
+
process "li.link-box", :extra_src => :text
|
67
|
+
|
68
|
+
process "td.team>a", :teams => :text
|
69
|
+
process "td.score", :scores => :text
|
70
|
+
|
71
|
+
process "li.status>a", :status => :text
|
72
|
+
|
73
|
+
|
74
|
+
result :date_src, :teams, :scores, :status, :class_src, :extra_src
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
sports = Scraper.define do
|
79
|
+
|
80
|
+
array :games
|
81
|
+
|
82
|
+
process "ul.game-list>li", :games => sports_game
|
83
|
+
|
84
|
+
result :games
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
games_temp = sports.scrape(html)
|
89
|
+
|
90
|
+
games = []
|
91
|
+
|
92
|
+
return games if games_temp.nil?
|
93
|
+
|
94
|
+
games_temp.each { |g|
|
95
|
+
|
96
|
+
gm = OpenStruct.new
|
97
|
+
gm.status = g.status.strip if g.status
|
98
|
+
gm.team1 = g.teams[0].strip if g.teams[0]
|
99
|
+
gm.team2 = g.teams[1].strip if g.teams[1]
|
100
|
+
gm.score1 = g.scores[0].strip if g.scores[0]
|
101
|
+
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
|
+
|
109
|
+
if g.class_src.include? ' ' then
|
110
|
+
gm.state = g.class_src[ g.class_src.index(' ')+1, g.class_src.length ].strip
|
111
|
+
else
|
112
|
+
gm.state = g.class_src.strip
|
113
|
+
end
|
114
|
+
|
115
|
+
gm.extra = $1 if g.extra_src =~ /TV: (.*)/
|
116
|
+
|
117
|
+
next if not state.empty? and state != gm.state
|
118
|
+
games << gm
|
119
|
+
|
120
|
+
}
|
121
|
+
|
122
|
+
return games
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.get_team_stats(sport, str)
|
127
|
+
|
128
|
+
sport.downcase!
|
129
|
+
if sport !~ /^(nba|nhl|nfl|mlb)$/ then
|
130
|
+
raise sprintf("Invalid param for 'sport' = '%s'", sport)
|
131
|
+
end
|
132
|
+
|
133
|
+
str.downcase!
|
134
|
+
(team, html) = find_team_page(sport, str)
|
135
|
+
if html.nil? then
|
136
|
+
raise sprintf("Can't find team '%s'", str)
|
137
|
+
end
|
138
|
+
|
139
|
+
info = get_team_info(html)
|
140
|
+
last5, next5 = get_scores_and_schedule(html)
|
141
|
+
live_game = get_live_game(info.name, html)
|
142
|
+
|
143
|
+
return OpenStruct.new({:name => info.name,
|
144
|
+
:standing => info.standing,
|
145
|
+
:position => info.position,
|
146
|
+
:last5 => last5,
|
147
|
+
:next5 => next5,
|
148
|
+
:live => live_game})
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def self.get_team_info(html)
|
155
|
+
|
156
|
+
info_scraper = Scraper.define do
|
157
|
+
|
158
|
+
process "div#team-header div.info h1", :name => :text
|
159
|
+
process "div#team-header div.info div.stats li.score", :standing => :text
|
160
|
+
process "div#team-header div.info div.stats li.position", :position => :text
|
161
|
+
|
162
|
+
result :name, :standing, :position
|
163
|
+
end
|
164
|
+
|
165
|
+
info_temp = info_scraper.scrape(html)
|
166
|
+
|
167
|
+
info = OpenStruct.new
|
168
|
+
return info if info_temp.nil?
|
169
|
+
|
170
|
+
info.name = info_temp.name
|
171
|
+
info_temp.standing.gsub!(/,/, '')
|
172
|
+
info.standing = info_temp.standing
|
173
|
+
info.position = info_temp.position
|
174
|
+
return info
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
def self.get_scores_and_schedule(html)
|
179
|
+
|
180
|
+
last5 = []
|
181
|
+
next5 = []
|
182
|
+
|
183
|
+
games_scraper = Scraper.define do
|
184
|
+
|
185
|
+
array :games
|
186
|
+
array :teams
|
187
|
+
|
188
|
+
process "div#team-schedule-list div.bd table tbody tr", :games => :text
|
189
|
+
process "div#team-schedule-list div.bd table tbody tr td.title span", :teams => :text
|
190
|
+
|
191
|
+
result :games, :teams
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
games_temp = games_scraper.scrape(html)
|
196
|
+
|
197
|
+
return [last5, next5] if games_temp.nil?
|
198
|
+
|
199
|
+
bye = false # bye week support for nfl
|
200
|
+
|
201
|
+
games_temp.games.each_index { |i|
|
202
|
+
|
203
|
+
info = games_temp.games[i].split("\n").slice(1, 3)
|
204
|
+
if info[0] == "Bye"
|
205
|
+
bye = true
|
206
|
+
team = nil
|
207
|
+
else
|
208
|
+
t = (bye ? i - 1 : i)
|
209
|
+
team = games_temp.teams[t].strip
|
210
|
+
end
|
211
|
+
|
212
|
+
gm = OpenStruct.new
|
213
|
+
|
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
|
+
info[1] =~ /(\([\d-]+\))/
|
223
|
+
record = $1
|
224
|
+
status = info[2]
|
225
|
+
|
226
|
+
gm.date = date
|
227
|
+
gm.team = "#{team} #{record}"
|
228
|
+
gm.status = status
|
229
|
+
|
230
|
+
if info[1] =~ / at / then
|
231
|
+
gm.away = 1
|
232
|
+
else
|
233
|
+
gm.away = 0
|
234
|
+
end
|
235
|
+
|
236
|
+
if gm.status =~ /^(W|L)/
|
237
|
+
last5 << gm
|
238
|
+
else
|
239
|
+
next5 << gm
|
240
|
+
end
|
241
|
+
|
242
|
+
}
|
243
|
+
|
244
|
+
return [last5, next5]
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.get_live_game(team, html)
|
248
|
+
|
249
|
+
return nil if html !~ /In Progress Game/
|
250
|
+
|
251
|
+
team_scraper = Scraper.define do
|
252
|
+
|
253
|
+
process_first "td:nth-child(2)", :name => :text
|
254
|
+
process_first "td:nth-child(4)", :runs => :text
|
255
|
+
process_first "td:nth-child(5)", :hits => :text
|
256
|
+
process_first "td:nth-child(6)", :errors => :text
|
257
|
+
|
258
|
+
result :name, :runs, :hits, :errors
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
live_scraper = Scraper.define do
|
263
|
+
array :teams
|
264
|
+
process_first "td.yspscores", :inning => :text
|
265
|
+
process "tr.ysptblclbg5", :teams => team_scraper
|
266
|
+
result :inning, :teams
|
267
|
+
end
|
268
|
+
|
269
|
+
game = live_scraper.scrape(html)
|
270
|
+
game = struct_to_ostruct(game)
|
271
|
+
game.inning.strip!
|
272
|
+
|
273
|
+
# they are at home if team 1 (2nd team) is them
|
274
|
+
if game.teams[1].name.split.size > 1 then
|
275
|
+
t = game.teams[1].name.split[-1]
|
276
|
+
else
|
277
|
+
t = game.teams[1].name
|
278
|
+
end
|
279
|
+
|
280
|
+
if team.include? t then
|
281
|
+
# home game
|
282
|
+
game.home = true
|
283
|
+
else
|
284
|
+
game.home = false
|
285
|
+
end
|
286
|
+
|
287
|
+
# helpers
|
288
|
+
game.away_team = game.teams[0]
|
289
|
+
game.home_team = game.teams[1]
|
290
|
+
game.delete_field('teams')
|
291
|
+
|
292
|
+
return game
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
def self.find_team_page(sport, str)
|
297
|
+
|
298
|
+
sport.downcase!
|
299
|
+
str.downcase!
|
300
|
+
|
301
|
+
begin
|
302
|
+
html = YahooSports.fetchurl("http://sports.yahoo.com/#{sport}/teams/" + str)
|
303
|
+
rescue => ex
|
304
|
+
puts ex
|
305
|
+
return
|
306
|
+
end
|
307
|
+
|
308
|
+
if html !~ %r{<title><MapleRegion id ="page_title_generic"/></title>} then
|
309
|
+
# got the right page
|
310
|
+
return [str, html]
|
311
|
+
end
|
312
|
+
|
313
|
+
# look for it
|
314
|
+
begin
|
315
|
+
html = YahooSports.fetchurl("http://sports.yahoo.com/#{sport}/teams")
|
316
|
+
rescue => ex
|
317
|
+
puts ex
|
318
|
+
return
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
team_scraper = Scraper.define do
|
323
|
+
array :teams, :links
|
324
|
+
process "table.yspcontent tr.ysprow1", :teams => :text
|
325
|
+
process "table.yspcontent tr.ysprow1 a", :links => "@href"
|
326
|
+
process "table.yspcontent tr.ysprow2", :teams => :text
|
327
|
+
process "table.yspcontent tr.ysprow2 a", :links => "@href"
|
328
|
+
result :teams, :links
|
329
|
+
end
|
330
|
+
|
331
|
+
ret = team_scraper.scrape(html)
|
332
|
+
return nil if ret.nil?
|
333
|
+
|
334
|
+
ret.teams.each_index { |i|
|
335
|
+
t = ret.teams[i]
|
336
|
+
l = ret.links[i].strip.gsub(%r{/$}, "") # strip trailing slash for nfl
|
337
|
+
t = YahooSports.strip_tags(t).strip
|
338
|
+
|
339
|
+
if t == str or t.downcase.include? str then
|
340
|
+
# found a matching team
|
341
|
+
begin
|
342
|
+
html = YahooSports.fetchurl("http://sports.yahoo.com#{l}")
|
343
|
+
rescue => ex
|
344
|
+
puts ex
|
345
|
+
return
|
346
|
+
end
|
347
|
+
t =~ %r{^/[a-z]+/teams/(.+)$}
|
348
|
+
return [$1, html]
|
349
|
+
end
|
350
|
+
}
|
351
|
+
|
352
|
+
return nil
|
353
|
+
|
354
|
+
end
|
355
|
+
|
356
|
+
def self.struct_to_ostruct(struct)
|
357
|
+
hash = {}
|
358
|
+
struct.each_pair { |key,val|
|
359
|
+
if val.kind_of? Struct then
|
360
|
+
val = struct_to_ostruct(val)
|
361
|
+
elsif val.kind_of? Array then
|
362
|
+
val.map! { |v| v.to_s =~ /struct/ ? struct_to_ostruct(v) : v }
|
363
|
+
end
|
364
|
+
hash[key] = val
|
365
|
+
}
|
366
|
+
return OpenStruct.new(hash)
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/yahoo_sports'
|
4
|
+
|
5
|
+
begin; require "turn"; rescue LoadError; end
|
6
|
+
|
7
|
+
if RUBY_PLATFORM =~ /darwin/ then
|
8
|
+
# fix for scrapi on Mac OS X
|
9
|
+
require "rubygems"
|
10
|
+
require "tidy"
|
11
|
+
Tidy.path = "/usr/lib/libtidy.dylib"
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class YahooSports_Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_homepage_games_sport_check
|
6
|
+
|
7
|
+
begin
|
8
|
+
YahooSports::Base.get_homepage_games("MLB")
|
9
|
+
rescue RuntimeError => e
|
10
|
+
if e.message =~ /Invalid param/ then
|
11
|
+
flunk("no exception should have been raised")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class MLB_Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_homepage_games
|
6
|
+
YahooSports::MLB.get_homepage_games
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get_team_stats
|
10
|
+
run_test("NYY")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_team_stats_by_name
|
14
|
+
run_test("yankees")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def run_test(str)
|
20
|
+
team = YahooSports::MLB.get_team_stats(str)
|
21
|
+
assert(team.name)
|
22
|
+
assert_equal("New York Yankees", team.name)
|
23
|
+
assert(team.standing)
|
24
|
+
assert(team.standing =~ /^\d+\-\d+$/)
|
25
|
+
assert(team.position)
|
26
|
+
assert((not team.last5.empty?), "last 5 games")
|
27
|
+
assert(team.next5)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class NBA_Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_homepage_games
|
6
|
+
YahooSports::NBA.get_homepage_games
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get_team_stats
|
10
|
+
run_test("NYK")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_team_stats_by_name
|
14
|
+
run_test("knicks")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def run_test(str)
|
20
|
+
team = YahooSports::NBA.get_team_stats(str)
|
21
|
+
assert(team.name)
|
22
|
+
assert_equal("New York Knicks", team.name)
|
23
|
+
assert(team.standing)
|
24
|
+
assert(team.standing =~ /^\d+\-\d+$/)
|
25
|
+
assert(team.position)
|
26
|
+
assert((not team.last5.empty?), "last 5 games")
|
27
|
+
assert(team.next5)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class NFL_Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_homepage_games
|
6
|
+
YahooSports::NFL.get_homepage_games
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get_team_stats
|
10
|
+
run_test("NYJ")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_team_stats_by_name
|
14
|
+
run_test("jets")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def run_test(str)
|
20
|
+
team = YahooSports::NFL.get_team_stats(str)
|
21
|
+
assert(team.name)
|
22
|
+
assert_equal("New York Jets", team.name)
|
23
|
+
assert(team.standing)
|
24
|
+
assert(team.standing =~ /^\d+\-\d+(-\d+)?$/)
|
25
|
+
assert(team.position)
|
26
|
+
assert((not team.last5.empty?), "last 5 games")
|
27
|
+
assert(team.next5)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class NHL_Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_homepage_games
|
6
|
+
YahooSports::NHL.get_homepage_games
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get_team_stats
|
10
|
+
run_test("NYR")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_team_stats_by_name
|
14
|
+
run_test("rangers")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def run_test(str)
|
20
|
+
team = YahooSports::NHL.get_team_stats(str)
|
21
|
+
assert(team.name)
|
22
|
+
assert_equal("New York Rangers", team.name)
|
23
|
+
assert(team.standing)
|
24
|
+
assert(team.standing =~ /^\d+\-\d+(-\d+)?$/)
|
25
|
+
assert(team.position)
|
26
|
+
assert((not team.last5.empty?), "last 5 games")
|
27
|
+
assert(team.next5)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class YahooSports_Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_autoload_classes
|
6
|
+
|
7
|
+
assert YahooSports::MLB
|
8
|
+
assert YahooSports::NBA
|
9
|
+
assert YahooSports::NFL
|
10
|
+
assert YahooSports::NHL
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{yahoo_sports}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Chetan Sarva"]
|
12
|
+
s.date = %q{2009-11-18}
|
13
|
+
s.description = %q{Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info.}
|
14
|
+
s.email = %q{chetan@pixelcop.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"History.txt",
|
20
|
+
"Manifest.txt",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lib/yahoo_sports.rb",
|
25
|
+
"lib/yahoo_sports/base.rb",
|
26
|
+
"lib/yahoo_sports/mlb.rb",
|
27
|
+
"lib/yahoo_sports/nba.rb",
|
28
|
+
"lib/yahoo_sports/nfl.rb",
|
29
|
+
"lib/yahoo_sports/nhl.rb",
|
30
|
+
"test/test_helper.rb",
|
31
|
+
"test/yahoo_sports/base_test.rb",
|
32
|
+
"test/yahoo_sports/mlb_test.rb",
|
33
|
+
"test/yahoo_sports/nba_test.rb",
|
34
|
+
"test/yahoo_sports/nfl_test.rb",
|
35
|
+
"test/yahoo_sports/nhl_test.rb",
|
36
|
+
"test/yahoo_sports_test.rb",
|
37
|
+
"yahoo_sports.gemspec"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/chetan/yahoo_sports}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.5}
|
43
|
+
s.summary = %q{Ruby library for parsing stats from Yahoo! Sports pages}
|
44
|
+
s.test_files = [
|
45
|
+
"test/test_helper.rb",
|
46
|
+
"test/yahoo_sports/base_test.rb",
|
47
|
+
"test/yahoo_sports/mlb_test.rb",
|
48
|
+
"test/yahoo_sports/nba_test.rb",
|
49
|
+
"test/yahoo_sports/nfl_test.rb",
|
50
|
+
"test/yahoo_sports/nhl_test.rb",
|
51
|
+
"test/yahoo_sports_test.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<scrapi>, [">= 1.2.0"])
|
60
|
+
s.add_runtime_dependency(%q<tzinfo>, [">= 0.3.15"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<scrapi>, [">= 1.2.0"])
|
63
|
+
s.add_dependency(%q<tzinfo>, [">= 0.3.15"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<scrapi>, [">= 1.2.0"])
|
67
|
+
s.add_dependency(%q<tzinfo>, [">= 0.3.15"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yahoo_sports
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chetan Sarva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-18 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: scrapi
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: tzinfo
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.15
|
34
|
+
version:
|
35
|
+
description: Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info.
|
36
|
+
email: chetan@pixelcop.net
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- History.txt
|
45
|
+
- Manifest.txt
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- VERSION
|
49
|
+
- lib/yahoo_sports.rb
|
50
|
+
- lib/yahoo_sports/base.rb
|
51
|
+
- lib/yahoo_sports/mlb.rb
|
52
|
+
- lib/yahoo_sports/nba.rb
|
53
|
+
- lib/yahoo_sports/nfl.rb
|
54
|
+
- lib/yahoo_sports/nhl.rb
|
55
|
+
- test/test_helper.rb
|
56
|
+
- test/yahoo_sports/base_test.rb
|
57
|
+
- test/yahoo_sports/mlb_test.rb
|
58
|
+
- test/yahoo_sports/nba_test.rb
|
59
|
+
- test/yahoo_sports/nfl_test.rb
|
60
|
+
- test/yahoo_sports/nhl_test.rb
|
61
|
+
- test/yahoo_sports_test.rb
|
62
|
+
- yahoo_sports.gemspec
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://github.com/chetan/yahoo_sports
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --charset=UTF-8
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.3.5
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Ruby library for parsing stats from Yahoo! Sports pages
|
91
|
+
test_files:
|
92
|
+
- test/test_helper.rb
|
93
|
+
- test/yahoo_sports/base_test.rb
|
94
|
+
- test/yahoo_sports/mlb_test.rb
|
95
|
+
- test/yahoo_sports/nba_test.rb
|
96
|
+
- test/yahoo_sports/nfl_test.rb
|
97
|
+
- test/yahoo_sports/nhl_test.rb
|
98
|
+
- test/yahoo_sports_test.rb
|