|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""YFPY demo. |
| 3 | +
|
| 4 | +""" |
| 5 | +__author__ = "Wren J. R. (uberfastman)" |
| 6 | + |
| 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))) |
0 commit comments