mlb_terminal 0.0.4 → 0.0.5
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.
- data/Gemfile.lock +3 -1
- data/README.md +166 -19
- data/bin/mlb +24 -10
- data/lib/mlb_terminal/game.rb +34 -7
- data/lib/mlb_terminal/version.rb +1 -1
- data/mlb_terminal.gemspec +3 -0
- metadata +19 -3
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mlb_terminal (0.0.
|
4
|
+
mlb_terminal (0.0.5)
|
5
5
|
activesupport (~> 3.2.8)
|
6
|
+
chronic (~> 0.8.0)
|
6
7
|
commander (~> 4.1.2)
|
7
8
|
nokogiri (~> 1.5.5)
|
8
9
|
|
@@ -12,6 +13,7 @@ GEM
|
|
12
13
|
activesupport (3.2.8)
|
13
14
|
i18n (~> 0.6)
|
14
15
|
multi_json (~> 1.0)
|
16
|
+
chronic (0.8.0)
|
15
17
|
commander (4.1.2)
|
16
18
|
highline (~> 1.6.11)
|
17
19
|
highline (1.6.15)
|
data/README.md
CHANGED
@@ -1,14 +1,76 @@
|
|
1
|
-
|
1
|
+
# MLB Terminal
|
2
2
|
|
3
|
-
Access to MLB baseball scores in the terminal.
|
3
|
+
Access to historical and real-time MLB baseball scores and stats in the terminal.
|
4
4
|
|
5
5
|
## Overview
|
6
6
|
|
7
7
|
Don't you just wish you could have a little terminal app to stream out real-time stats for a MLB baseball game? Look no further! _Please note, the use of this data is subjected to the terms put forth by the MLB. More information can be found here: [http://gdx.mlb.com/components/copyright.txt](http://gdx.mlb.com/components/copyright.txt). You're okay if you're using this data for individual use!_
|
8
8
|
|
9
|
-
|
9
|
+
Although there are several other gems out there that provide access to MLB Gamday data, `mlb_terminal` provides a one-stop shop for streaming data and piping it to other processes. For the true sports hacker in us all!
|
10
10
|
|
11
|
-
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
To install MLB Terminal, please [install Ruby 1.9.3 and RubyGems](http://docs.cloudfoundry.com/frameworks/ruby/installing-ruby.html). Then install MLB Terminal via:
|
14
|
+
|
15
|
+
gem install mlb_terminal
|
16
|
+
|
17
|
+
For more information regarding this gem, please visit the RubyGems page for [mlb_terminal](https://rubygems.org/gems/mlb_terminal).
|
18
|
+
|
19
|
+
## Syntax
|
20
|
+
|
21
|
+
Typical usage starts off by scanning the games for a specific date:
|
22
|
+
|
23
|
+
> mlb games --date yesterday
|
24
|
+
|
25
|
+
0 Athletics (0-2) @ Tigers (2-0) 12:00 ET (Final) 4-5
|
26
|
+
1 Nationals (1-0) @ Cardinals (0-1) 3:00 ET (Final) 3-2
|
27
|
+
2 Yankees (1-0) @ Orioles (0-1) 6:00 ET (Final) 7-2
|
28
|
+
3 Reds (2-0) @ Giants (0-2) 9:30 ET (Final) 9-0
|
29
|
+
|
30
|
+
If the `--date` flag isn't used, all commands will assume today.
|
31
|
+
|
32
|
+
Then you can use the index in the first column to pull out additional data, such as game events, pitches and hits.
|
33
|
+
|
34
|
+
> mlb game --date yesterday --pitches 1 | head | cut -f 1,4-6
|
35
|
+
|
36
|
+
2012-10-07 15:08:11 -0400 Adam Wainwright Jayson Werth B
|
37
|
+
2012-10-07 15:08:29 -0400 Adam Wainwright Jayson Werth S
|
38
|
+
2012-10-07 15:08:53 -0400 Adam Wainwright Jayson Werth B
|
39
|
+
2012-10-07 15:09:08 -0400 Adam Wainwright Jayson Werth S
|
40
|
+
2012-10-07 15:09:53 -0400 Adam Wainwright Jayson Werth S
|
41
|
+
2012-10-07 15:10:40 -0400 Adam Wainwright Bryce Harper X
|
42
|
+
2012-10-07 15:10:55 -0400 Adam Wainwright Ryan Zimmerman S
|
43
|
+
2012-10-07 15:11:13 -0400 Adam Wainwright Ryan Zimmerman B
|
44
|
+
2012-10-07 15:11:33 -0400 Adam Wainwright Ryan Zimmerman S
|
45
|
+
2012-10-07 15:12:16 -0400 Adam Wainwright Ryan Zimmerman S
|
46
|
+
|
47
|
+
> mlb game --date yesterday --hits 1 | head
|
48
|
+
|
49
|
+
1 Top Adam Wainwright Bryce Harper O Groundout 140.56 163.65
|
50
|
+
1 Bottom Gio Gonzalez Carlos Beltran O Groundout 140.56 162.65
|
51
|
+
1 Bottom Gio Gonzalez Allen Craig O Flyout 128.51 82.33
|
52
|
+
2 Top Adam Wainwright Ian Desmond H Single 134.54 87.35
|
53
|
+
2 Top Adam Wainwright Kurt Suzuki H Single 87.35 132.53
|
54
|
+
2 Top Adam Wainwright Jayson Werth O Groundout 111.45 164.66
|
55
|
+
2 Bottom Gio Gonzalez David Freese O Flyout 125.5 47.19
|
56
|
+
2 Bottom Gio Gonzalez Jon Jay O Flyout 73.29 108.43
|
57
|
+
2 Bottom Gio Gonzalez Carlos Beltran O Flyout 145.58 71.29
|
58
|
+
3 Top Adam Wainwright Ryan Zimmerman H Single 113.45 98.39
|
59
|
+
|
60
|
+
> mlb game --date yesterday --pitches 1 | head
|
61
|
+
|
62
|
+
2012-10-07 1 Top 1 2/3/1 Jayson Werth strikes out swinging.
|
63
|
+
2012-10-07 1 Top 2 0/0/2 Bryce Harper grounds out, second baseman Daniel Descalso to first baseman Allen Craig.
|
64
|
+
2012-10-07 1 Top 3 1/3/3 Ryan Zimmerman strikes out swinging.
|
65
|
+
2012-10-07 1 Bottom 4 1/3/1 Jon Jay called out on strikes.
|
66
|
+
2012-10-07 1 Bottom 5 2/1/2 Carlos Beltran grounds out, second baseman Danny Espinosa to first baseman Adam LaRoche.
|
67
|
+
2012-10-07 1 Bottom 6 4/1/2 Matt Holliday walks.
|
68
|
+
2012-10-07 1 Bottom 7 2/2/3 Allen Craig flies out to center fielder Bryce Harper.
|
69
|
+
2012-10-07 2 Top 8 4/1/0 Adam LaRoche walks.
|
70
|
+
2012-10-07 2 Top 9 0/3/1 Michael Morse strikes out swinging.
|
71
|
+
2012-10-07 2 Top 10 0/1/1 Ian Desmond singles on a line drive to center fielder Jon Jay. Adam LaRoche to 3rd.
|
72
|
+
|
73
|
+
### Commands
|
12
74
|
|
13
75
|
To find out more about a specific command, use `mlb [command] --help` to view the appropriate documentation.
|
14
76
|
|
@@ -16,7 +78,7 @@ To find out more about a specific command, use `mlb [command] --help` to view th
|
|
16
78
|
* `games [options]`: Print out a list of scheduled games for the specified date
|
17
79
|
* `game [options] [game_number]`: Print out play-by-play events for a specific game. Use `--pitches` to output realtime pitch trajectory data.
|
18
80
|
|
19
|
-
|
81
|
+
### Global options
|
20
82
|
|
21
83
|
* -h, --help: Display help documentation
|
22
84
|
|
@@ -24,29 +86,30 @@ To find out more about a specific command, use `mlb [command] --help` to view th
|
|
24
86
|
|
25
87
|
* -t, --trace: Display backtrace when an error occurs
|
26
88
|
|
27
|
-
|
89
|
+
## Data Output Format
|
28
90
|
|
29
91
|
Each command outputs data in tab-separated format. When outputting data for a game in progress, the application will continue to pipe in data as it is made available.
|
30
92
|
|
31
|
-
|
93
|
+
### `games` (Game listings)
|
32
94
|
|
33
95
|
1. Game index. A numbered value unique to the specified date that is referenced in the `game` command.
|
34
96
|
2. Opposing teams. A string containing: `<Away Team> (Wins - Losses) @ <Home Team> (Wins - Losses).
|
35
97
|
3. Starting time and status.
|
36
98
|
4. Current score.
|
37
99
|
|
38
|
-
|
100
|
+
### `game` (Game events)
|
39
101
|
|
40
102
|
1. Event time.
|
41
103
|
2. Inning.
|
42
|
-
3.
|
43
|
-
4. Event
|
104
|
+
3. Top or bottom of inning.
|
105
|
+
4. Event number.
|
106
|
+
5. Event description.
|
44
107
|
|
45
|
-
|
108
|
+
### `game --pitches` (Pitch events)
|
46
109
|
|
47
110
|
1. Pitch time.
|
48
111
|
2. Inning.
|
49
|
-
3. Top
|
112
|
+
3. Top or bottom of inning.
|
50
113
|
4. Pitcher name.
|
51
114
|
5. Batter name.
|
52
115
|
6. Pitch type. (S-Strike, B-Ball, X-hit)
|
@@ -93,10 +156,25 @@ Each command outputs data in tab-separated format. When outputting data for a ga
|
|
93
156
|
|
94
157
|
For more information regarding PITCHf/x tracjectory data, please visit [http://fastballs.wordpress.com/category/pitchfx-glossary/](http://fastballs.wordpress.com/category/pitchfx-glossary/).
|
95
158
|
|
96
|
-
###
|
159
|
+
### `game --hits` (Hit events)
|
160
|
+
|
161
|
+
You also have access to hit locations for each batter. However, the coordinate system that is used relies on a 250-by-250 pixel image where the corresponding scale depends on which stadium the hit was made at. See the examples of how hits can be plotted on a generic baseball field.
|
162
|
+
|
163
|
+
1. Inning.
|
164
|
+
2. Top or bottom of inning.
|
165
|
+
3. Pitcher.
|
166
|
+
4. Batter.
|
167
|
+
5. Hit / Out / Error.
|
168
|
+
6. Description of hit.
|
169
|
+
7. X-coordinate.
|
170
|
+
8. Y-coordinate.
|
171
|
+
|
172
|
+
## Examples
|
173
|
+
|
174
|
+
List todays games:
|
97
175
|
|
98
|
-
> # List todays games
|
99
176
|
> mlb games
|
177
|
+
|
100
178
|
0 Red Sox (69-88) @ Orioles (90-67) 7:05 ET (F) 1-9
|
101
179
|
1 Reds (95-62) @ Pirates (76-81) 7:05 ET (F) 1-0
|
102
180
|
2 Royals (70-87) @ Indians (66-91) 7:05 ET (F) 5-8
|
@@ -113,12 +191,16 @@ For more information regarding PITCHf/x tracjectory data, please visit [http://f
|
|
113
191
|
13 Giants (92-65) @ Padres (74-83) 10:05 ET (F) 3-1
|
114
192
|
14 Rockies (62-95) @ Dodgers (82-75) 10:10 ET (F) 0-8
|
115
193
|
|
116
|
-
|
194
|
+
How did the Nationals do on 5/30/2012?
|
195
|
+
|
117
196
|
> mlb games --date 2012-05-30 | grep -i nationals | cut -f 2,4
|
197
|
+
|
118
198
|
Nationals (29-21) @ Marlins (29-22) 3-5
|
119
199
|
|
120
|
-
|
200
|
+
How did Bryce Harper do tonight?
|
201
|
+
|
121
202
|
> mlb games | grep Nationals | cut -f 1 | xargs mlb game | grep Harper
|
203
|
+
|
122
204
|
2012-09-29 19:18:00 1 2 1/2/1 Bryce Harper singles on a soft line drive to center fielder Jon Jay.
|
123
205
|
2012-09-29 19:20:11 1 3 1/2/1 Ryan Zimmerman doubles (36) on a fly ball to left fielder Matt Holliday. Bryce Harper to 3rd.
|
124
206
|
2012-09-29 19:26:56 1 5 0/0/1 Play reviewed and overturned: Michael Morse hits a grand slam (17) to right field. Bryce Harper scores. Ryan Zimmerman scores. Adam LaRoche scores.
|
@@ -133,13 +215,78 @@ For more information regarding PITCHf/x tracjectory data, please visit [http://f
|
|
133
215
|
2012-09-29 22:10:49 9 71 1/0/2 Bryce Harper doubles (25) on a line drive to left fielder Matt Holliday.
|
134
216
|
2012-09-29 22:21:20 9 76 0/0/2 Jon Jay out on a sacrifice fly to center fielder Bryce Harper. Pete Kozma scores.
|
135
217
|
|
136
|
-
|
218
|
+
Visualize pitch speed for Gio Gonzalez on his full game on August 8, 2012.
|
219
|
+
|
137
220
|
> mlb games --date 2012-08-08 \
|
138
221
|
| grep Nationals \
|
139
222
|
| cut -f 1 \
|
140
223
|
| xargs mlb game --pitches --date 2012-08-08 \
|
141
224
|
| awk 'BEGIN{FS="\t"}{ if ($4=="Gio Gonzalez") print}' \
|
142
225
|
| cut -f 1,9,6 \
|
143
|
-
| Rscript -e
|
144
|
-
|
226
|
+
| Rscript -e "
|
227
|
+
library(ggplot2); \
|
228
|
+
library(scales); \
|
229
|
+
d <- read.csv('stdin', header=F, sep='\\\\t', col.names=c('time', 'type', 'pitch_speed')); \
|
230
|
+
png('gio-pitch-speed.png'); \
|
231
|
+
ggplot(d, aes(x=as.POSIXlt(time), y=pitch_speed, colour=type, shape=type)) \
|
232
|
+
+ geom_point() \
|
233
|
+
+ labs(title='Pitch Speed Over Time for Gio Gonzalez', x='Time', y='Pitch Speed') \
|
234
|
+
+ scale_x_datetime(breaks=date_breaks('1 hour'), minor_breaks=date_breaks('15 min'), labels=date_format('%H:%M')) \
|
235
|
+
+ scale_colour_discrete(name = 'Pitch Type') \
|
236
|
+
+ scale_shape_discrete(name = 'Pitch Type'); \
|
237
|
+
dev.off()"
|
238
|
+
|
239
|
+
|
240
|
+
|
145
241
|

|
242
|
+
|
243
|
+
Get a breakdown of pitch types for Ross Detwiler in this season up until 9/30/2012.
|
244
|
+
|
245
|
+
> mlb pitchers --date 2012-09-30 11 \
|
246
|
+
| grep "Ross Detwiler" \
|
247
|
+
| cut -f 2 \
|
248
|
+
| xargs mlb pitcher --date 2012-09-30 11 \
|
249
|
+
| cut -f 8,9 \
|
250
|
+
| awk 'BEGIN{FS="\t"}{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' \
|
251
|
+
| sort
|
252
|
+
Changeup 172
|
253
|
+
Four-seam Fastball 1136
|
254
|
+
Sinker 838
|
255
|
+
Slider 314
|
256
|
+
|
257
|
+
What is Adam LaRoche's last 30-day spray pattern compared to that of 60-90 days ago?
|
258
|
+
|
259
|
+
> for DAY in `seq 1 30; seq 60 90`
|
260
|
+
do
|
261
|
+
mlb games --date "$DAY days ago" \
|
262
|
+
| grep Nationals \
|
263
|
+
| cut -f 1 \
|
264
|
+
| xargs mlb game --date "$DAY days ago" --hits \
|
265
|
+
| grep "Adam LaRoche" \
|
266
|
+
| cut -f 5-8 \
|
267
|
+
| sed -e "s/^/Day #DAY /"
|
268
|
+
done \
|
269
|
+
| Rscript -e " \
|
270
|
+
library(ggplot2); \
|
271
|
+
library(png); \
|
272
|
+
library(gridExtra); \
|
273
|
+
field_url <- 'http://i.imgur.com/0phAi.png'; \
|
274
|
+
download.file(field_url, '/tmp/baseball-field.png', mode = 'wb'); \
|
275
|
+
m <- readPNG('/tmp/baseball-field.png', FALSE); \
|
276
|
+
w <- matrix(rgb(m[,,1],m[,,2],m[,,3], m[,,4] * 0.2), nrow=dim(m)[1]); \
|
277
|
+
d <- read.csv('stdin', header=F, sep='\\\\t', col.names=c('time', 'type', 'desc', 'x', 'y')); \
|
278
|
+
png('laroche-spray-chart.png', width=600, height=1200); \
|
279
|
+
ggplot(d, aes(x,y, shape=type, colour=type)) \
|
280
|
+
+ geom_point() \
|
281
|
+
+ annotation_custom(xmin=-Inf, ymin=-Inf, xmax=Inf, ymax=Inf, rasterGrob(w)) \
|
282
|
+
+ labs(title='Hit Locations For Adam LaRoche', x='', y='') \
|
283
|
+
+ scale_x_continuous(breaks=c(), limits = c(0,250)) \
|
284
|
+
+ scale_y_continuous(breaks=c(), limits = c(0,250)) \
|
285
|
+
+ theme(panel.grid.minor = element_blank(), \
|
286
|
+
panel.grid.minor = element_blank(), \
|
287
|
+
panel.background = element_blank(), \
|
288
|
+
axis.ticks = element_blank()) \
|
289
|
+
+ facet_grid(time ~ .); \
|
290
|
+
dev.off();"
|
291
|
+
|
292
|
+

|
data/bin/mlb
CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
|
|
4
4
|
require 'commander/import'
|
5
5
|
require 'mlb_terminal'
|
6
6
|
require 'date'
|
7
|
+
require 'chronic'
|
7
8
|
|
8
9
|
program :version, MLBTerminal::VERSION
|
9
10
|
program :description, 'Stream MLB games into the terminal'
|
@@ -13,11 +14,11 @@ command :games do |c|
|
|
13
14
|
c.summary = 'Print out a list of scheduled games for the specified date.'
|
14
15
|
c.description = 'Print out a tab-seperated value list to STDOUT wih columns ' \
|
15
16
|
'for index, team names, game status, and current score.'
|
16
|
-
c.example 'description', 'mlb --date "
|
17
|
+
c.example 'description', 'mlb --date "3 days ago" | grep Nationals'
|
17
18
|
c.option '--date STRING', String, 'List games for specified dates (Default: today)'
|
18
19
|
c.action do |args, options|
|
19
20
|
options.default :date => Time.now.to_date.to_s
|
20
|
-
MLBTerminal::Game.list(
|
21
|
+
MLBTerminal::Game.list(Chronic.parse(options.date)).each_with_index do |game, index|
|
21
22
|
puts [
|
22
23
|
index,
|
23
24
|
"#{game[:away_team][:name]} " \
|
@@ -52,7 +53,7 @@ command :pitchers do |c|
|
|
52
53
|
|
53
54
|
game_number = args.first.to_i
|
54
55
|
|
55
|
-
gameday_id = MLBTerminal::Game.list(
|
56
|
+
gameday_id = MLBTerminal::Game.list(Chronic.parse(options.date))[game_number][:game_id]
|
56
57
|
|
57
58
|
MLBTerminal::Pitcher.list(gameday_id).each_pair do |pitcher_id, pitcher_info|
|
58
59
|
puts [
|
@@ -96,7 +97,7 @@ command :pitcher do |c|
|
|
96
97
|
end
|
97
98
|
|
98
99
|
game_number = game_number.to_i
|
99
|
-
games = MLBTerminal::Game.list(
|
100
|
+
games = MLBTerminal::Game.list(Chronic.parse(options.date))
|
100
101
|
gameday_id = games[game_number][:game_id]
|
101
102
|
pitcher = MLBTerminal::Pitcher.new(gameday_id, pitcher_id)
|
102
103
|
|
@@ -124,15 +125,15 @@ end
|
|
124
125
|
command :game do |c|
|
125
126
|
c.syntax = 'mlb game [options] [game-number]'
|
126
127
|
c.summary = 'Print game events'
|
127
|
-
c.description = 'Print play-by-play action for the corresponding game. Columns: time, inning, balls/strikes/outs/description.'
|
128
|
-
c.example 'description', 'command example'
|
128
|
+
c.description = 'Print play-by-play action for the corresponding game. Columns: time, inning, balls/strikes/outs/description. When the --pitches flag is used, columns include: time, inning, inning location, pitcher, batter, pitch type, x (old), y (old), start speed, end speed, top of strike zone, bottom of strike zone, horizontal movement, vertical movement, x-location at plate, y-location at plate, initial horizontal location, initial distance from home plate, initial height position, initial x-velocity, initial y-velocity, initial z-velocity, breaking point, breaking angle, breaking length, pitch type, pitch type confidence, pitch zone, nasty factor, spin direction, spin rate, comments and an unknown field. When --hits is specified, fields include: inning, inning location, pitcher, batter, Hit/Out/Error designation, description of hit, x-location (in pixels based on 250x250 image), y-location (in pixels based on 250x250 image).'
|
129
129
|
c.option '--date STRING', String, 'Specify the date for the corresponding game number.'
|
130
130
|
c.option '--pitches', 'Print pitch-by-pitch action'
|
131
|
+
c.option '--hits', 'Print hit locations'
|
131
132
|
c.action do |args, options|
|
132
133
|
options.default :date => Time.now.to_date.to_s
|
133
134
|
|
134
135
|
# Input validation.
|
135
|
-
date = (
|
136
|
+
date = (Chronic.parse(options.date) rescue Time.now)
|
136
137
|
if (Float(args.first) rescue nil).nil?
|
137
138
|
puts "Error: Game number must be a valid integer"
|
138
139
|
break
|
@@ -152,7 +153,7 @@ command :game do |c|
|
|
152
153
|
if options.pitches
|
153
154
|
game.pitches.each do |pitch|
|
154
155
|
puts [
|
155
|
-
pitch[:time].getlocal
|
156
|
+
pitch[:time].getlocal,
|
156
157
|
pitch[:inning],
|
157
158
|
pitch[:inning_loc],
|
158
159
|
pitch[:pitcher],
|
@@ -189,17 +190,30 @@ command :game do |c|
|
|
189
190
|
pitch[:cc],
|
190
191
|
pitch[:mt]].join("\t")
|
191
192
|
end
|
193
|
+
elsif options.hits
|
194
|
+
game.hits.each do |hit|
|
195
|
+
puts [
|
196
|
+
hit[:inning],
|
197
|
+
hit[:inning_loc],
|
198
|
+
hit[:pitcher],
|
199
|
+
hit[:batter],
|
200
|
+
hit[:type],
|
201
|
+
hit[:desc],
|
202
|
+
hit[:x],
|
203
|
+
hit[:y]].join("\t")
|
204
|
+
end
|
192
205
|
else
|
193
206
|
game.events.each do |event|
|
194
207
|
puts [
|
195
|
-
event[:time].getlocal.
|
208
|
+
event[:time].getlocal.to_date.to_s,
|
196
209
|
event[:inning],
|
210
|
+
event[:inning_loc],
|
197
211
|
event[:num],
|
198
212
|
"#{event[:balls]}/#{event[:strikes]}/#{event[:outs]}",
|
199
213
|
event[:desc]].join("\t")
|
200
214
|
end
|
201
215
|
end
|
202
|
-
rescue SystemExit, Interrupt
|
216
|
+
rescue SystemExit, Interrupt, Errno::EPIPE
|
203
217
|
# Do nothing if a user issues ctrl-c.
|
204
218
|
end
|
205
219
|
end
|
data/lib/mlb_terminal/game.rb
CHANGED
@@ -33,15 +33,19 @@ module MLBTerminal
|
|
33
33
|
@base_url = Game.parse_gameday_id_to_url gameday
|
34
34
|
end
|
35
35
|
|
36
|
-
def events(delay =
|
36
|
+
def events(delay = 2, &block)
|
37
37
|
last_atbat = 0
|
38
38
|
|
39
39
|
Enumerator.new do |y|
|
40
40
|
begin
|
41
41
|
doc = Nokogiri::HTML(open "#{@base_url}/game_events.xml")
|
42
|
+
|
43
|
+
if doc.xpath("//game/inning/*/atbat").count == 0
|
44
|
+
break
|
45
|
+
end
|
42
46
|
|
43
47
|
doc.xpath("//game/inning[*/atbat/@num > #{last_atbat}]").each do |inning|
|
44
|
-
inning.xpath("*/atbat").each do |at_bat|
|
48
|
+
inning.xpath("*/atbat[@num > #{last_atbat}]").each do |at_bat|
|
45
49
|
y.yield({
|
46
50
|
:inning => inning["num"],
|
47
51
|
:inning_loc => at_bat.xpath("..").first.name.camelcase,
|
@@ -56,21 +60,45 @@ module MLBTerminal
|
|
56
60
|
|
57
61
|
last_atbat = doc.xpath("//game/inning/*/atbat/@num").map(&:value).map(&:to_i).max
|
58
62
|
|
59
|
-
if
|
63
|
+
if game_status != "F"
|
64
|
+
sleep delay
|
65
|
+
end
|
66
|
+
end while game_status != "F"
|
67
|
+
end.each(&block)
|
68
|
+
end
|
69
|
+
|
70
|
+
def hits(delay = 2, &block)
|
71
|
+
players = player_lookup
|
72
|
+
next_hit = 0
|
73
|
+
Enumerator.new do |y|
|
74
|
+
begin
|
75
|
+
doc = Nokogiri::HTML(open "#{@base_url}/inning/inning_hit.xml")
|
76
|
+
doc.xpath("//hitchart/hip").slice(next_hit..-1).each do |hit|
|
77
|
+
y.yield({
|
78
|
+
:inning => hit["inning"],
|
79
|
+
:inning_loc => (hit["team"]=="A" ? "Top" : "Bottom"),
|
80
|
+
:batter => players[hit["batter"]],
|
81
|
+
:pitcher => players[hit["pitcher"]],
|
82
|
+
:type => hit["type"],
|
83
|
+
:desc => hit["des"],
|
84
|
+
:x => hit["x"].to_f,
|
85
|
+
:y => hit["y"].to_f})
|
86
|
+
end
|
87
|
+
if game_status != "F"
|
60
88
|
sleep delay
|
61
|
-
doc = Nokogiri::HTML(open "#{@base_url}/inning/inning_all.xml")
|
62
89
|
end
|
90
|
+
next_hit = doc.xpath("//hitchart/hip").count
|
63
91
|
end while game_status != "F"
|
64
92
|
end.each(&block)
|
65
93
|
end
|
66
94
|
|
67
|
-
def pitches(delay =
|
95
|
+
def pitches(delay = 2, &block)
|
68
96
|
last_pitch = 0
|
69
97
|
players = player_lookup
|
70
|
-
doc = Nokogiri::HTML(open "#{@base_url}/inning/inning_all.xml")
|
71
98
|
|
72
99
|
Enumerator.new do |y|
|
73
100
|
begin
|
101
|
+
doc = Nokogiri::HTML(open "#{@base_url}/inning/inning_all.xml")
|
74
102
|
doc.xpath("//game/inning[*/*/pitch/@id > #{last_pitch}]").each do |inning|
|
75
103
|
|
76
104
|
inning.xpath("*/atbat").each do |at_bat|
|
@@ -123,7 +151,6 @@ module MLBTerminal
|
|
123
151
|
|
124
152
|
if doc.xpath("//game").first["ind"] != "F"
|
125
153
|
sleep delay
|
126
|
-
doc = Nokogiri::HTML(open "#{@base_url}/inning/inning_all.xml")
|
127
154
|
end
|
128
155
|
end while game_status != "F"
|
129
156
|
end.each(&block)
|
data/lib/mlb_terminal/version.rb
CHANGED
data/mlb_terminal.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mlb_terminal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: commander
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.2.8
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: chronic
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.8.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.8.0
|
62
78
|
description: A small terminal app to pipe formatted MLB baseball feeds into the terminal
|
63
79
|
for easy manipulation. Includes access to both historic and real-time baseball feeds
|
64
80
|
including play-by-play and pitch-by-pitch data. Visit the homepage for examples!
|
@@ -92,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
108
|
requirements:
|
93
109
|
- - ! '>='
|
94
110
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
111
|
+
version: '1.9'
|
96
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
113
|
none: false
|
98
114
|
requirements:
|