Skip to content

Commit 1e74a0e

Browse files
committed
fix issue with json string output in nested queries and saving/loading, update docs, and add quickstart code
1 parent f1761f0 commit 1e74a0e

21 files changed

+893
-389
lines changed

DEPLOYMENT.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,51 +63,63 @@
6363
python -m pytest -v -s -m integration test/integration/test_api_game_data.py -k test_get_game_key_by_season
6464
```
6565

66-
12. Update the git tag:
66+
12. *(Optional)* Build the documentation and PyPI package independent of deployment:
6767

68-
`git tag -a [tag_name/version] -m [message]`
68+
```shell
69+
make -C docs-sphinx docs
70+
```
71+
72+
***Note***: You can run `make -C docs-sphinx docs_no_build` to recreate documentation without building the PyPI package with `setup.py`.
73+
74+
13. *(Optional)* Check Sphinx documentation locally:
6975

7076
```shell
71-
git tag -a v1.0.0 -m 'first release'
72-
git push origin --tags
77+
make -C docs-sphinx open_local_docs
7378
```
7479

75-
13. *(Optional)* Build the documentation and PyPI package independent of deployment:
80+
14. Create a git commit:
7681

7782
```shell
78-
make -C docs-sphinx docs
83+
git add .
84+
git commit -m 'commit message'
7985
```
80-
81-
***Note***: You can run `make -C docs-sphinx docs_no_build` to recreate documentation without building the PyPI package with `setup.py`.
8286

83-
14. *(Optional)* Check Sphinx documentation locally:
87+
15. Update the git tag with the new version:
88+
89+
`git tag -a [tag_name/version] -m [message]`
8490

8591
```shell
86-
make -C docs-sphinx open_local_docs
92+
git tag -a v1.0.0 -m 'release message'
93+
git push origin --tags
8794
```
8895

89-
15. Install `twine` (if not already installed):
96+
16. Install `twine` (if not already installed):
9097

9198
```shell
9299
pip install twine
93100
```
94101

95-
16. *(Optional)* Test deployment by building the PyPI packages, recreating the documentation, and deploying to Test PyPI:
102+
17. *(Optional)* Test deployment by building the PyPI packages, recreating the documentation, and deploying to Test PyPI:
96103

97104
```shell
98105
make -C docs-sphinx test_deploy
99106
```
100107

101-
17. Deploy YFPY by building the PyPI packages, recreating the Sphinx documentation, and deploying to PyPI:
108+
18. Deploy YFPY by building the PyPI packages, recreating the Sphinx documentation, and deploying to PyPI:
102109

103110
```shell
104111
make -C docs-sphinx deploy
105112
```
106113

107-
18. Update YFPY GitHub repository:
114+
19. Create a second git commit with updated version number and documentation:
108115

109116
```shell
110117
git add .
111-
git commit -m 'commit message'
118+
git commit -m 'update version number and docs'
119+
```
120+
121+
20. Update YFPY GitHub repository:
122+
123+
```shell
112124
git push
113125
```

docs-sphinx/source/_autosummary/yfpy.data.Data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.. autosummary::
1717
:nosignatures:
1818

19-
~Data.get
19+
~Data.fetch
2020
~Data.load
2121
~Data.retrieve
2222
~Data.save
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
yfpy.utils.jsonify\_data
2+
========================
3+
4+
.. currentmodule:: yfpy.utils
5+
6+
.. autofunction:: jsonify_data
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
yfpy.utils.jsonify\_data\_to\_file
2+
==================================
3+
4+
.. currentmodule:: yfpy.utils
5+
6+
.. autofunction:: jsonify_data_to_file

docs-sphinx/source/_autosummary/yfpy.utils.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
yfpy.utils
1+
yfpy.utils
22
==========
33

44
.. automodule:: yfpy.utils
@@ -22,6 +22,8 @@ yfpy.utils
2222
flatten_to_list
2323
flatten_to_objects
2424
get_type
25+
jsonify_data
26+
jsonify_data_to_file
2527
prettify_data
2628
reformat_json_list
2729
reorganize_json_dict

docs-sphinx/source/_static/custom.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
/* necessary to remove the duplicated toctree entries created by referencing index in the sphinx index.rst */
2222
.wy-menu-vertical > ul > li:nth-child(1),
2323
.wy-menu-vertical > ul > li:nth-child(2),
24+
.wy-menu-vertical > ul > li:nth-child(3),
2425
.wy-nav-content .toctree-wrapper > ul > li:nth-child(1),
25-
.wy-nav-content .toctree-wrapper > ul > li:nth-child(2) {
26+
.wy-nav-content .toctree-wrapper > ul > li:nth-child(2),
27+
.wy-nav-content .toctree-wrapper > ul > li:nth-child(3) {
2628
display: none;
2729
}
2830

docs-sphinx/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:maxdepth: 2
44

55
index
6+
Quickstart <yfpy-quickstart>
67
Package <_autosummary/yfpy>
78
Tests <_autosummary/test>
89

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Quickstart
2+
**********
3+
4+
.. literalinclude:: ../../quickstart/quickstart.py
5+
:language: python

quickstart/quickstart.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# -*- coding: utf-8 -*-
2+
"""YFPY demo.
3+
4+
"""
5+
__author__ = "Wren J. R. (uberfastman)"
6+
__email__ = "[email protected]"
7+
8+
import os
9+
from pathlib import Path
10+
11+
from dotenv import load_dotenv
12+
13+
from yfpy import Data
14+
from yfpy.query import YahooFantasySportsQuery
15+
16+
"""
17+
Example public Yahoo league URL: "https://archive.fantasysports.yahoo.com/nfl/2014/729259"
18+
19+
Example vars using public Yahoo leagues still require auth through a personal Yahoo account: see README.md
20+
"""
21+
22+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
23+
# ENVIRONMENT SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
24+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
25+
26+
# load .env file in order to read local environment variables
27+
load_dotenv()
28+
29+
# set directory location of private.json for authentication
30+
auth_dir = Path(__file__).parent
31+
32+
# set target directory for data output
33+
data_dir = Path(__file__).parent / "output"
34+
35+
# create YFPY Data instance for saving/loading data
36+
data = Data(data_dir)
37+
38+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
39+
# VARIABLE SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
40+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
41+
42+
# set desired season year
43+
season = 2021
44+
45+
# set desired week
46+
chosen_week = 1
47+
48+
# set desired date
49+
chosen_date = "2013-04-15" # NHL - 2013 (for 2012)
50+
# chosen_date = "2013-04-16" # NHL - 2013
51+
# chosen_date = "2021-10-25" # NHL - 2021
52+
# chosen_date = "2021-04-01" # MLB - 2021
53+
# chosen_date = "2022-04-10" # MLB - 2022
54+
55+
# set desired Yahoo Fantasy Sports game code
56+
game_code = "nfl" # NFL
57+
# game_code = "nhl" # NHL
58+
# game_code = "mlb" # MLB
59+
60+
# set desired Yahoo Fantasy Sports game ID (see the get_all_yahoo_fantasy_game_keys query to retrieve values)
61+
# game_id = 331 # NFL - 2014
62+
# game_id = 348 # NFL - 2015 (testing for league with divisions)
63+
# game_id = 390 # NFL - 2019
64+
# game_id = 399 # NFL - 2020
65+
game_id = 406 # NFL - 2021
66+
# game_id = 303 # NHL - 2012
67+
# game_id = 411 # NHL - 2021
68+
# game_id = 404 # MLB - 2021
69+
# game_id = 412 # MLB - 2022
70+
71+
# set desired Yahoo Fantasy Sports game key (see the get_all_yahoo_fantasy_game_keys query to retrieve values)
72+
# game_key = "331" # NFL - 2014
73+
# game_key = "348" # NFL - 2015 (testing for league with divisions)
74+
# game_key = "390" # NFL - 2019
75+
# game_key = "399" # NFL - 2020
76+
game_key = "406" # NFL - 2021
77+
# game_key = "303" # NHL - 2012
78+
# game_key = "411" # NHL - 2021
79+
# game_key = "404" # MLB - 2021
80+
# game_key = "412" # MLB - 2022
81+
82+
# set desired league ID (see README.md for finding value)
83+
# league_id = "907359" # NFL - 2015 (testing for league with divisions)
84+
# league_id = "79230" # NFL - 2019
85+
# league_id = "655434" # NFL - 2020
86+
league_id = "413954" # NFL - 2021
87+
# league_id = "69624" # NHL - 2012
88+
# league_id = "101592" # NHL - 2021
89+
# league_id = "40134" # MLB - 2021
90+
91+
# set desired team ID within desired league
92+
team_id = 1 # NFL
93+
# team_id = 2 # NHL (2012)
94+
95+
# set desired team name within desired league
96+
team_name = "Legion" # NFL
97+
# team_name = "The Bateleurs" # NHL (2012)
98+
99+
# set desired team ID within desired league
100+
player_id = 7200 # NFL: Aaron Rodgers - 2020/2021
101+
# player_id = 4588 # NHL: Braden Holtby - 2012
102+
# player_id = 8205 # NHL: Jeffrey Viel - 2021
103+
# player_id = 3637 # NHL: Alex Ovechkin - 2021
104+
# player_id = 9897 # MLB: Tim Anderson - 2021/2022
105+
106+
# set the maximum number players you wish the get_league_players query to retrieve
107+
league_player_limit = 101
108+
# league_player_limit = 2610
109+
110+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
111+
# QUERY SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
112+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
113+
114+
# configure the Yahoo Fantasy Sports query (change all_output_as_json_str=True if you want to output JSON strings)
115+
yahoo_query = YahooFantasySportsQuery(
116+
auth_dir,
117+
league_id,
118+
game_id=game_id,
119+
game_code=game_code,
120+
offline=False,
121+
all_output_as_json_str=False,
122+
consumer_key=os.environ["YFPY_CONSUMER_KEY"],
123+
consumer_secret=os.environ["YFPY_CONSUMER_SECRET"],
124+
browser_callback=True
125+
)
126+
127+
# Manually override league key for example code to work
128+
yahoo_query.league_key = f"{game_id}.l.{league_id}"
129+
130+
# Manually override player key for example code to work
131+
player_key = f"{game_id}.p.{player_id}"
132+
133+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
134+
# RUN QUERIES # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
135+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
136+
137+
print(repr(yahoo_query.get_all_yahoo_fantasy_game_keys()))
138+
print(repr(yahoo_query.get_game_key_by_season(season)))
139+
print(repr(yahoo_query.get_current_game_info()))
140+
print(repr(yahoo_query.get_current_game_metadata()))
141+
print(repr(yahoo_query.get_game_info_by_game_id(game_id)))
142+
print(repr(yahoo_query.get_game_metadata_by_game_id(game_id)))
143+
print(repr(yahoo_query.get_game_weeks_by_game_id(game_id)))
144+
print(repr(yahoo_query.get_game_stat_categories_by_game_id(game_id)))
145+
print(repr(yahoo_query.get_game_position_types_by_game_id(game_id)))
146+
print(repr(yahoo_query.get_game_roster_positions_by_game_id(game_id)))
147+
print(repr(yahoo_query.get_league_key(season)))
148+
print(repr(yahoo_query.get_current_user()))
149+
print(repr(yahoo_query.get_user_games()))
150+
print(repr(yahoo_query.get_user_leagues_by_game_key(game_key)))
151+
print(repr(yahoo_query.get_user_teams()))
152+
print(repr(yahoo_query.get_league_info()))
153+
print(repr(yahoo_query.get_league_metadata()))
154+
print(repr(yahoo_query.get_league_settings()))
155+
print(repr(yahoo_query.get_league_standings()))
156+
print(repr(yahoo_query.get_league_teams()))
157+
print(repr(yahoo_query.get_league_players(player_count_limit=10, player_count_start=0)))
158+
print(repr(yahoo_query.get_league_draft_results()))
159+
print(repr(yahoo_query.get_league_transactions()))
160+
print(repr(yahoo_query.get_league_scoreboard_by_week(chosen_week)))
161+
print(repr(yahoo_query.get_league_matchups_by_week(chosen_week)))
162+
print(repr(yahoo_query.get_team_info(team_id)))
163+
print(repr(yahoo_query.get_team_metadata(team_id)))
164+
print(repr(yahoo_query.get_team_stats(team_id)))
165+
print(repr(yahoo_query.get_team_stats_by_week(team_id, chosen_week)))
166+
print(repr(yahoo_query.get_team_standings(team_id)))
167+
print(repr(yahoo_query.get_team_roster_by_week(team_id, chosen_week)))
168+
print(repr(yahoo_query.get_team_roster_player_info_by_week(team_id, chosen_week)))
169+
# print(repr(yahoo_query.get_team_roster_player_info_by_date(team_id, chosen_date))) # NHL/MLB/NBA
170+
print(repr(yahoo_query.get_team_roster_player_stats(team_id)))
171+
print(repr(yahoo_query.get_team_roster_player_stats_by_week(team_id, chosen_week)))
172+
print(repr(yahoo_query.get_team_draft_results(team_id)))
173+
print(repr(yahoo_query.get_team_matchups(team_id)))
174+
print(repr(yahoo_query.get_player_stats_for_season(player_key)))
175+
print(repr(yahoo_query.get_player_stats_by_week(player_key, chosen_week)))
176+
# print(repr(yahoo_query.get_player_stats_by_date(player_key, chosen_date))) # NHL/MLB/NBA
177+
print(repr(yahoo_query.get_player_ownership(player_key)))
178+
print(repr(yahoo_query.get_player_percent_owned_by_week(player_key, chosen_week)))
179+
print(repr(yahoo_query.get_player_draft_analysis(player_key)))

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
bandit==1.7.4
2-
coverage==6.4.4
2+
coverage==6.5.0
33
flake8==5.0.4
44
pytest==7.1.3
55
python-dotenv==0.21.0
66
requests==2.28.1
77
stringcase==1.2.0
8-
yahoo-oauth==1.1
8+
yahoo-oauth==2.0

0 commit comments

Comments
 (0)