nfl_data 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +8 -0
- data/lib/nfl_data/api/player.rb +32 -0
- data/lib/nfl_data/parsers/player_parser.rb +68 -0
- data/lib/nfl_data/player.rb +22 -0
- data/lib/nfl_data/version.rb +3 -0
- data/lib/nfl_data.rb +8 -0
- data/nfl_data.gemspec +27 -0
- data/test/nfl_data/player_test.rb +74 -0
- data/test/test_helper.rb +4 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjNhOTYxZmI2MDJmNjQ1MzhlOWZkZTY2OGQ1NGZhZTk4MWVjNTRhYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWJjMzA4YTJiZTcyYWNlZmFlZjQ1YmVlOTJlYmZlM2VhNTM0NWQ5Yg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWQ2OWIzNTdjMTEzOWEwNGIxY2RhY2Q1Yjg0YjdmYzNkNjk1YTgwNWQ4M2U0
|
10
|
+
MmQwMTZjNTkwOGYzMWZkNzBjYjk1YzE4MTM2MDUxYTRlOWQ0NDcyODE5ZDMy
|
11
|
+
YTBiMDA1YWY0YWY2YmIzZTE5MDNhYjI0NTNjYjVlMDg4NTkwN2U=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTA3ZjhlNDkwNTdlMGJiMDljY2YwMTUwNTQyZTdmNWFhOGI5ZjhlZjZmMzg5
|
14
|
+
ODJkZGVhNjQ4NmE1NjQ0MThkZTg5MjE5NWJjNTUzNTQ2Y2Q0Y2M4NDdiZDY2
|
15
|
+
MWE3ODE4ODNhYjRmOTcyM2MzZmNlOGY3NjEzN2Q5ODExMDZhMjc=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
nfl_data
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p547
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 thetizzo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# NflData
|
2
|
+
|
3
|
+
This gem is for parsing data from NFL.com and returning a JSON blob that can be used for any fantasy related activities you may wish to pursue.
|
4
|
+
|
5
|
+
This was written by @mikesells and @thetizzo
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'nfl_data'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nfl_data
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Players
|
24
|
+
|
25
|
+
To pull players you can do so by position as follows:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
NflData::API::Player.get_quarterbacks
|
29
|
+
|
30
|
+
NflData::API::Player.get_runningbacks
|
31
|
+
|
32
|
+
NflData::API::Player.get_wide_receivers
|
33
|
+
|
34
|
+
NflData::API::Player.get_tight_ends
|
35
|
+
```
|
36
|
+
|
37
|
+
These will return JSON blobs of available players at each position
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/nfl_data/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module NflData
|
2
|
+
module API
|
3
|
+
class Player
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def positions
|
7
|
+
['quarterback', 'runningback', 'widereceiver', 'tightend']
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_quarterbacks
|
11
|
+
players = PlayerParser.new.get_by_position('quarterback').map { |player| player.to_json }
|
12
|
+
JSON.generate({quarterbacks: players})
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_runningbacks
|
16
|
+
players = PlayerParser.new.get_by_position('runningback').map { |player| player.to_json }
|
17
|
+
JSON.generate({runningbacks: players})
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_wide_receivers
|
21
|
+
players = PlayerParser.new.get_by_position('widereceiver').map { |player| player.to_json }
|
22
|
+
JSON.generate({wide_receivers: players})
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_tight_ends
|
26
|
+
players = PlayerParser.new.get_by_position('tightend').map { |player| player.to_json }
|
27
|
+
JSON.generate({tight_ends: players})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module NflData
|
4
|
+
class PlayerParser
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@url = "http://www.nfl.com/players/search?category=position&conferenceAbbr=null&playerType=current&conference=ALL&filter="
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_by_position(position)
|
11
|
+
baseurl = @url + position
|
12
|
+
url = baseurl
|
13
|
+
returnVal = []
|
14
|
+
page_num = 1
|
15
|
+
|
16
|
+
count = 100
|
17
|
+
|
18
|
+
loop do
|
19
|
+
page_num += 1
|
20
|
+
players_found = update_or_create_players(url)
|
21
|
+
returnVal.push(players_found[1])
|
22
|
+
break if players_found[0] == 0
|
23
|
+
url = baseurl + '&d-447263-p='
|
24
|
+
url += page_num.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
returnVal.flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_or_create_players(url)
|
31
|
+
# puts "Pulling from url = #{url}"
|
32
|
+
doc = open(url) { |f| Nokogiri(f) }
|
33
|
+
if doc.nil?
|
34
|
+
return 0
|
35
|
+
end
|
36
|
+
|
37
|
+
#NFL.com stores players in 2 types of rows. Class = Odd or Even. This pulls them all.
|
38
|
+
odds = doc.search("tr.odd")
|
39
|
+
evens = doc.search("tr.even")
|
40
|
+
|
41
|
+
all = odds + evens
|
42
|
+
|
43
|
+
players = all.map do |p|
|
44
|
+
player = Player.new
|
45
|
+
elements = p.search("td")
|
46
|
+
player.position = elements[0].inner_text.strip
|
47
|
+
player.number = elements[1].inner_text.strip
|
48
|
+
player.name = elements[2].inner_text.strip
|
49
|
+
player.status = elements[3].inner_text.strip
|
50
|
+
player.team = elements[12].inner_text.strip
|
51
|
+
|
52
|
+
#Get NFL.com Unique player id
|
53
|
+
player.nfl_player_id = elements[2].to_s.split('/')[3]
|
54
|
+
|
55
|
+
names = player.name.split(',')
|
56
|
+
|
57
|
+
player.first_name = names[1].strip
|
58
|
+
player.last_name = names[0].strip
|
59
|
+
|
60
|
+
player.full_name = [player.first_name, player.last_name].join(' ')
|
61
|
+
player
|
62
|
+
end
|
63
|
+
|
64
|
+
[players.count, players]
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module NflData
|
4
|
+
|
5
|
+
class Player
|
6
|
+
attr_accessor :first_name, :last_name, :full_name, :position, :number, :status, :team, :nfl_player_id
|
7
|
+
|
8
|
+
def to_json
|
9
|
+
JSON.generate({
|
10
|
+
first_name: first_name,
|
11
|
+
last_name: last_name,
|
12
|
+
full_name: full_name,
|
13
|
+
position: position,
|
14
|
+
number: number,
|
15
|
+
status: status,
|
16
|
+
team: team,
|
17
|
+
nfl_player_id: nfl_player_id
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/nfl_data.rb
ADDED
data/nfl_data.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'nfl_data/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "nfl_data"
|
9
|
+
spec.version = NflData::VERSION
|
10
|
+
spec.authors = ["thetizzo"]
|
11
|
+
spec.email = ["j.m.taylor1@gmail.com"]
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.summary = %q{Grabber for NFL data that is useful for fantasy purposes from NFL.com}
|
15
|
+
spec.description = %q{This gem is a way to get NFL data for fantasy purposes.}
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.4.1"
|
25
|
+
|
26
|
+
spec.add_dependency "nokogiri", "~> 1.6.3.1"
|
27
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe NflData::Player do
|
4
|
+
before do
|
5
|
+
@player = NflData::Player.new
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@player = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has a first name' do
|
13
|
+
@player.must_respond_to :first_name
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has a last name' do
|
17
|
+
@player.must_respond_to :last_name
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has a full name' do
|
21
|
+
@player.must_respond_to :full_name
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has a position' do
|
25
|
+
@player.must_respond_to :position
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has a number' do
|
29
|
+
@player.must_respond_to :number
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has a status' do
|
33
|
+
@player.must_respond_to :status
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'has a team' do
|
37
|
+
@player.must_respond_to :team
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has an NFL player ID' do
|
41
|
+
@player.must_respond_to :nfl_player_id
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'to_json' do
|
45
|
+
before do
|
46
|
+
@player.first_name = 'John'
|
47
|
+
@player.last_name = 'Elway'
|
48
|
+
@player.position = 'QB'
|
49
|
+
@player.full_name = 'John Elway'
|
50
|
+
@player.number = 7
|
51
|
+
@player.status = 'Retired'
|
52
|
+
@player.team = 'Broncos'
|
53
|
+
@player.nfl_player_id = '123'
|
54
|
+
end
|
55
|
+
|
56
|
+
def valid_player_json
|
57
|
+
JSON.generate({
|
58
|
+
first_name: 'John',
|
59
|
+
last_name: 'Elway',
|
60
|
+
full_name: 'John Elway',
|
61
|
+
position: 'QB',
|
62
|
+
number: 7,
|
63
|
+
status: 'Retired',
|
64
|
+
team: 'Broncos',
|
65
|
+
nfl_player_id: '123'
|
66
|
+
})
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'can return itself as JSON' do
|
70
|
+
@player.to_json.must_equal valid_player_json
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nfl_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- thetizzo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.4.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.4.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.3.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.3.1
|
69
|
+
description: This gem is a way to get NFL data for fantasy purposes.
|
70
|
+
email:
|
71
|
+
- j.m.taylor1@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .ruby-gemset
|
78
|
+
- .ruby-version
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/nfl_data.rb
|
84
|
+
- lib/nfl_data/api/player.rb
|
85
|
+
- lib/nfl_data/parsers/player_parser.rb
|
86
|
+
- lib/nfl_data/player.rb
|
87
|
+
- lib/nfl_data/version.rb
|
88
|
+
- nfl_data.gemspec
|
89
|
+
- test/nfl_data/player_test.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
homepage: ''
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Grabber for NFL data that is useful for fantasy purposes from NFL.com
|
115
|
+
test_files:
|
116
|
+
- test/nfl_data/player_test.rb
|
117
|
+
- test/test_helper.rb
|