mlb_terminal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@mlb-terminal --create
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mlb_terminal (0.0.1)
5
+ commander
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ commander (4.1.2)
12
+ highline (~> 1.6.11)
13
+ highline (1.6.15)
14
+ nokogiri (1.5.5)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ mlb_terminal!
@@ -0,0 +1,46 @@
1
+ # MLB Terminal
2
+
3
+ Access to MLB baseball scores in the terminal.
4
+
5
+ ## Overview
6
+
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!
8
+
9
+ ### Syntax
10
+
11
+ #### Commands
12
+
13
+ * help: Display global or [command] help documentation.
14
+ * list: Print out a list of scheduled games for the specified date
15
+
16
+ #### Global options
17
+
18
+ * -h, --help: Display help documentation
19
+
20
+ * -v, --version: Display version information
21
+
22
+ * -t, --trace: Display backtrace when an error occurs
23
+
24
+ ### Examples
25
+
26
+ > # List todays games
27
+ > mlb list
28
+ 0 Red Sox (69-88) @ Orioles (90-67) 7:05 ET (F) 1-9
29
+ 1 Reds (95-62) @ Pirates (76-81) 7:05 ET (F) 1-0
30
+ 2 Royals (70-87) @ Indians (66-91) 7:05 ET (F) 5-8
31
+ 3 Yankees (91-66) @ Blue Jays (69-88) 7:07 ET (F) 11-4
32
+ 4 Phillies (78-79) @ Marlins (67-90) 7:10 ET (F) 1-2
33
+ 5 Mets (73-84) @ Braves (91-66) 7:35 ET (F) 3-1
34
+ 6 Angels (87-70) @ Rangers (92-65) 8:05 ET (F) 7-4
35
+ 7 Tigers (84-73) @ Twins (66-91) 8:10 ET (F) 2-4
36
+ 8 Astros (52-105) @ Brewers (80-77) 8:10 ET (F) 7-6
37
+ 9 Rays (86-71) @ White Sox (83-74) 8:10 ET (F) 1-3
38
+ 10 Nationals (95-62) @ Cardinals (85-72) 8:15 ET (F) 2-12
39
+ 11 Cubs (59-98) @ D-backs (79-78) 9:40 ET (F) 3-8
40
+ 12 Mariners (73-84) @ Athletics (89-68) 10:05 ET (F) 2-8
41
+ 13 Giants (92-65) @ Padres (74-83) 10:05 ET (F) 3-1
42
+ 14 Rockies (62-95) @ Dodgers (82-75) 10:10 ET (F) 0-8
43
+
44
+ # How did the Nationals do on May 30th of this year?
45
+ > mlb list --date 2012-05-30 | grep -i nationals | cut -f 2,4
46
+ Nationals (29-21) @ Marlins (29-22) 3-5
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Open an irb session preloaded with this library"
4
+ task :console do
5
+ sh "irb -rubygems -I lib -r mlb_terminal.rb"
6
+ end
data/bin/mlb ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'mlb_terminal'
6
+ require 'date'
7
+
8
+ program :version, MLBTerminal::VERSION
9
+ program :description, 'Stream MLB games into the terminal'
10
+
11
+ command :list do |c|
12
+ c.syntax = 'mlb list [options]'
13
+ c.summary = 'Print out a list of scheduled games for the specified date'
14
+ c.description = 'Print out a tab-seperated value list to STDOUT wih columns ' \
15
+ 'for index, team names, game status, and current score.'
16
+ c.example 'description', 'mlb --date "2012-09-28" | grep Nationals'
17
+ c.option '--date STRING', String, 'List games for specified dates (Default: today)'
18
+ c.action do |args, options|
19
+ options.default :date => Time.now.to_date.to_s
20
+ MLBTerminal::Client.list_games(Date.parse options.date).each_with_index do |game, index|
21
+ puts [
22
+ index,
23
+ "#{game[:away_team][:name]} " \
24
+ "(#{game[:away_team][:wins]}-#{game[:away_team][:losses]}) " \
25
+ "@ #{game[:home_team][:name]} " \
26
+ "(#{game[:home_team][:wins]}-#{game[:home_team][:losses]})",
27
+ "#{game[:starts]} (#{game[:status]})",
28
+ "#{game[:score][:away]}-#{game[:score][:home]}"].join("\t")
29
+ end
30
+ end
31
+ end
32
+
33
+ command :watch do |c|
34
+ c.syntax = 'mlb watch [options]'
35
+ c.summary = ''
36
+ c.description = ''
37
+ c.example 'description', 'command example'
38
+ c.option '--some-switch', 'Some switch that does something'
39
+ c.action do |args, options|
40
+ # Do something or c.when_called Mlbterminal::Commands::Watch
41
+ end
42
+ end
43
+
@@ -0,0 +1,2 @@
1
+ require 'mlb_terminal/version'
2
+ require 'mlb_terminal/client'
@@ -0,0 +1,33 @@
1
+ require 'date'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module MLBTerminal
6
+ MLB_BASE_URL = 'http://gd2.mlb.com/components/game/mlb'
7
+
8
+ class Client
9
+ def self.list_games(date = Time.now.to_date)
10
+ doc = Nokogiri::HTML(open "#{base_url_for_date date}/scoreboard_iphone.xml")
11
+ doc.xpath("//games/game").map{|game|
12
+ {:home_team => {
13
+ :name => game["home_team_name"],
14
+ :wins => game["home_win"],
15
+ :losses => game["home_loss"]},
16
+ :away_team => {
17
+ :name => game["away_team_name"],
18
+ :wins => game["away_win"],
19
+ :losses => game["away_loss"]},
20
+ :score => {
21
+ :home => (game.xpath("linescore/r").first["home"] rescue nil),
22
+ :away => (game.xpath("linescore/r").first["away"] rescue nil)},
23
+ :starts => "#{game["time"]} #{game["time_zone"]}",
24
+ :status => game.xpath("status").first["ind"]}}
25
+ end
26
+
27
+ private
28
+
29
+ def self.base_url_for_date(date = Time.now.to_date)
30
+ "#{MLB_BASE_URL}/year_#{date.year}/month_#{"%02d" % date.month}/day_#{"%02d" % date.day}/"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module MLBTerminal
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mlb_terminal/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mlb_terminal"
7
+ s.version = MLBTerminal::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Stefan Novak"]
10
+ s.email = ["stefan.louis.novak@gmail.com"]
11
+ s.homepage = "https://github.com/slnovak/mlb_terminal"
12
+ s.description = %q{A small terminal app to translate MLB baseball feeds into the terminal for easy manipulation.}
13
+ s.summary = %q{Command line interface to keeping track of MLB ballgames}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "commander"
21
+ s.add_dependency "nokogiri"
22
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mlb_terminal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stefan Novak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: commander
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: nokogiri
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A small terminal app to translate MLB baseball feeds into the terminal
47
+ for easy manipulation.
48
+ email:
49
+ - stefan.louis.novak@gmail.com
50
+ executables:
51
+ - mlb
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .rvmrc
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - README.md
59
+ - Rakefile
60
+ - bin/mlb
61
+ - lib/mlb_terminal.rb
62
+ - lib/mlb_terminal/client.rb
63
+ - lib/mlb_terminal/version.rb
64
+ - mlb_terminal.gemspec
65
+ homepage: https://github.com/slnovak/mlb_terminal
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Command line interface to keeping track of MLB ballgames
89
+ test_files: []