sportify 0.2.0 → 1.0.0
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 +4 -4
- data/config/environment.rb +2 -1
- data/lib/cli/cli.rb +33 -26
- data/lib/players/mlb_player.rb +18 -0
- data/lib/scrapers/mlb_scraper.rb +21 -65
- data/lib/teams/mlb_team.rb +27 -0
- metadata +3 -2
- data/lib/leagues/mlb_teams.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95b846b5835f54e704d73d55a9f5a1a0983941dd
|
|
4
|
+
data.tar.gz: 7e1f7429029bed8128774ac2bfb3aab92087f163
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0578f797e0b91ce55838b433931d5eff6052c27fa206d7a702d5efa17eff1f5431b66c6026fc0f49df75623cfe1e10e967bbe600e5daed5992b2d06509dcaf26
|
|
7
|
+
data.tar.gz: 3bacf9cb36ea92bbd5a3b40b82e99373d1b34fbb80593d86d16d15f0acddb6b58d94d9d6393135df060ae33d86c1410ed4504dcd12e50e8d7b70eb2af0530558
|
data/config/environment.rb
CHANGED
data/lib/cli/cli.rb
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
class Sportify::CLI
|
|
2
2
|
|
|
3
3
|
def initialize
|
|
4
|
-
|
|
4
|
+
Sportify::MLBscraper.team_builder
|
|
5
5
|
main_menu
|
|
6
|
-
team_selector
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
def main_menu
|
|
10
9
|
puts "***** Welcome To Sportify *****"
|
|
11
10
|
puts ""
|
|
12
|
-
|
|
13
|
-
puts "#{index + 1}) #{team
|
|
11
|
+
Sportify::MLBteam.teams.each_with_index do |team, index|
|
|
12
|
+
puts "#{index + 1}) #{team.name}"
|
|
14
13
|
end
|
|
15
14
|
puts ""
|
|
16
15
|
puts "Enter the number of the team you want information on or type 'exit' to leave Sportify"
|
|
17
16
|
puts ""
|
|
17
|
+
team_selector
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def team_selector
|
|
21
21
|
input = gets.strip
|
|
22
22
|
puts ""
|
|
23
|
-
if input.to_i.between?(1,
|
|
24
|
-
team_menu(
|
|
23
|
+
if input.to_i.between?(1, Sportify::MLBteam.teams.length)
|
|
24
|
+
team_menu(Sportify::MLBteam.teams[input.to_i - 1])
|
|
25
25
|
elsif input.downcase == "exit"
|
|
26
26
|
puts "Goodbye"
|
|
27
27
|
else
|
|
@@ -31,8 +31,7 @@ class Sportify::CLI
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def team_menu(team)
|
|
34
|
-
puts ""
|
|
35
|
-
puts "You've selected the #{team[:team_name]}"
|
|
34
|
+
puts "You've selected the #{team.name}"
|
|
36
35
|
puts""
|
|
37
36
|
puts "Please choose an option"
|
|
38
37
|
puts ""
|
|
@@ -48,11 +47,14 @@ class Sportify::CLI
|
|
|
48
47
|
puts ""
|
|
49
48
|
case input
|
|
50
49
|
when 1
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
if team.roster_url == nil
|
|
51
|
+
Sportify::MLBscraper.roster_url(team)
|
|
52
|
+
active_roster_display(team)
|
|
53
|
+
else
|
|
54
|
+
active_roster_display(team)
|
|
55
|
+
end
|
|
54
56
|
when 2
|
|
55
|
-
|
|
57
|
+
main_menu
|
|
56
58
|
when 3
|
|
57
59
|
puts "Goodbye"
|
|
58
60
|
else
|
|
@@ -62,8 +64,11 @@ class Sportify::CLI
|
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def active_roster_display(team)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
if team.players.length == 0
|
|
68
|
+
Sportify::MLBscraper.player_builder(team)
|
|
69
|
+
end
|
|
70
|
+
team.players.each_with_index do |player, index|
|
|
71
|
+
puts "#{index + 1}) #{player.name}"
|
|
67
72
|
end
|
|
68
73
|
player_selector(team)
|
|
69
74
|
end
|
|
@@ -74,30 +79,32 @@ class Sportify::CLI
|
|
|
74
79
|
puts ""
|
|
75
80
|
input = gets.strip
|
|
76
81
|
puts ""
|
|
77
|
-
if input.to_i.between?(1,
|
|
78
|
-
player_display(
|
|
79
|
-
team_menu(team)
|
|
82
|
+
if input.to_i.between?(1, team.players.length)
|
|
83
|
+
player_display(team.players[input.to_i - 1])
|
|
80
84
|
elsif input.downcase == "menu"
|
|
81
85
|
team_menu(team)
|
|
82
86
|
else
|
|
83
|
-
|
|
84
|
-
player_selector(team)
|
|
87
|
+
active_roster_display(team)
|
|
85
88
|
end
|
|
86
89
|
end
|
|
87
90
|
|
|
88
91
|
def player_display(player)
|
|
89
|
-
player
|
|
90
|
-
|
|
92
|
+
if player.number == nil
|
|
93
|
+
Sportify::MLBscraper.add_player_data(player)
|
|
94
|
+
end
|
|
95
|
+
puts "You've selected #{player.name}"
|
|
96
|
+
puts ""
|
|
97
|
+
puts "Jersey Number: #{player.number}"
|
|
91
98
|
puts ""
|
|
92
|
-
puts "
|
|
99
|
+
puts "Position: #{player.position}"
|
|
93
100
|
puts ""
|
|
94
|
-
puts "
|
|
101
|
+
puts "#{player.bats_and_throws}"
|
|
95
102
|
puts ""
|
|
96
|
-
puts "#{player
|
|
103
|
+
puts "Height/Weight: #{player.height_weight}"
|
|
97
104
|
puts ""
|
|
98
|
-
puts "
|
|
105
|
+
puts "#{player.age}"
|
|
99
106
|
puts ""
|
|
100
|
-
|
|
107
|
+
team_menu(player.team)
|
|
101
108
|
end
|
|
102
109
|
|
|
103
110
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Sportify::MLBplayer
|
|
2
|
+
|
|
3
|
+
attr_accessor :name, :player_url, :team, :number, :position, :bats_and_throws, :height_weight, :age
|
|
4
|
+
|
|
5
|
+
@@all = []
|
|
6
|
+
|
|
7
|
+
def initialize(name = nil, player_url = nil, team = nil)
|
|
8
|
+
@name = name
|
|
9
|
+
@player_url = player_url
|
|
10
|
+
@team = team
|
|
11
|
+
@@all << self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.all
|
|
15
|
+
@@all
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
data/lib/scrapers/mlb_scraper.rb
CHANGED
|
@@ -1,81 +1,37 @@
|
|
|
1
1
|
class Sportify::MLBscraper
|
|
2
2
|
|
|
3
|
-
@@
|
|
4
|
-
@@root_html = open(@@root_url)
|
|
5
|
-
@@root_doc = Nokogiri::HTML(@@root_html)
|
|
3
|
+
@@team_data = Nokogiri::HTML(open("https://www.mlb.com/team")).css("div.p-featured-content__body")
|
|
6
4
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
teams << team.text
|
|
5
|
+
def self.team_builder
|
|
6
|
+
@@team_data.each do |data|
|
|
7
|
+
Sportify::MLBteam.new(name = data.css("a").css("div.u-text-h4.u-text-flow").text, team_url = data.css("div.p-wysiwyg").css("a")[0]["href"])
|
|
11
8
|
end
|
|
12
|
-
teams
|
|
13
9
|
end
|
|
14
10
|
|
|
15
|
-
def
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
team_urls
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def roster_doc(team)
|
|
24
|
-
team_html = open(team[:team_url])
|
|
25
|
-
team_doc = Nokogiri::HTML(team_html)
|
|
26
|
-
if team[:team_url] == "https://www.mlb.com/reds" || team[:team_url] == "https://www.mlb.com/dodgers" || team[:team_url] == "https://www.mlb.com/giants"
|
|
27
|
-
roster_url = team_doc.css("div.megamenu-navbar").css("a.megamenu-static-navbar__menu-item.megamenu-static-navbar__menu-item--roster").attribute("href").value
|
|
11
|
+
def self.roster_url(team)
|
|
12
|
+
team_home_page = Nokogiri::HTML(open(team.team_url))
|
|
13
|
+
if team.team_url == "https://www.mlb.com/reds" || team.team_url == "https://www.mlb.com/dodgers" || team.team_url == "https://www.mlb.com/giants"
|
|
14
|
+
roster_url = team_home_page.css("div.megamenu-navbar").css("a.megamenu-static-navbar__menu-item.megamenu-static-navbar__menu-item--roster").attribute("href").value
|
|
28
15
|
else
|
|
29
|
-
roster_url =
|
|
16
|
+
roster_url = team_home_page.css("div.megamenu-navbar").css("a.megamenu-static-navbar__menu-item.megamenu-static-navbar__menu-item--team").attribute("href").value
|
|
30
17
|
end
|
|
31
|
-
|
|
32
|
-
Nokogiri::HTML(roster_html)
|
|
18
|
+
team.roster_url = roster_url
|
|
33
19
|
end
|
|
34
20
|
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
def self.player_builder(team)
|
|
22
|
+
@team = team
|
|
23
|
+
Nokogiri::HTML(open(@team.roster_url)).css("td.dg-name_display_first_last").css("a").each do |data|
|
|
24
|
+
@team.add_player(Sportify::MLBplayer.new(player_name = data.text, player_url = team.team_url + data["href"], team = @team))
|
|
39
25
|
end
|
|
40
|
-
roster
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def player_urls(team)
|
|
44
|
-
player_urls = []
|
|
45
|
-
team_url = team[:team_url]
|
|
46
|
-
roster_doc(team).css("td.dg-name_display_first_last").css("a").each do |player|
|
|
47
|
-
player_urls << team_url + player["href"]
|
|
48
|
-
end
|
|
49
|
-
player_urls
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def player_doc(player)
|
|
53
|
-
html = open(player[:player_url])
|
|
54
|
-
Nokogiri::HTML(html)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def name(player)
|
|
58
|
-
player_doc(player).css("span.player-header--vitals-name").text
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def number(player)
|
|
62
|
-
player_doc(player).css("span.player-header--vitals-number").text
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def position(player)
|
|
66
|
-
player_doc(player).css("div.player-header--vitals").css("ul").css("li")[0].text
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def bats_and_throws(player)
|
|
70
|
-
player_doc(player).css("div.player-header--vitals").css("ul").css("li")[1].text
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def height_weight(player)
|
|
74
|
-
player_doc(player).css("div.player-header--vitals").css("ul").css("li.player-header--vitals-height").text
|
|
75
26
|
end
|
|
76
27
|
|
|
77
|
-
def
|
|
78
|
-
|
|
28
|
+
def self.add_player_data(player)
|
|
29
|
+
data = Nokogiri::HTML(open(player.player_url))
|
|
30
|
+
player.number = data.css("span.player-header--vitals-number").text
|
|
31
|
+
player.position = data.css("div.player-header--vitals").css("ul").css("li")[0].text
|
|
32
|
+
player.bats_and_throws = data.css("div.player-header--vitals").css("ul").css("li")[1].text
|
|
33
|
+
player.height_weight = data.css("div.player-header--vitals").css("ul").css("li.player-header--vitals-height").text
|
|
34
|
+
player.age = data.css("div.player-header--vitals").css("ul").css("li.player-header--vitals-age").text
|
|
79
35
|
end
|
|
80
36
|
|
|
81
37
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class Sportify::MLBteam
|
|
2
|
+
|
|
3
|
+
attr_accessor :name, :team_url, :roster_url
|
|
4
|
+
|
|
5
|
+
@@teams = []
|
|
6
|
+
|
|
7
|
+
def initialize(name = nil, team_url = nil)
|
|
8
|
+
@name = name
|
|
9
|
+
@team_url = team_url
|
|
10
|
+
@@teams << self
|
|
11
|
+
@players = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.teams
|
|
15
|
+
@@teams.sort_by(&:name)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_player(player)
|
|
19
|
+
@players << player
|
|
20
|
+
player.team = self
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def players
|
|
24
|
+
@players
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sportify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bruce Hillsworth
|
|
@@ -108,9 +108,10 @@ files:
|
|
|
108
108
|
- bin/sportify
|
|
109
109
|
- config/environment.rb
|
|
110
110
|
- lib/cli/cli.rb
|
|
111
|
-
- lib/
|
|
111
|
+
- lib/players/mlb_player.rb
|
|
112
112
|
- lib/scrapers/mlb_scraper.rb
|
|
113
113
|
- lib/sportify.rb
|
|
114
|
+
- lib/teams/mlb_team.rb
|
|
114
115
|
homepage: https://rubygems.org/gems/sportify
|
|
115
116
|
licenses:
|
|
116
117
|
- MIT
|
data/lib/leagues/mlb_teams.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'pry'
|
|
2
|
-
|
|
3
|
-
class Sportify::MLBteams
|
|
4
|
-
|
|
5
|
-
def initialize
|
|
6
|
-
@scraper = Sportify::MLBscraper.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def teams
|
|
10
|
-
@scraper.teams.zip(@scraper.team_urls).map { |team, team_url| {team_name: team, team_url: team_url} }.sort_by { |team| team[:team_name] }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def roster(team)
|
|
14
|
-
@scraper.roster(team).zip(@scraper.player_urls(team)).map { |name, player_url| {name: name, player_url: player_url}}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def player_builder(player)
|
|
18
|
-
{
|
|
19
|
-
name: @scraper.name(player),
|
|
20
|
-
number: @scraper.number(player),
|
|
21
|
-
position: @scraper.position(player),
|
|
22
|
-
bats_and_throws: @scraper.bats_and_throws(player),
|
|
23
|
-
height_weight: @scraper.height_weight(player),
|
|
24
|
-
age: @scraper.age(player)
|
|
25
|
-
}
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|