Skip to content

Commit 83a3f5f

Browse files
committed
update queries and custom classes to return flattened objects without unnecessary single-key dict access, fix type hints to support flattened return values, and update docs, tests, and quickstart
1 parent fda0b16 commit 83a3f5f

File tree

6 files changed

+923
-906
lines changed

6 files changed

+923
-906
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ In order to use YFPY with private fantasy leagues, you must set up an app on you
109109

110110
* See the documentation on the [`yfpy.query.YahooFantasySportsQuery`](https://yfpy.uberfastman.com/_autosummary/yfpy.query.YahooFantasySportsQuery.html#yfpy.query.YahooFantasySportsQuery) class for example usage of all available queries.
111111
* See [`quickstart/quickstart.py`](https://github.com/uberfastman/yfpy/blob/main/quickstart/quickstart.py) for example usage output.
112-
* Uncomment/comment out whichever configuration values with which you wish to experiment.
112+
* Uncomment/comment out whichever configuration values in their respective functions with which you wish to experiment.
113113
* Uncomment/comment out whichever query lines in the `RUN QUERIES` section you wish to run.
114114
* Uncomment/comment out whichever query lines in the `CHECK FOR MISSING DATA FIELDS` section you wish to check for any new/missing data fields returned by the Yahoo Sports Fantasy Football API.
115115

@@ -130,6 +130,7 @@ YFPY has a collection of fully functional code snippets that can be run using [p
130130
* Before running any integration tests, make a copy of [`auth/EXAMPLE.env`](https://github.com/uberfastman/yfpy/blob/main/auth/EXAMPLE.env) in the [`auth/`](https://github.com/uberfastman/yfpy/blob/main/auth/) directory and rename it to `.env`.
131131
* Copy your Yahoo `Client ID` and `Client Secret` into the environment variables in `.env` so that pytest can use them when hitting the Yahoo Fantasy Sports API.
132132
* If this is the first time running pytest with your Yahoo API credentials, you ***MUST*** allow interactive prompts within pytest by using the `-s` flag.
133+
* The fixture values in [`test/integration/conftest.py`](https://github.com/uberfastman/yfpy/blob/main/test/integration/conftest.py) are defined in [`quickstart/quickstart.py`](https://github.com/uberfastman/yfpy/blob/main/quickstart/quickstart.py), and can be changed for testing by uncommenting/commenting out the values inside each respective function.
133134

134135
#### Running
135136

quickstart/quickstart.py

Lines changed: 176 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,74 +41,203 @@
4141
# VARIABLE SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4242
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
4343

44+
4445
# set desired season year
45-
season = 2021
46-
# season = 2012
46+
def get_season():
47+
# season = 2012
48+
# season = 2013
49+
# season = 2014
50+
# season = 2015
51+
# season = 2016
52+
# season = 2017
53+
# season = 2018
54+
# season = 2019
55+
# season = 2020
56+
# season = 2021
57+
# season = 2022
58+
season = 2023
59+
return season
60+
61+
62+
season = get_season()
63+
4764

4865
# set desired week
49-
chosen_week = 1
66+
def get_chosen_week():
67+
chosen_week = 1
68+
return chosen_week
69+
70+
71+
chosen_week = get_chosen_week()
72+
5073

5174
# set desired date
52-
chosen_date = "2013-04-15" # NHL - 2013 (for 2012)
53-
# chosen_date = "2013-04-16" # NHL - 2013
54-
# chosen_date = "2021-10-25" # NHL - 2021
55-
# chosen_date = "2021-04-01" # MLB - 2021
56-
# chosen_date = "2022-04-10" # MLB - 2022
75+
def get_chosen_date():
76+
# HOCKEY
77+
# chosen_date = "2013-04-15" # NHL - 2013 (for 2012 season)
78+
chosen_date = "2021-10-25" # NHL - 2021
79+
80+
# BASEBALL
81+
# chosen_date = "2021-04-01" # MLB - 2021
82+
# chosen_date = "2022-04-10" # MLB - 2022
83+
84+
return chosen_date
85+
86+
87+
chosen_date = get_chosen_date()
88+
5789

5890
# set desired Yahoo Fantasy Sports game code
59-
game_code = "nfl" # NFL
60-
# game_code = "nhl" # NHL
61-
# game_code = "mlb" # MLB
91+
def get_game_code():
92+
# FOOTBALL
93+
game_code = "nfl" # NFL
94+
95+
# HOCKEY
96+
# game_code = "nhl" # NHL
97+
98+
# BASEBALL
99+
# game_code = "mlb" # MLB
100+
101+
return game_code
102+
103+
104+
game_code = get_game_code()
105+
62106

63107
# set desired Yahoo Fantasy Sports game ID (see the get_all_yahoo_fantasy_game_keys query to retrieve values)
64-
# game_id = 331 # NFL - 2014
65-
# game_id = 348 # NFL - 2015 (testing for league with divisions)
66-
# game_id = 390 # NFL - 2019
67-
# game_id = 399 # NFL - 2020
68-
game_id = 406 # NFL - 2021
69-
# game_id = 303 # NHL - 2012
70-
# game_id = 411 # NHL - 2021
71-
# game_id = 404 # MLB - 2021
72-
# game_id = 412 # MLB - 2022
108+
def get_game_id():
109+
# FOOTBALL
110+
# game_id = 331 # NFL - 2014
111+
# game_id = 348 # NFL - 2015 (divisions)
112+
# game_id = 359 # NFL - 2016
113+
# game_id = 371 # NFL - 2017
114+
# game_id = 380 # NFL - 2018
115+
# game_id = 390 # NFL - 2019
116+
# game_id = 399 # NFL - 2020
117+
# game_id = 406 # NFL - 2021
118+
# game_id = 414 # NFL - 2022 (divisions)
119+
game_id = 423 # NFL - 2023
120+
121+
# HOCKEY
122+
# game_id = 303 # NHL - 2012
123+
# game_id = 411 # NHL - 2021
124+
125+
# BASEBALL
126+
# game_id = 404 # MLB - 2021
127+
# game_id = 412 # MLB - 2022
128+
129+
return game_id
130+
131+
132+
game_id = get_game_id()
133+
73134

74135
# set desired Yahoo Fantasy Sports game key (see the get_all_yahoo_fantasy_game_keys query to retrieve values)
75-
# game_key = "331" # NFL - 2014
76-
# game_key = "348" # NFL - 2015 (testing for league with divisions)
77-
# game_key = "390" # NFL - 2019
78-
# game_key = "399" # NFL - 2020
79-
game_key = "406" # NFL - 2021
80-
# game_key = "303" # NHL - 2012
81-
# game_key = "411" # NHL - 2021
82-
# game_key = "404" # MLB - 2021
83-
# game_key = "412" # MLB - 2022
136+
def get_game_key():
137+
# FOOTBALL
138+
# game_key = "331" # NFL - 2014
139+
# game_key = "348" # NFL - 2015 (divisions)
140+
# game_key = "359" # NFL - 2016
141+
# game_key = "371" # NFL - 2017
142+
# game_key = "380" # NFL - 2018
143+
# game_key = "390" # NFL - 2019
144+
# game_key = "399" # NFL - 2020
145+
# game_key = "406" # NFL - 2021
146+
# game_key = "414" # NFL - 2022 (divisions)
147+
game_key = "423" # NFL - 2023
148+
149+
# HOCKEY
150+
# game_key = "303" # NHL - 2012
151+
# game_key = "411" # NHL - 2021
152+
153+
# BASEBALL
154+
# game_key = "404" # MLB - 2021
155+
# game_key = "412" # MLB - 2022
156+
157+
return game_key
158+
159+
160+
game_key = get_game_key()
161+
84162

85163
# set desired league ID (see README.md for finding value)
86-
# league_id = "907359" # NFL - 2015 (testing for league with divisions)
87-
# league_id = "79230" # NFL - 2019
88-
# league_id = "655434" # NFL - 2020
89-
league_id = "413954" # NFL - 2021
90-
# league_id = "69624" # NHL - 2012
91-
# league_id = "101592" # NHL - 2021
92-
# league_id = "40134" # MLB - 2021
164+
def get_league_id():
165+
# FOOTBALL
166+
# league_id = "907359" # NFL - 2015 (divisions)
167+
# league_id = "79230" # NFL - 2019
168+
# league_id = "655434" # NFL - 2020
169+
# league_id = "413954" # NFL - 2021
170+
# league_id = "791337" # NFL - 2022 (divisions)
171+
league_id = "321958" # NFL - 2023
172+
173+
# HOCKEY
174+
# league_id = "69624" # NHL - 2012
175+
# league_id = "101592" # NHL - 2021
176+
177+
# BASEBALL
178+
# league_id = "40134" # MLB - 2021
179+
180+
return league_id
181+
182+
183+
league_id = get_league_id()
184+
93185

94186
# set desired team ID within desired league
95-
team_id = 1 # NFL
96-
# team_id = 2 # NHL (2012)
187+
def get_team_id():
188+
# FOOTBALL
189+
team_id = 1 # NFL
190+
191+
# HOCKEY
192+
# team_id = 2 # NHL (2012)
193+
194+
return team_id
195+
196+
197+
team_id = get_team_id()
198+
97199

98200
# set desired team name within desired league
99-
team_name = "Legion" # NFL
100-
# team_name = "The Bateleurs" # NHL (2012)
201+
def get_team_name():
202+
# FOOTBALL
203+
team_name = "Legion" # NFL
204+
205+
# HOCKEY
206+
# team_name = "The Bateleurs" # NHL (2012)
207+
208+
return team_name
209+
210+
211+
team_name = get_team_name()
212+
101213

102214
# set desired team ID within desired league
103-
player_id = 7200 # NFL: Aaron Rodgers - 2020/2021
104-
# player_id = 4588 # NHL: Braden Holtby - 2012
105-
# player_id = 8205 # NHL: Jeffrey Viel - 2021
106-
# player_id = 3637 # NHL: Alex Ovechkin - 2021
107-
# player_id = 9897 # MLB: Tim Anderson - 2021/2022
215+
def get_player_id():
216+
# FOOTBALL
217+
player_id = 30123 # NFL: Patrick Mahomes - 2020/2021/2023
218+
219+
# HOCKEY
220+
# player_id = 4588 # NHL: Braden Holtby - 2012
221+
# player_id = 8205 # NHL: Jeffrey Viel - 2021
222+
# player_id = 3637 # NHL: Alex Ovechkin - 2021
223+
224+
# BASEBALL
225+
# player_id = 9897 # MLB: Tim Anderson - 2021/2022
226+
227+
return player_id
228+
229+
230+
player_id = get_player_id()
231+
108232

109233
# set the maximum number players you wish the get_league_players query to retrieve
110-
league_player_limit = 101
111-
# league_player_limit = 2610
234+
def get_league_player_limit():
235+
league_player_limit = 101
236+
237+
return league_player_limit
238+
239+
240+
league_player_limit = get_league_player_limit()
112241

113242
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
114243
# QUERY SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

0 commit comments

Comments
 (0)