espn_nba_fantasy 0.0.2.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5314f60e93b62ccdf2e1e3cf6049bff50dce041dea90267e6a55e9cf135bcb99
4
- data.tar.gz: dc2a8da15cadf81be9a528aac61389387da200e1aa32c6418c291f67e259029f
3
+ metadata.gz: 4306b1e3c1b828575b2baf7c5b237c54bfc3916463f84170a054c13dcd3d1dba
4
+ data.tar.gz: 833f12b70aabf99b9365ac334924b612dd9b0e71603f69d7305091d68fedb140
5
5
  SHA512:
6
- metadata.gz: 30d6f7e686ba062fc860ebe1a385d7d08161de1c36cf1400cfd59c037828b375bc04779f557636d1cf7af1e8e4dff0da1abcc63904dfb6a2b80541a57d8daf51
7
- data.tar.gz: 0b3d61a04c9515d96e580cee05a7208891b4a89a9b4aab116d468fd1fca9e6979e6b7ca7e7e2c5dd07ce7d14480b5822d173c71237bf9111a63a13d43582c680
6
+ metadata.gz: 88b1dcadb34024a8bf8d42c572fcea180fe3167370bda2dcb2a76a538c1014a1502e03feece0c95b504e04c054b9b3c91e26a2c19ffca9dfc80e9f838f1cdfd6
7
+ data.tar.gz: feab0635a4fae468d362e316ac791d0410066c0889170babccf94632210e021527ef25130bb40bb073c1698135b4a4ca83741f86333af31bb31771d2c9220be7
@@ -0,0 +1,94 @@
1
+ #these are some of the constants necessary to map ids from the ESPN Fantasy Library to,
2
+ #so that things like position, stat name, etc are readable!
3
+
4
+ POSITION_MAP = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'SG/SF', 'G/F', 'PF/C', 'F/C', 'UT', 'BE', 'IR', '', 'Rookie']
5
+
6
+ PRO_TEAM_MAP = ['FA', 'ATL','BOS','NOP','CHI','CLE','DAL','DEN','DET','GSW','HOU','IND',
7
+ 'LAC','LAL','MIA','MIL','MIN','BKN','NYK','ORL','PHL','PHO','POR','SAC','SAS','OKC',
8
+ 'UTA','WAS','TOR','MEM','CHA']
9
+
10
+ STATS_MAP = {
11
+ '0' => 'PTS',
12
+ '1' => 'BLK',
13
+ '2' => 'STL',
14
+ '3' => 'AST',
15
+ '4' => 'OREB',
16
+ '5' => 'DREB',
17
+ '6' => 'REB',
18
+ '7'=> '7',
19
+ '8'=> '8',
20
+ '9'=> 'PF',
21
+ '10'=> '10',
22
+ '11'=> 'TO',
23
+ '12'=> '12',
24
+ '13'=> 'FGM',
25
+ '14'=> 'FGA',
26
+ '15'=> 'FTM',
27
+ '16'=> 'FTA',
28
+ '17'=> '3PTM',
29
+ '18'=> '3PTA',
30
+ '19'=> 'FG%',
31
+ '20'=> 'FT%',
32
+ '21'=> '3PT%',
33
+ '22'=> '22',
34
+ '23'=> '23',
35
+ '24'=> '24',
36
+ '25'=> '25',
37
+ '26'=> '26',
38
+ '27'=> '27',
39
+ '28'=> 'MPG',
40
+ '29'=> '29',
41
+ '30'=> '30',
42
+ '31'=> '31',
43
+ '32'=> '32',
44
+ '33'=> '33',
45
+ '34'=> '34',
46
+ '35'=> '35',
47
+ '36'=> '36',
48
+ '37'=> '37',
49
+ '38'=> '38',
50
+ '39'=> '39',
51
+ '40'=> 'MIN',
52
+ '41'=> 'GS',
53
+ '42'=> 'GP',
54
+ '43'=> '43',
55
+ '44'=> '44',
56
+ '45'=> '45',
57
+ }
58
+
59
+ STAT_ID_MAP = {
60
+ '00': 'total',
61
+ '10': 'projected',
62
+ '01': 'last_7',
63
+ '02': 'last_15',
64
+ '03': 'last_30'
65
+ }
66
+
67
+ ACTIVITY_MAP = {
68
+ 178 => 'FA ADDED',
69
+ 180 => 'WAIVER ADDED',
70
+ 179 => 'DROPPED',
71
+ 181 => 'DROPPED',
72
+ 239 => 'DROPPED',
73
+ 244 => 'TRADED',
74
+ 'FA': 178,
75
+ 'WAIVER': 180,
76
+ 'TRADED': 244
77
+ }
78
+
79
+ NINE_CAT_STATS = [
80
+ '3PTM',
81
+ 'AST',
82
+ 'BLK',
83
+ 'FG%',
84
+ 'FT%',
85
+ 'PTS',
86
+ 'REB',
87
+ 'STL',
88
+ 'TO'
89
+ ]
90
+
91
+ STATS = ['PTS','BLK','STL','AST','OREB','DREB','TO','FGM','FTM','3PTM', 'FGA', '3PTA', 'FTA']
92
+
93
+ EMPTY_STATS = {'PTS'=>0,'BLK'=>0,'STL'=>0,'AST'=>0,'OREB'=>0,'DREB'=>0,'TO'=>0,'FGM'=>0,'FTM'=>0,'3PTM'=>0, 'FGA'=>0, '3PTA'=>0, 'FTA'=>0}
94
+
@@ -13,13 +13,19 @@ class League
13
13
  #initializes the league
14
14
 
15
15
  def initialize(league_id, year, s2, sw)
16
- @uri = "https://fantasy.espn.com/apis/v3/games/fba/seasons/#{year}/segments/0/leagues/#{league_id}?view=mTeam&view=mRoster&view=mMatchup&view=mSettings&view=mStandings"
16
+ @league_id = league_id
17
+
18
+ @uri = "https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/#{year}/segments/0/leagues/#{league_id}?view=mRoster&view=mSettings&view=mTeam&view=modular&view=mNav"
17
19
  @cookies = {'espn_s2': "#{s2}", 'SWID': "#{sw}"}
18
20
  @data = JSON.parse(RestClient.get(@uri, {cookies: @cookies}))
19
21
  @teams = make_team_objects
20
22
  @stat_data = make_stat_data
21
23
  end
22
24
 
25
+ def to_s
26
+ "League #{@league_id}"
27
+ end
28
+
23
29
  #gives you an array of each team's name and id in the league
24
30
 
25
31
  def team_list
@@ -17,12 +17,12 @@ class Player
17
17
  @team = team
18
18
  end
19
19
 
20
- private
21
-
22
20
  def to_s
23
21
  "Player: #{name} | Position: #{position} | Stats: #{stats}"
24
22
  end
25
23
 
24
+ private
25
+
26
26
  def stat_card_maker(player)
27
27
  avgstats = player['stats'].first['averageStats']
28
28
  statcard = avgstats ? avgstats.transform_keys!{ |k| STATS_MAP[k] }.slice(*STATS) : EMPTY_STATS
@@ -27,6 +27,10 @@ class Team
27
27
  #returns data including the players trading away and receiving, your stats before and after the trade, and your
28
28
  #change in stats for each category
29
29
 
30
+ def to_s
31
+ "Team Name: #{name} | Roster: #{roster_names}"
32
+ end
33
+
30
34
  def trade_players(to_trade = [], to_receive = [], other_team_name)
31
35
  other_team = league.teams.select{|team| team.name == other_team_name}.first
32
36
  return "No team named #{other_team_name}" unless other_team
@@ -40,10 +44,6 @@ class Team
40
44
 
41
45
  private
42
46
 
43
- def to_s
44
- "Team Name: #{name} | Roster: #{roster_names}"
45
- end
46
-
47
47
  def roster_names
48
48
  players.map(&:name)
49
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espn_nba_fantasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Usborn Ocampo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-22 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - lib/espn_nba_fantasy.rb
91
91
  - lib/espn_nba_fantasy/calculate_stats.rb
92
+ - lib/espn_nba_fantasy/constants.rb
92
93
  - lib/espn_nba_fantasy/league.rb
93
94
  - lib/espn_nba_fantasy/player.rb
94
95
  - lib/espn_nba_fantasy/player_finder.rb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  - !ruby/object:Gem::Version
113
114
  version: '0'
114
115
  requirements: []
115
- rubygems_version: 3.4.14
116
+ rubygems_version: 3.5.13
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: Get info from your ESPN NBA Fantasy League as JSON data