nba-draft-2017 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +38 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/nba-draft-2017 +6 -0
- data/bin/setup +8 -0
- data/lib/nba_draft_2017.rb +10 -0
- data/lib/nba_draft_2017/cli.rb +209 -0
- data/lib/nba_draft_2017/player.rb +69 -0
- data/lib/nba_draft_2017/scraper.rb +127 -0
- data/lib/nba_draft_2017/version.rb +3 -0
- data/nba_draft_2017.gemspec +28 -0
- data/spec/nba_draft_spec.rb +11 -0
- data/spec/spec_helper.rb +14 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f0147b2d14e9de9f667cd81cf6f7bf961de71da
|
4
|
+
data.tar.gz: 7fd014c50775c251d4682dd2cb958e31216db3d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80b35e9b3e8f3c133f78f43aace50c75480c0f3164c8fffd447f8b5d536a1e0ec2823a149bf8282189786727df901d2551fb88a9e7e21d3195a42805b5473541
|
7
|
+
data.tar.gz: f78bae7c9d4656a7d00bed51fc6ebe4014dd8fdd6dada6a909b8f8bf68f0725e870a989556df6bac13662c1fa4460dacb4c182d2f617db3656ce5e95f5fd74ac
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 psnider30
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/NOTES.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Description: CLI gem for 2017 NBA draft picks
|
2
|
+
|
3
|
+
- A cli for the 2017 NBA draft from getting basic draft data from http://www.cbssports.com/nba/news/2017-nba-draft-picks-complete-results-full-list-of-players-selected-highlights-grades/ and more details on each player from http://www.nba.com/draft/2017/prospects/[PLAYERNAME]
|
4
|
+
|
5
|
+
user types nba-draft-2017
|
6
|
+
|
7
|
+
A list of options appears prompting the user to list the draft, see a player's stats and details, see player's' by NBA team, or see player's by former college or Country.
|
8
|
+
|
9
|
+
List draft
|
10
|
+
1. Markelle Fultz from Washington to 76ers
|
11
|
+
2. Lonzo Ball from UCLA to Lakers
|
12
|
+
etc
|
13
|
+
|
14
|
+
player details (What is a player?)
|
15
|
+
PLAYERNAME
|
16
|
+
round:_ pick:_
|
17
|
+
drafted as:
|
18
|
+
Height
|
19
|
+
Weight
|
20
|
+
STATS
|
21
|
+
PPG:
|
22
|
+
ASG:
|
23
|
+
RBG:
|
24
|
+
etc.
|
25
|
+
|
26
|
+
players by NBA team
|
27
|
+
ask user for input
|
28
|
+
for input = 'Warriors'
|
29
|
+
Rd. 2 Pick: 38 Jordan Bell from Oregon
|
30
|
+
(list all players that team drafted)
|
31
|
+
ask user if they want to see more player(s) details
|
32
|
+
|
33
|
+
players by Former team
|
34
|
+
ask user for input
|
35
|
+
for input = Washington
|
36
|
+
Rd. 1 Pick 1 Markelle Fultz to 76ers
|
37
|
+
(list all players that were on team and drafted into the NBA)
|
38
|
+
ask user if they want to see more player(s) details
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# NbaDraft2017
|
2
|
+
|
3
|
+
This Ruby Gem provides a Command Line Interface to view the 60 picks from the 2017 NBA draft. This draft class is thought to be very strong especially in lottery talent and will have significant impact on the future of many NBA teams. It displays a draft board, player stats, NBA team's picks, and picks from Former Schools or Countries.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nba-draft-2017'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nba-draft-2017
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Type the below and follow the on screen prompts
|
24
|
+
|
25
|
+
$ nba-draft-2017
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/psnider30/nba_draft_2017. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nba_draft_2017"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/nba-draft-2017
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'pry'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
|
7
|
+
require_relative "../lib/nba_draft_2017/version"
|
8
|
+
require_relative '../lib/nba_draft_2017/cli'
|
9
|
+
require_relative '../lib/nba_draft_2017/player'
|
10
|
+
require_relative '../lib/nba_draft_2017/scraper'
|
@@ -0,0 +1,209 @@
|
|
1
|
+
class NbaDraft2017::Cli
|
2
|
+
|
3
|
+
def call
|
4
|
+
puts 'Welcome to the 2017 NBA Draft!'
|
5
|
+
make_players
|
6
|
+
menu
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_draft
|
10
|
+
list_round_1
|
11
|
+
list_round_2
|
12
|
+
end
|
13
|
+
|
14
|
+
def list_round_1
|
15
|
+
dotted_line
|
16
|
+
puts "Round 1".colorize(:blue).bold
|
17
|
+
dotted_line
|
18
|
+
|
19
|
+
i = 0
|
20
|
+
while i < 30
|
21
|
+
player = NbaDraft2017::Player.all[i]
|
22
|
+
if i < 9
|
23
|
+
puts "#{i + 1}. #{player.name.colorize(:green).bold} #{player.position.colorize(:red)} from #{player.former_team.colorize(:blue).bold} drafted by #{player.nba_team.colorize(:green).bold}"
|
24
|
+
else
|
25
|
+
puts "#{i + 1}. #{player.name.colorize(:green).bold} #{player.position.colorize(:red)} from #{player.former_team.colorize(:blue).bold} drafted by #{player.nba_team.colorize(:green).bold}"
|
26
|
+
end
|
27
|
+
i += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
dotted_line
|
31
|
+
end
|
32
|
+
|
33
|
+
def list_round_2
|
34
|
+
puts "Round 2".colorize(:blue).bold
|
35
|
+
dotted_line
|
36
|
+
|
37
|
+
i = 30
|
38
|
+
while i < 60
|
39
|
+
player = NbaDraft2017::Player.all[i]
|
40
|
+
puts "#{i + 1}. #{player.name.colorize(:green).bold} #{player.position.colorize(:red)} from #{player.former_team.colorize(:blue).bold} drafted by #{player.nba_team.colorize(:green).bold}"
|
41
|
+
i += 1
|
42
|
+
end
|
43
|
+
|
44
|
+
dotted_line
|
45
|
+
end
|
46
|
+
|
47
|
+
def dotted_line
|
48
|
+
puts "------------------------------------------------------------".bold.colorize(:red)
|
49
|
+
end
|
50
|
+
|
51
|
+
def make_players
|
52
|
+
players_array = NbaDraft2017::Scraper.scrape_draft
|
53
|
+
NbaDraft2017::Player.create_from_collection(players_array)
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_attributes_to_player(player_name)
|
57
|
+
player = NbaDraft2017::Player.find_player_by_name(player_name)
|
58
|
+
attributes = NbaDraft2017::Scraper.scrape_player("http://www.nba.com/draft/2017/prospects/" + player.profile_url)
|
59
|
+
player.add_player_attributes(attributes)
|
60
|
+
player
|
61
|
+
end
|
62
|
+
|
63
|
+
def menu
|
64
|
+
input = nil
|
65
|
+
|
66
|
+
while input != 'exit'
|
67
|
+
list_controls
|
68
|
+
input = gets.strip.downcase
|
69
|
+
if input == 'draft'
|
70
|
+
list_draft
|
71
|
+
elsif input == 'rd1' || input == 'rd 1'
|
72
|
+
list_round_1
|
73
|
+
elsif input == 'rd2' || input == 'rd 2'
|
74
|
+
list_round_2
|
75
|
+
elsif input == 'player' || input == 'players'
|
76
|
+
find_and_list_player
|
77
|
+
elsif input == 'nba team' || input == 'nba'
|
78
|
+
list_draft_picks_by_nba_team
|
79
|
+
elsif input == 'former team' || input == 'former'
|
80
|
+
list_draft_picks_by_former_team
|
81
|
+
elsif input == 'exit'
|
82
|
+
good_bye
|
83
|
+
else
|
84
|
+
error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def list_controls
|
90
|
+
draft = "'draft'"
|
91
|
+
round_1 = "'rd1'"
|
92
|
+
round_2 = "'rd2'"
|
93
|
+
player = "'player'"
|
94
|
+
nba_team = "'nba'"
|
95
|
+
former_team = "'former'"
|
96
|
+
puts "Enter #{draft.colorize(:green)}, #{round_1.colorize(:green)} or #{round_2.colorize(:green)} to see list of draft picks."
|
97
|
+
puts "Enter #{player.colorize(:green)} to see player details and stats"
|
98
|
+
puts "Enter #{nba_team.colorize(:green)} to show players drafted by a NBA team"
|
99
|
+
puts "Enter #{former_team.colorize(:green)} to show players drated out of colleges or clubs"
|
100
|
+
puts "To quit, type" + " 'exit'".colorize(:green)
|
101
|
+
end
|
102
|
+
|
103
|
+
def find_and_list_player
|
104
|
+
puts "Please enter player draft pick number or player name."
|
105
|
+
lookup = gets.strip
|
106
|
+
|
107
|
+
if lookup.to_i.between?(1, NbaDraft2017::Player.all.size)
|
108
|
+
player = NbaDraft2017::Player.find_player_by_pick(lookup)
|
109
|
+
list_player_details(player.name)
|
110
|
+
elsif NbaDraft2017::Player.find_player_by_name(lookup)
|
111
|
+
list_player_details(lookup)
|
112
|
+
else
|
113
|
+
error
|
114
|
+
end
|
115
|
+
player
|
116
|
+
end
|
117
|
+
|
118
|
+
def list_player_details(player_name)
|
119
|
+
player = add_attributes_to_player(player_name)
|
120
|
+
|
121
|
+
puts "#{player.name.upcase.bold.underline}".colorize(:green).bold
|
122
|
+
puts " Round:".bold.colorize(:red) +" #{player.round}" + " Pick:".bold.colorize(:red) +" #{player.pick}"
|
123
|
+
puts " Drafted By:".bold.colorize(:red) +" #{player.nba_team}"
|
124
|
+
puts " From:".bold.colorize(:red) +" #{player.former_team}"
|
125
|
+
puts " Position:".bold.colorize(:red) +" #{player.position}"
|
126
|
+
puts " Drafted As:".bold.colorize(:red) +" #{player.former_status}"
|
127
|
+
puts " Age:".bold.colorize(:red) +" #{player.age}"
|
128
|
+
puts " Height:".bold.colorize(:red) +" #{player.height}"
|
129
|
+
puts " Weight:".bold.colorize(:red) +" #{player.weight}"
|
130
|
+
puts " STATS".colorize(:green).bold if player.key_stats
|
131
|
+
|
132
|
+
if player.key_stats
|
133
|
+
puts " PPG:".bold.colorize(:red) + " #{player.ppg}" if player.ppg
|
134
|
+
puts " RPG:".bold.colorize(:red) + " #{player.rpg}" if player.rpg
|
135
|
+
puts " APG:".bold.colorize(:red) + " #{player.apg}" if player.apg
|
136
|
+
puts " FG:".bold.colorize(:red) + " #{(player.fg * 100).round(2)}%" if player.fg
|
137
|
+
puts " 3PT:".bold.colorize(:red) + " #{(player.three * 100).round(2)}%" if player.three
|
138
|
+
puts " FT:".bold.colorize(:red) + " #{(player.ft * 100).round(2)}%" if player.ft
|
139
|
+
puts " TPG:".bold.colorize(:red) + " #{player.tpg}" if player.tpg
|
140
|
+
puts " SPG:".bold.colorize(:red) + " #{player.spg}" if player.spg
|
141
|
+
puts " BPG:".bold.colorize(:red) + " #{player.bpg}" if player.bpg
|
142
|
+
puts " MPG:".bold.colorize(:red) + " #{player.mpg}" if player.mpg
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def list_draft_picks_by_nba_team
|
147
|
+
puts NbaDraft2017::Player.nba_teams.sort
|
148
|
+
puts 'Enter an NBA team (name only) as in list above:'.colorize(:green)
|
149
|
+
|
150
|
+
nba_team = gets.strip.downcase
|
151
|
+
|
152
|
+
if NbaDraft2017::Player.nba_teams.include?(nba_team)
|
153
|
+
NbaDraft2017::Player.players_by_nba_team(nba_team)
|
154
|
+
more_info_on_player?(nba_team)
|
155
|
+
else
|
156
|
+
error
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def list_draft_picks_by_former_team
|
161
|
+
puts NbaDraft2017::Player.former_teams.sort
|
162
|
+
puts 'Enter a School or Country name exactly as shown in list above:'.colorize(:green)
|
163
|
+
|
164
|
+
former_team = gets.strip.downcase
|
165
|
+
|
166
|
+
if NbaDraft2017::Player.former_teams.include?(former_team)
|
167
|
+
NbaDraft2017::Player.players_by_former_team(former_team)
|
168
|
+
more_info_on_player?(former_team)
|
169
|
+
else
|
170
|
+
error
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def more_info_on_player?(team)
|
175
|
+
request = nil
|
176
|
+
|
177
|
+
while request != 'n' && request != 'exit'
|
178
|
+
puts "Would you like more info on any of the players? 'y' or 'n'?"
|
179
|
+
request = gets.downcase.strip
|
180
|
+
|
181
|
+
if request =='y'
|
182
|
+
player = find_and_list_player
|
183
|
+
|
184
|
+
if player.nba_team.downcase != team.downcase && player.former_team.downcase != team.downcase
|
185
|
+
dotted_line
|
186
|
+
puts "That player isn't on or from #{team} though!!!".upcase.bold.colorize(:red)
|
187
|
+
dotted_line
|
188
|
+
end
|
189
|
+
|
190
|
+
elsif request == 'n' || request == 'exit'
|
191
|
+
break
|
192
|
+
|
193
|
+
else
|
194
|
+
error
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def error
|
201
|
+
puts "I didn't understand that! Please try agian or type 'exit'.".colorize(:red).bold
|
202
|
+
puts "------------------------------------------------------------".colorize(:green).bold
|
203
|
+
end
|
204
|
+
|
205
|
+
def good_bye
|
206
|
+
puts "Thanks for checking out the 2017 NBA Draft! Good Luck!"
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class NbaDraft2017::Player
|
2
|
+
|
3
|
+
attr_accessor :name, :last_name, :first_name, :profile_url, :pick, :round, :nba_team, :position, :former_team, :height, :weight, :former_status, :age,
|
4
|
+
:key_stats, :ppg, :rpg, :apg, :tpg, :spg, :bpg, :mpg, :fg, :three, :ft
|
5
|
+
|
6
|
+
@@all = []
|
7
|
+
@@nba_teams = []
|
8
|
+
@@former_teams = []
|
9
|
+
|
10
|
+
def initialize(player_hash)
|
11
|
+
player_hash.each {|attribute, value| self.send("#{attribute}=", value) }
|
12
|
+
@@all << self
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create_from_collection(players_array)
|
16
|
+
players_array.each { |player| NbaDraft2017::Player.new(player) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_player_attributes(attributes_hash)
|
20
|
+
attributes_hash.each { |attribute, value| self.send("#{attribute}=", value) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find_player_by_name(player_name)
|
24
|
+
NbaDraft2017::Player.all.detect { |player| player.name.downcase == player_name.downcase }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_player_by_pick(pick)
|
28
|
+
NbaDraft2017::Player.all.detect { |player| player.pick == pick.to_s }
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.nba_teams
|
32
|
+
self.all.each do |player|
|
33
|
+
@@nba_teams << player.nba_team.downcase.strip
|
34
|
+
end
|
35
|
+
@@nba_teams.uniq
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.players_by_nba_team(nba_team)
|
39
|
+
puts nba_team.upcase.bold.colorize(:green)
|
40
|
+
|
41
|
+
self.all.each do |player|
|
42
|
+
if player.nba_team.downcase == nba_team.downcase
|
43
|
+
puts "Rd: ".colorize(:red) +"#{player.round}" + " Pick: ".colorize(:red) +"#{player.pick} #{player.name.upcase.bold.colorize(:blue)} from #{player.former_team.bold.colorize(:blue)}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.former_teams
|
49
|
+
self.all.each do |player|
|
50
|
+
@@former_teams << player.former_team.downcase.strip
|
51
|
+
end
|
52
|
+
|
53
|
+
@@former_teams.uniq
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.players_by_former_team(former_team)
|
57
|
+
puts former_team.upcase.bold.colorize(:green)
|
58
|
+
|
59
|
+
self.all.each do |player|
|
60
|
+
if player.former_team.downcase == former_team.downcase
|
61
|
+
puts "Rd: ".colorize(:red) +"#{player.round}" + " Pick: ".colorize(:red) +"#{player.pick} #{player.name.upcase.bold.colorize(:blue)} to #{player.nba_team.bold.colorize(:blue)}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.all
|
67
|
+
@@all
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
class NbaDraft2017::Scraper
|
2
|
+
|
3
|
+
def self.scrape_draft
|
4
|
+
doc = Nokogiri::HTML(open('http://www.cbssports.com/nba/news/2017-nba-draft-picks-complete-results-full-list-of-players-selected-highlights-grades/'))
|
5
|
+
draft = doc.xpath('//*[@id="article-main-body"]/div/ol')
|
6
|
+
players = []
|
7
|
+
pick = '1'
|
8
|
+
|
9
|
+
i = 0
|
10
|
+
while i < 60
|
11
|
+
player = {}
|
12
|
+
player_info = draft.css('li p')[i]
|
13
|
+
|
14
|
+
player[:pick] = pick.to_s
|
15
|
+
player[:nba_team] = player_info.css('strong').text.gsub("\u00A0", '').gsub(':', '').strip
|
16
|
+
player[:former_team] = player_info.text.split('-')[-1].gsub("\u00A0", '').gsub(':', '').strip
|
17
|
+
details = player_info.text.split(' ')
|
18
|
+
player[:position] = details. detect { |d| d.include?('(') }.strip
|
19
|
+
|
20
|
+
if i < 30
|
21
|
+
player[:round] = '1'
|
22
|
+
|
23
|
+
if details[0].include?(':')
|
24
|
+
player[:first_name] = details[0].split(':')[1].gsub(/\W/, "").strip
|
25
|
+
player[:last_name] = details[1].gsub(/\W/, "").strip
|
26
|
+
else
|
27
|
+
player[:first_name] = details[1].split(':')[1].gsub(/\W/, "").strip
|
28
|
+
player[:last_name] = details[2].gsub(/\W/, "").strip
|
29
|
+
end
|
30
|
+
|
31
|
+
elsif i >= 30
|
32
|
+
player[:round] = '2'
|
33
|
+
|
34
|
+
player[:first_name] = details[1].gsub(/\W/, "").strip
|
35
|
+
player[:last_name] = details[2].gsub(/\W/, "").strip
|
36
|
+
end
|
37
|
+
|
38
|
+
player[:name] = player[:first_name].strip + ' ' + player[:last_name].strip
|
39
|
+
if player[:first_name] == 'Andzejs'
|
40
|
+
player[:profile_url] = 'anzejs_pasecniks'
|
41
|
+
else
|
42
|
+
player[:profile_url] = player[:first_name].gsub(/\W/, '').downcase + '_' + player[:last_name].gsub(/\W/, '').downcase
|
43
|
+
end
|
44
|
+
|
45
|
+
players << player
|
46
|
+
pick = pick.to_i + 1
|
47
|
+
i += 1
|
48
|
+
end
|
49
|
+
players
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.scrape_player(profile_url)
|
53
|
+
player_page = Nokogiri::HTML(open(profile_url))
|
54
|
+
player = {}
|
55
|
+
ht_weight = player_page.css('.stats').text.split(':')[1]
|
56
|
+
|
57
|
+
player[:height] = ht_weight.split('/')[0].gsub("\"", "").strip if ht_weight
|
58
|
+
player[:weight] = ht_weight.split('/')[1].strip if ht_weight
|
59
|
+
player[:former_status] = player_page.css('.status').text.split(':')[1].strip
|
60
|
+
|
61
|
+
dob = player_page.css('.birthday').text.split(':')[1].strip
|
62
|
+
player[:age] = get_age(dob) if dob
|
63
|
+
|
64
|
+
stats = get_key_stats(player_page)
|
65
|
+
split_key_stats(stats, player) if stats
|
66
|
+
|
67
|
+
player
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_age(dob)
|
71
|
+
b_year= dob.split(' ')[2].strip.to_i
|
72
|
+
b_month = Date::MONTHNAMES.index(dob.split(' ')[0].strip)
|
73
|
+
b_day = dob.split(' ')[1].chop.strip.to_i
|
74
|
+
|
75
|
+
age = Date.today.year - b_year - ((Date.today.month > b_month || (Date.today.month == b_month && Date.today.day >= b_day)) ? 0 : 1)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.get_key_stats(player_page)
|
79
|
+
stats = nil
|
80
|
+
idx = 10
|
81
|
+
while idx <= 14 && stats == nil
|
82
|
+
if player_page.css(".field-items p[#{idx}] strong").text.downcase.strip == "key statistics:"
|
83
|
+
stats = player_page.css(".field-items p[#{idx}]").text.split(':')[1].strip
|
84
|
+
end
|
85
|
+
idx += 1
|
86
|
+
end
|
87
|
+
stats
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.split_key_stats(stats, player)
|
91
|
+
player[:key_stats] = stats.strip.split(',').collect do |stat|
|
92
|
+
|
93
|
+
if stat.downcase.include?('ppg')
|
94
|
+
player[:ppg] = stat.split(' ')[0].strip.to_f
|
95
|
+
player[:ppg].to_s + ' ' + stat.split(' ')[1].strip
|
96
|
+
elsif stat.downcase.include?('rpg')
|
97
|
+
player[:rpg] = stat.split(' ')[0].strip.to_f
|
98
|
+
player[:rpg].to_s + ' ' + stat.split(' ')[1].strip
|
99
|
+
elsif stat.downcase.include?('apg')
|
100
|
+
player[:apg] = stat.split(' ')[0].strip.to_f
|
101
|
+
player[:apg].to_s + ' ' + stat.split(' ')[1].strip
|
102
|
+
elsif stat.downcase.include?('tpg')
|
103
|
+
player[:tpg] = stat.split(' ')[0].strip.to_f
|
104
|
+
player[:tpg].to_s + ' ' + stat.split(' ')[1].strip
|
105
|
+
elsif stat.downcase.include?('spg')
|
106
|
+
player[:spg] = stat.split(' ')[0].strip.to_f
|
107
|
+
player[:spg].to_s + ' ' + stat.split(' ')[1].strip
|
108
|
+
elsif stat.downcase.include?('bpg')
|
109
|
+
player[:bpg] = stat.split(' ')[0].strip.to_f
|
110
|
+
player[:bpg].to_s + ' ' + stat.split(' ')[1].strip
|
111
|
+
elsif stat.downcase.include?('mpg')
|
112
|
+
player[:mpg] = stat.split(' ')[0].strip.to_f
|
113
|
+
player[:mpg].to_s + ' ' + stat.split(' ')[1].strip
|
114
|
+
elsif stat.downcase.include?('fg')
|
115
|
+
player[:fg] = stat.split(' ')[0].strip.to_f
|
116
|
+
player[:FG].to_s + ' ' + stat.split(' ')[1].strip
|
117
|
+
elsif stat.downcase.include?('3pt')
|
118
|
+
player[:three] = stat.split(' ')[0].strip.to_f
|
119
|
+
player[:_3PT].to_s + ' ' + stat.split(' ')[1].strip
|
120
|
+
elsif stat.downcase.include?('ft')
|
121
|
+
player[:ft] = stat.split(' ')[0].strip.to_f
|
122
|
+
player[:FT].to_s + ' ' + stat.split(' ')[1].strip
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nba_draft_2017/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nba-draft-2017"
|
8
|
+
spec.version = NbaDraft2017::VERSION
|
9
|
+
spec.authors = ["Paul Snider"]
|
10
|
+
spec.email = ["pbsnider@gmail.com"]
|
11
|
+
spec.summary = "Retrieve draft picks and corresponding details from the 2017 NBA draft"
|
12
|
+
spec.homepage = "https://github.com/psnider30/nba-draft-2017"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($\)
|
16
|
+
spec.executables = ["nba-draft-2017"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib", "lib/nba_draft_2017"]
|
19
|
+
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "nokogiri", "~>1.8.0"
|
27
|
+
spec.add_runtime_dependency "colorize"
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "nba_draft_2017"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nba-draft-2017
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Snider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- pbsnider@gmail.com
|
100
|
+
executables:
|
101
|
+
- nba-draft-2017
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- NOTES.md
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/nba-draft-2017
|
115
|
+
- bin/setup
|
116
|
+
- lib/nba_draft_2017.rb
|
117
|
+
- lib/nba_draft_2017/cli.rb
|
118
|
+
- lib/nba_draft_2017/player.rb
|
119
|
+
- lib/nba_draft_2017/scraper.rb
|
120
|
+
- lib/nba_draft_2017/version.rb
|
121
|
+
- nba_draft_2017.gemspec
|
122
|
+
- spec/nba_draft_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/psnider30/nba-draft-2017
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
- lib/nba_draft_2017
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.6.12
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Retrieve draft picks and corresponding details from the 2017 NBA draft
|
149
|
+
test_files:
|
150
|
+
- spec/nba_draft_spec.rb
|
151
|
+
- spec/spec_helper.rb
|