nfl_data 0.0.14 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.envrc +7 -0
- data/.gitignore +3 -3
- data/.rspec +1 -0
- data/.standard.yml +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +94 -22
- data/Rakefile +5 -6
- data/bin/console +1 -1
- data/bin/setup +8 -0
- data/lib/nfl_data.rb +10 -19
- data/lib/nfl_data/api/player.rb +8 -26
- data/lib/nfl_data/api/schedule.rb +19 -0
- data/lib/nfl_data/api/statline.rb +8 -22
- data/lib/nfl_data/models/game.rb +5 -0
- data/lib/nfl_data/models/player.rb +11 -18
- data/lib/nfl_data/models/schedule.rb +12 -0
- data/lib/nfl_data/models/statline.rb +18 -19
- data/lib/nfl_data/my_sports_feeds/client.rb +45 -0
- data/lib/nfl_data/my_sports_feeds/players_feed.rb +18 -0
- data/lib/nfl_data/my_sports_feeds/seasonal_games_feed.rb +22 -0
- data/lib/nfl_data/my_sports_feeds/weekly_player_gamelogs.rb +21 -0
- data/lib/nfl_data/parsers/player_parser.rb +20 -93
- data/lib/nfl_data/parsers/schedule_parser.rb +20 -0
- data/lib/nfl_data/parsers/statline_parser.rb +27 -71
- data/lib/nfl_data/version.rb +1 -1
- data/nfl_data.gemspec +23 -23
- data/spec/api/player_spec.rb +24 -0
- data/spec/api/schedule_spec.rb +20 -0
- data/spec/api/statline_spec.rb +31 -0
- data/spec/models/game_spec.rb +15 -0
- data/spec/models/player_spec.rb +42 -0
- data/spec/models/schedule_spec.rb +17 -0
- data/spec/models/statline_spec.rb +63 -0
- data/spec/my_sports_feeds/client_spec.rb +17 -0
- data/spec/my_sports_feeds/players_feed_spec.rb +49 -0
- data/spec/my_sports_feeds/seasonal_games_feed_spec.rb +41 -0
- data/spec/my_sports_feeds/weekly_player_gamelogs_spec.rb +144 -0
- data/spec/parsers/player_parser_spec.rb +63 -0
- data/spec/parsers/schedule_parser_spec.rb +41 -0
- data/spec/parsers/statline_parser_spec.rb +68 -0
- data/spec/spec_helper.rb +55 -0
- metadata +83 -52
- data/.codeclimate.yml +0 -5
- data/.rubocop.yml +0 -2
- data/lib/nfl_data/api/team.rb +0 -23
- data/lib/nfl_data/models/team.rb +0 -38
- data/lib/nfl_data/parsers/data/teams.rb +0 -36
- data/lib/nfl_data/parsers/parser_helper.rb +0 -6
- data/lib/nfl_data/parsers/team_parser.rb +0 -76
- data/test/nfl_data/api/player_test.rb +0 -25
- data/test/nfl_data/api/statline_test.rb +0 -21
- data/test/nfl_data/api/team_test.rb +0 -13
- data/test/nfl_data/models/player_test.rb +0 -81
- data/test/nfl_data/models/statline_test.rb +0 -121
- data/test/nfl_data/models/team_test.rb +0 -43
- data/test/nfl_data/parsers/player_parser_test.rb +0 -81
- data/test/nfl_data/parsers/statline_parser_test.rb +0 -34
- data/test/nfl_data/parsers/team_parser_test.rb +0 -37
- data/test/test_helper.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8aae3b48befa5e49a3400e2e4955cca323f7e3ed4aa7e4ecd17d888eea7029c
|
4
|
+
data.tar.gz: 9e03e003f759db815c8d8be2eca6592ce610fa1148b709f8156002ffe86a26a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10f022e51cec852029038277ffeaff0887946bb44129ee309e32329f427cea141980fbb5f98d34d5cd9feca1c7537c8f7367e7497546fa5a738b93e1ef618e47
|
7
|
+
data.tar.gz: 73788afad7732273a27f4daf8f66028b0baf7b96b0f66a15a6174a73c16778775647712ac3b1f69f67ddb57dd91d8c1ec0d2b27bae836fe89fec357dacd05a64
|
data/.envrc
ADDED
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.standard.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
## 0.1.0 / 2020-08-31
|
2
|
+
|
3
|
+
* No more NFL.com parsing, using MySportsFeeds API instead. This will require users to acquire their own MySportsFeeds accounts and API tokens. Please see the README or [the MySportsFeeds website](https://www.mysportsfeeds.com for more details.
|
4
|
+
|
5
|
+
## 0.0.14 and previous
|
6
|
+
|
7
|
+
* This version and previous used Nokogiri to parse NFL.com. NFL has since changed their website and broken all of the parsing code. Any version before here probably won't work and should be upgraded.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
# NflData
|
2
2
|
|
3
|
-
This gem is for parsing data from NFL.com and returning a JSON blob that can be used
|
3
|
+
This gem is for parsing data from NFL.com and returning a JSON blob that can be used
|
4
|
+
for any fantasy related activities you may wish to pursue.
|
4
5
|
|
5
|
-
|
6
|
+
**However** since NFL.com has updated their website to a much more difficult to parse version,
|
7
|
+
this gem is now going to be using [MySportsFeeds API](https://www.mysportsfeeds.com/data-feeds/) instead.
|
8
|
+
|
9
|
+
Thanks to the people at [MySportsFeeds](https://www.mysportsfeeds.com) for providing an affordable
|
10
|
+
service for this type of data. If you would like to use this gem I encourage you to head over to their
|
11
|
+
website and sign up for an account.
|
12
|
+
|
13
|
+
This gem was written by @mikesells and @thetizzo
|
6
14
|
|
7
15
|
[![Gem Version](https://badge.fury.io/rb/nfl_data.svg)](http://badge.fury.io/rb/nfl_data)
|
8
|
-
|
16
|
+
|
17
|
+
[![Build Status](https://travis-ci.com/thetizzo/nfl_data.svg?branch=master)](https://travis-ci.com/thetizzo/nfl_data)
|
9
18
|
|
10
19
|
## Installation
|
11
20
|
|
@@ -21,24 +30,56 @@ Or install it yourself as:
|
|
21
30
|
|
22
31
|
$ gem install nfl_data
|
23
32
|
|
24
|
-
##
|
33
|
+
## Configuration
|
25
34
|
|
26
|
-
|
35
|
+
Configuration for [MySportsFeeds API](https://www.mysportsfeeds.com/data-feeds/) credentials
|
36
|
+
can be set with the following Environment Variables:
|
27
37
|
|
28
|
-
|
38
|
+
```
|
39
|
+
MYSPORTSFEEDS_API_KEY
|
40
|
+
MYSPORTSFEEDS_API_HOST
|
41
|
+
MYSPORTSFEEDS_API_VERSION
|
42
|
+
```
|
29
43
|
|
30
|
-
|
44
|
+
### MySportsFeeds API Docs
|
31
45
|
|
32
|
-
|
33
|
-
NflData::API::Player.get_all
|
46
|
+
https://www.mysportsfeeds.com/data-feeds/api-docs/
|
34
47
|
|
35
|
-
|
48
|
+
I've written this to use >= v2.1 of the MSF API.
|
36
49
|
|
37
|
-
|
50
|
+
## Usage
|
38
51
|
|
39
|
-
|
52
|
+
To use this gem there are some simple calls that can be made. Everything will return JSON.
|
53
|
+
|
54
|
+
### Players
|
40
55
|
|
41
|
-
|
56
|
+
Pull players by position. Not passing a position param will pull all players.
|
57
|
+
|
58
|
+
Position param is passed through to MySportsFeeds and can be any value they accept. Please see
|
59
|
+
their docs above.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
NflData::API::Player.new.players(position: "qb")
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Example Response
|
66
|
+
|
67
|
+
```json
|
68
|
+
{
|
69
|
+
"players": [
|
70
|
+
{
|
71
|
+
"first_name": "John",
|
72
|
+
"last_name": "Elway",
|
73
|
+
"full_name": "John Elway",
|
74
|
+
"position": "QB",
|
75
|
+
"number": 7,
|
76
|
+
"team": "DEN",
|
77
|
+
"msf_player_id": 12345,
|
78
|
+
"image_source":""
|
79
|
+
},
|
80
|
+
...
|
81
|
+
]
|
82
|
+
}
|
42
83
|
```
|
43
84
|
|
44
85
|
### Statlines
|
@@ -46,21 +87,52 @@ Pull players by position:
|
|
46
87
|
Pull statlines by week and year:
|
47
88
|
|
48
89
|
```ruby
|
49
|
-
NflData::API::Statline.
|
50
|
-
|
51
|
-
NflData::API::Statline.get_rushing(1, 2014)
|
52
|
-
|
53
|
-
NflData::API::Statline.get_receiving(1, 2014)
|
90
|
+
NflData::API::Statline.new.statlines(year: 2020, week: 1)
|
54
91
|
```
|
55
92
|
|
56
|
-
|
93
|
+
#### Example Response
|
94
|
+
|
95
|
+
```json
|
96
|
+
{
|
97
|
+
"statlines": [
|
98
|
+
{
|
99
|
+
"rush_atts": 2,
|
100
|
+
"rush_yards": 11,
|
101
|
+
"rush_tds": 1,
|
102
|
+
"fumbles": 0,
|
103
|
+
"pass_comp": 11,
|
104
|
+
"pass_att": 23,
|
105
|
+
"pass_yards": 123,
|
106
|
+
"pass_tds": 2,
|
107
|
+
"ints": 1,
|
108
|
+
"qb_rating": 92.6,
|
109
|
+
"receptions": 3,
|
110
|
+
"rec_yards": 10,
|
111
|
+
"rec_tds": 0,
|
112
|
+
"msf_game_id": 51465,
|
113
|
+
"msf_player_id": 6826
|
114
|
+
}
|
115
|
+
...
|
116
|
+
]
|
117
|
+
}
|
118
|
+
```
|
57
119
|
|
58
|
-
|
120
|
+
### Schedule
|
59
121
|
|
122
|
+
Pull season schedule by year:
|
60
123
|
```ruby
|
61
|
-
NflData::
|
124
|
+
NflData::Api::Schedule.new.season(year: 2020)
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Example Response
|
62
128
|
|
63
|
-
|
129
|
+
```json
|
130
|
+
{
|
131
|
+
"games": [
|
132
|
+
{"week":1,"away_team":"HOU","home_team":"KC","start_time":"2020-09-10T04:25:00.000Z"}
|
133
|
+
...
|
134
|
+
]
|
135
|
+
}
|
64
136
|
```
|
65
137
|
|
66
138
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "standard/rake"
|
3
|
+
require "rspec/core/rake_task"
|
2
4
|
|
3
|
-
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
4
6
|
|
5
|
-
|
6
|
-
t.libs << 'test'
|
7
|
-
t.pattern = 'test/**/*_test.rb'
|
8
|
-
end
|
7
|
+
task default: [:spec, :standard]
|
data/bin/console
CHANGED
data/bin/setup
ADDED
data/lib/nfl_data.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require 'nfl_data/parsers/data/teams'
|
12
|
-
require 'nfl_data/parsers/parser_helper'
|
13
|
-
require 'nfl_data/parsers/player_parser'
|
14
|
-
require 'nfl_data/parsers/statline_parser'
|
15
|
-
require 'nfl_data/parsers/team_parser'
|
16
|
-
|
17
|
-
require 'nfl_data/api/player'
|
18
|
-
require 'nfl_data/api/statline'
|
19
|
-
require 'nfl_data/api/team'
|
1
|
+
require "nokogiri"
|
2
|
+
require "open-uri"
|
3
|
+
require "json"
|
4
|
+
require "typhoeus"
|
5
|
+
require "base64"
|
6
|
+
require "zeitwerk"
|
7
|
+
|
8
|
+
loader = Zeitwerk::Loader.for_gem
|
9
|
+
loader.collapse("lib/nfl_data/models")
|
10
|
+
loader.setup
|
20
11
|
|
21
12
|
module NflData
|
22
13
|
end
|
data/lib/nfl_data/api/player.rb
CHANGED
@@ -1,34 +1,16 @@
|
|
1
1
|
module NflData
|
2
|
-
module
|
2
|
+
module Api
|
3
3
|
class Player
|
4
|
-
|
5
|
-
@parser = PlayerParser.new
|
6
|
-
end
|
4
|
+
attr_reader :parser, :feed
|
7
5
|
|
8
|
-
def
|
9
|
-
@parser
|
6
|
+
def initialize(parser: Parsers::PlayerParser.new, feed: MySportsFeeds::PlayersFeed.new)
|
7
|
+
@parser = parser
|
8
|
+
@feed = feed
|
10
9
|
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_quarterbacks
|
18
|
-
new.get(:quarterbacks)
|
19
|
-
end
|
20
|
-
|
21
|
-
def get_runningbacks
|
22
|
-
new.get(:runningbacks)
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_wide_receivers
|
26
|
-
new.get(:wide_receivers)
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_tight_ends
|
30
|
-
new.get(:tight_ends)
|
31
|
-
end
|
11
|
+
def players(position: nil)
|
12
|
+
player_data = feed.feed(position: position)
|
13
|
+
{players: parser.parse(player_data: player_data).map(&:to_h)}.to_json
|
32
14
|
end
|
33
15
|
end
|
34
16
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NflData
|
4
|
+
module Api
|
5
|
+
class Schedule
|
6
|
+
attr_reader :parser, :feed
|
7
|
+
|
8
|
+
def initialize(parser: Parsers::ScheduleParser.new, feed: MySportsFeeds::SeasonalGamesFeed.new)
|
9
|
+
@parser = parser
|
10
|
+
@feed = feed
|
11
|
+
end
|
12
|
+
|
13
|
+
def season(year:)
|
14
|
+
schedule_data = feed.feed(season_start_year: year)
|
15
|
+
parser.parse(schedule_data: schedule_data).to_h.to_json
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,30 +1,16 @@
|
|
1
1
|
module NflData
|
2
|
-
module
|
2
|
+
module Api
|
3
3
|
class Statline
|
4
|
-
|
5
|
-
@parser = StatlineParser.new
|
6
|
-
end
|
4
|
+
attr_reader :parser, :feed
|
7
5
|
|
8
|
-
def
|
9
|
-
@parser
|
6
|
+
def initialize(parser: Parsers::StatlineParser.new, feed: MySportsFeeds::WeeklyPlayerGamelogs.new)
|
7
|
+
@parser = parser
|
8
|
+
@feed = feed
|
10
9
|
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_passing(week, year)
|
18
|
-
new.get(week, year, :passing)
|
19
|
-
end
|
20
|
-
|
21
|
-
def get_rushing(week, year)
|
22
|
-
new.get(week, year, :rushing)
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_receiving(week, year)
|
26
|
-
new.get(week, year, :receiving)
|
27
|
-
end
|
11
|
+
def statlines(year:, week:)
|
12
|
+
statline_data = feed.feed(season_start_year: year, week: week)
|
13
|
+
{statlines: parser.parse(statline_data: statline_data).map(&:to_h)}.to_json
|
28
14
|
end
|
29
15
|
end
|
30
16
|
end
|
@@ -1,20 +1,13 @@
|
|
1
1
|
module NflData
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def to_hash
|
15
|
-
attributes_hash = {}
|
16
|
-
ATTRIBUTES.each { |attr| attributes_hash.merge!(attr => send(attr)) }
|
17
|
-
attributes_hash
|
18
|
-
end
|
19
|
-
end
|
2
|
+
Player = Struct.new(
|
3
|
+
:first_name,
|
4
|
+
:last_name,
|
5
|
+
:full_name,
|
6
|
+
:position,
|
7
|
+
:number,
|
8
|
+
:team,
|
9
|
+
:msf_player_id,
|
10
|
+
:image_source,
|
11
|
+
keyword_init: true
|
12
|
+
)
|
20
13
|
end
|
@@ -1,21 +1,20 @@
|
|
1
1
|
module NflData
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
2
|
+
Statline = Struct.new(
|
3
|
+
:rush_atts,
|
4
|
+
:rush_yards,
|
5
|
+
:rush_tds,
|
6
|
+
:fumbles,
|
7
|
+
:pass_comp,
|
8
|
+
:pass_att,
|
9
|
+
:pass_yards,
|
10
|
+
:pass_tds,
|
11
|
+
:ints,
|
12
|
+
:qb_rating,
|
13
|
+
:receptions,
|
14
|
+
:rec_yards,
|
15
|
+
:rec_tds,
|
16
|
+
:msf_game_id,
|
17
|
+
:msf_player_id,
|
18
|
+
keyword_init: true
|
19
|
+
)
|
21
20
|
end
|