pitch_fx_scraper 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/pitch_fx_scraper/fetch.rb +39 -8
- data/lib/pitch_fx_scraper/version.rb +1 -1
- data/spec/fetch_spec.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDdlOGJkNTk5MGMwOGYxODgyZTQ4ODVjOTUzOWFkYjNhMjhmNmY2OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGEwZWNhNTc1MDMzMTcyNGJjNTNhMDE1ZTJlNjEzM2QwNzljY2RlMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWI4NDVhMDY5YTljYWRjYzVlMDYzZTRmNzMxMGYxOTI3YjJjNWU4NWEzYWU3
|
10
|
+
NzZmM2ViYWFiYjAwMmEyMDQxZmNiNTUwYjJlZTJkMWI1ZTljOGM2NjFjMzI5
|
11
|
+
ODg3ZWQxMTJmNzY1ZWQxNzU0ZWY3YzA4MDY2YzU3ODk1YmUwNWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTI0ZmY0OTMwM2Y0NjNhNTA5YzQxMDMyMTk2ZjA4YzljOTAwYjE1ZWYxMWFi
|
14
|
+
ZjE4ODllNmQ0MTJhMDZmNjJiNzgzOTU0N2I5M2Q3ZDhhZWYxNTBhYTQwOTQw
|
15
|
+
NjU2OTMwYTJjOTlhMmU1MDA3NTM5Y2I1MDk3ZWI0NGRkYzdmMWM=
|
@@ -7,11 +7,15 @@ module Fetch
|
|
7
7
|
|
8
8
|
@@host_url_base = "http://gd2.mlb.com"
|
9
9
|
|
10
|
-
def Fetch.url_for_date(date,
|
10
|
+
def Fetch.url_for_date(date, league=:mlb)
|
11
11
|
date_object = Chronic.parse(date)
|
12
|
-
if
|
12
|
+
if league == :mlb
|
13
13
|
url_base = @@host_url_base + "/components/game/mlb/"
|
14
|
-
|
14
|
+
elsif league == :milb_high
|
15
|
+
url_base = @@host_url_base + "/components/game/min/"
|
16
|
+
elsif league == :milb_low
|
17
|
+
url_base = @@host_url_base + "/components/game/min/"
|
18
|
+
elsif league == :milb
|
15
19
|
url_base = @@host_url_base + "/components/game/milb/"
|
16
20
|
end
|
17
21
|
url_base += "year_#{"%04d" % date_object.year}/"
|
@@ -19,15 +23,42 @@ module Fetch
|
|
19
23
|
url_base += "day_#{"%02d" % date_object.day}"
|
20
24
|
end
|
21
25
|
|
26
|
+
## Return a list of home games for date
|
27
|
+
##
|
28
|
+
def Fetch.get_game_home_teams(date, league=:mlb)
|
29
|
+
if league == :mlb
|
30
|
+
master_scoreboard_url = Fetch.url_for_date(date,league) + "/master_scoreboard.xml"
|
31
|
+
elsif league == :milb_high
|
32
|
+
master_scoreboard_url = Fetch.url_for_date(date,league) + "/mobile_epg_min_high.xml"
|
33
|
+
elsif league == :milb_low
|
34
|
+
master_scoreboard_url = Fetch.url_for_date(date,league) + "/mobile_epg_min_low.xml"
|
35
|
+
end
|
36
|
+
|
37
|
+
scoreboard = Nokogiri::XML(open(master_scoreboard_url))
|
38
|
+
|
39
|
+
game_teams = []
|
40
|
+
|
41
|
+
scoreboard.xpath("//game").each do |node|
|
42
|
+
if (league == :milb_high || league == :milb_low)
|
43
|
+
home_city = node.attr('home_team_city')
|
44
|
+
home_team = node.attr('home_team_name')
|
45
|
+
end
|
46
|
+
|
47
|
+
game_teams << home_city+" "+home_team
|
48
|
+
end
|
49
|
+
|
50
|
+
return game_teams
|
51
|
+
end
|
52
|
+
|
22
53
|
|
23
54
|
## Return a list of hashes containing game data urls
|
24
55
|
## with game ids for a given date string
|
25
56
|
##
|
26
|
-
def Fetch.get_game_urls(date,
|
27
|
-
if
|
57
|
+
def Fetch.get_game_urls(date, league=:mlb)
|
58
|
+
if league == :mlb
|
28
59
|
master_scoreboard_url = Fetch.url_for_date(date) + "/master_scoreboard.xml"
|
29
60
|
else
|
30
|
-
master_scoreboard_url = Fetch.url_for_date(date,
|
61
|
+
master_scoreboard_url = Fetch.url_for_date(date,league) + "/milb_master_game_file.xml"
|
31
62
|
end
|
32
63
|
|
33
64
|
scoreboard = Nokogiri::XML(open(master_scoreboard_url))
|
@@ -35,7 +66,7 @@ module Fetch
|
|
35
66
|
game_urls = []
|
36
67
|
|
37
68
|
scoreboard.xpath("//game").each do |node|
|
38
|
-
if
|
69
|
+
if league == :mlb
|
39
70
|
game_path = node.attr('game_data_directory')
|
40
71
|
game_id = node.attr('gameday')
|
41
72
|
game_url = @@host_url_base + game_path + "/game_events.xml"
|
@@ -53,7 +84,7 @@ module Fetch
|
|
53
84
|
## Return a list of hashes containing home team data
|
54
85
|
## for a given date string
|
55
86
|
def Fetch.get_milb_schedule (date)
|
56
|
-
game_boxscores = Fetch.get_game_urls(date,
|
87
|
+
game_boxscores = Fetch.get_game_urls(date, :milb)
|
57
88
|
|
58
89
|
games = []
|
59
90
|
|
data/spec/fetch_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Fetch do
|
|
11
11
|
|
12
12
|
it 'should return a valid milb url for 2014-04-24' do
|
13
13
|
our_date = '2014-04-24'
|
14
|
-
result = Fetch.url_for_date(our_date,
|
14
|
+
result = Fetch.url_for_date(our_date, :milb)
|
15
15
|
result.should == 'http://gd2.mlb.com/components/game/milb/year_2014/month_04/day_24'
|
16
16
|
end
|
17
17
|
end
|
@@ -38,4 +38,11 @@ describe Fetch do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
describe "get_milb_home_teams" do
|
42
|
+
it 'should have Trenton on July 11th 2014' do
|
43
|
+
list_of_games = Fetch.get_game_home_teams('July 11th 2014', :milb_high)
|
44
|
+
list_of_games.should include('Trenton Thunder')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
41
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pitch_fx_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Sachitano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|