### Install Dependencies Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Installs project dependencies from both `requirements.txt` and `requirements-dev.txt`. This step ensures all necessary packages are available for development and deployment. ```shell pip install -r requirements.txt -r requirements-dev.txt ``` -------------------------------- ### Install YFPY Manually Source: https://github.com/uberfastman/yfpy/blob/main/README.md This snippet outlines the steps for manually installing the YFPY library from source. It involves cloning the repository and then running the setup script. ```bash git clone https://github.com/uberfastman/yfpy.git cd yfpy pip install . ``` -------------------------------- ### Install Twine Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Installs the `twine` utility, which is used for uploading Python packages to PyPI. This is a prerequisite for deploying packages. ```shell pip install twine ``` -------------------------------- ### Install YFPY using Pip Source: https://github.com/uberfastman/yfpy/blob/main/docs/readme/index.html This snippet shows the command to install the YFPY library using pip, the Python package installer. It's the most common way to get the library into your Python environment. ```bash pip install yfpy ``` -------------------------------- ### Get League Settings Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves the settings configuration for the current fantasy league. This includes rules, scoring, and roster settings. ```Python query.get_league_settings() ``` -------------------------------- ### Get League Information Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves general information about the current fantasy league. This includes league name, settings, and other core details. ```Python query.get_league_info() ``` -------------------------------- ### Run Yahoo Fantasy Sports Queries Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Provides examples of various query methods available in the YahooFantasySportsQuery class, such as retrieving game keys, league information, player data, and standings. ```Python # print(repr(query.get_all_yahoo_fantasy_game_keys())) # print(repr(query.get_game_key_by_season(test_season))) # print(repr(query.get_current_game_info())) # print(repr(query.get_current_game_metadata())) # print(repr(query.get_game_info_by_game_id(test_game_id))) # print(repr(query.get_game_metadata_by_game_id(test_game_id))) # print(repr(query.get_game_weeks_by_game_id(test_game_id))) # print(repr(query.get_game_stat_categories_by_game_id(test_game_id))) # print(repr(query.get_game_position_types_by_game_id(test_game_id))) # print(repr(query.get_game_roster_positions_by_game_id(test_game_id))) # print(repr(query.get_league_key(test_season))) # print(repr(query.get_current_user())) # print(repr(query.get_user_games())) # print(repr(query.get_user_leagues_by_game_key(test_game_key))) # print(repr(query.get_user_teams())) # print(repr(query.get_league_info())) # print(repr(query.get_league_metadata())) # print(repr(query.get_league_settings())) # print(repr(query.get_league_standings())) # print(repr(query.get_league_teams())) # print(repr(query.get_league_players(player_count_limit=10, player_count_start=0))) # print(repr(query.get_league_draft_results())) # print(repr(query.get_league_transactions())) # print(repr(query.get_league_scoreboard_by_week(test_chosen_week))) # print(repr(query.get_l ``` -------------------------------- ### Get User Games Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches a list of all fantasy games the current user is participating in. This provides an overview of the user's fantasy leagues. ```Python query.get_user_games() ``` -------------------------------- ### Retrieve Player Stats for Season Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Gets the statistics for a player for the entire season. This provides a season-long performance overview. ```Python query.get_player_stats_for_season(test_player_key) ``` ```Python query.get_player_stats_for_season(test_player_key, limit_to_league_stats=False) ``` -------------------------------- ### Get League Metadata Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches metadata for the current fantasy league. This can include administrative details, creation date, and other relevant information. ```Python query.get_league_metadata() ``` -------------------------------- ### Get League Players Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches a list of players available in the current fantasy league's player pool. Allows for pagination using `player_count_limit` and `player_count_start`. ```Python query.get_league_players(player_count_limit=10, player_count_start=0) ``` -------------------------------- ### Get All Yahoo Fantasy Game Keys Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves a list of all available Yahoo Fantasy game keys. These keys are used to identify specific fantasy sports games. ```Python query.get_all_yahoo_fantasy_game_keys() ``` -------------------------------- ### Get League Transactions Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches a log of all transactions (e.g., add/drops, trades) that have occurred in the league. This provides a history of team changes. ```Python query.get_league_transactions() ``` -------------------------------- ### Get League Standings Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches the current standings for all teams in the league. This provides a ranked view of all participants. ```Python query.get_league_standings() ``` -------------------------------- ### Get Current Game Metadata Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches metadata for the currently active fantasy game. This includes administrative details and settings for the ongoing game. ```Python query.get_current_game_metadata() ``` -------------------------------- ### Get Game Key Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves the game key for a specified season, used to identify the fantasy sports game. ```Python def get_game_key(): # MLB - 2022 # BASKETBALL # game_key = "428" # NBA - 2023 game_key = "428" # Example for NBA - 2023 return game_key test_game_key = get_game_key() ``` -------------------------------- ### Get League Teams Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves a list of all teams participating in the current fantasy league. This includes basic information for each team. ```Python query.get_league_teams() ``` -------------------------------- ### Get League Scoreboard by Week Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves the scoreboard for a specific week in the league. This shows the results of all matchups for that week. ```Python query.get_league_scoreboard_by_week(test_chosen_week) ``` -------------------------------- ### Get User Teams Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches a list of all fantasy teams managed by the current user across all their games. This provides a consolidated view of the user's teams. ```Python query.get_user_teams() ``` -------------------------------- ### Build PyPI Package Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Builds the PyPI package for the project. This is an optional step performed independently of the deployment process. ```make make build ``` -------------------------------- ### Get Game Metadata by Game ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches metadata for a specific fantasy game identified by its game ID. This provides administrative details for a particular game. ```Python query.get_game_metadata_by_game_id(test_game_id) ``` -------------------------------- ### Install YFPY using Pip Source: https://github.com/uberfastman/yfpy/blob/main/README.md This snippet shows the command to install the YFPY library using pip, the standard package installer for Python. Ensure you have Python and pip installed. ```bash pip install yfpy ``` -------------------------------- ### Get Current Game Information Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves information about the currently active fantasy game. This provides details about the ongoing season or game. ```Python query.get_current_game_info() ``` -------------------------------- ### Get Game Roster Positions by Game ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Fetches the roster position settings for a specific fantasy game ID. This details the available roster spots and their requirements. ```Python query.get_game_roster_positions_by_game_id(test_game_id) ``` -------------------------------- ### Retrieve Team Roster Player Info by Week Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Gets detailed information about players on a team's roster for a specific week. This can include player stats, status, and other relevant data. ```Python query.get_team_roster_player_info_by_week(test_team_id, test_chosen_week) ``` -------------------------------- ### Get User Leagues by Game Key Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves a list of leagues the current user is part of for a specific game key. This helps filter leagues by sport or season. ```Python query.get_user_leagues_by_game_key(test_game_key) ``` -------------------------------- ### Install YFPY using Pip Source: https://github.com/uberfastman/yfpy/blob/main/README.md Installs the YFPY library using pip. This is the recommended method for integrating YFPY into an existing Python project. ```shell pip install yfpy ``` -------------------------------- ### Retrieve Team Roster Player Stats by Week Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Gets the statistics for players on a team's roster for a specific week. This allows for detailed weekly player performance analysis. ```Python query.get_team_roster_player_stats_by_week(test_team_id, test_chosen_week) ``` -------------------------------- ### Get Game Info by Game ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves information for a specific fantasy game using its unique game ID. This allows access to data for any past or present game. ```Python query.get_game_info_by_game_id(test_game_id) ``` -------------------------------- ### Install YFPY using Pip Source: https://github.com/uberfastman/yfpy/blob/main/docs/readme/index.html Installs the YFPY library using pip. This is the recommended method for integrating YFPY into an existing Python project. ```shell pip install yfpy ``` -------------------------------- ### Lint Code with Flake8 Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Applies the flake8 linter to the project code to check for style guide violations and potential errors. It counts errors and displays the source code for each. ```shell flake8 . --count --show-source --statistics ``` -------------------------------- ### Serve MkDocs Documentation Locally Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Serves the MkDocs generated documentation locally, typically at http://localhost:8000/. This allows for previewing the documentation before deployment. ```make make test_docs ``` -------------------------------- ### Get Team Name Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Sets and returns a team name for a specified league. The example provided is for the NFL. ```Python def get_team_name(): # FOOTBALL team_name = "Let Baker Bake" # NFL # HOCKEY # team_name = "The Bateleurs" # NHL (2012) return team_name test_team_name = get_team_name() ``` -------------------------------- ### Get Team ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Sets and returns a team ID for a specified league. The example provided is for the NFL. ```Python def get_team_id(): # FOOTBALL team_id = 1 # NFL # HOCKEY # team_id = 2 # NHL (2012) return team_id test_team_id = get_team_id() ``` -------------------------------- ### Get Player ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Sets and returns a player ID for a specified league and season. The code includes examples for NFL, NHL, MLB, and NBA players. ```Python def get_player_id(): # FOOTBALL player_id = 30123 # NFL: Patrick Mahomes - 2020/2021/2023/2024 # HOCKEY # player_id = 4588 # NHL: Braden Holtby - 2012 # player_id = 8205 # NHL: Jeffrey Viel - 2021 # player_id = 3637 # NHL: Alex Ovechkin - 2021 # BASEBALL # player_id = 9897 # MLB: Tim Anderson - 2021/2022 # BASKETBALL # player_id = 3704 # NBA: LeBron James - 2023 return player_id test_player_id = get_player_id() ``` -------------------------------- ### Initialize YFPY Data and Query Objects Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html This snippet demonstrates how to set up the YFPY environment by creating a Data instance for saving/loading data and configuring variables like season, week, date, game code, game ID, and game key. These variables are essential for querying the Yahoo Fantasy Sports API. ```Python # -*- coding: utf-8 -*- """YFPY demo. """ __author__ = "Wren J. R. (uberfastman)" __email__ = "uberfastman@uberfastman.dev" import os import sys from logging import DEBUG from pathlib import Path project_dir = Path(__file__).parent.parent sys.path.insert(0, str(project_dir)) from yfpy import Data # noqa: E402 from yfpy.logger import get_logger # noqa: E402 from yfpy.query import YahooFantasySportsQuery # noqa: E402 """ Example public Yahoo league URL: "https://archive.fantasysports.yahoo.com/nfl/2014/729259" Example vars using public Yahoo leagues still require auth through a personal Yahoo account: see README.md """ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ENVIRONMENT SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # set target directory for data output data_dir = Path(__file__).parent / "output" # create YFPY Data instance for saving/loading data data = Data(data_dir) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # VARIABLE SETUP # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # set desired season year def get_season(): # season = 2012 # season = 2013 # season = 2014 # season = 2015 # season = 2016 # season = 2017 # season = 2018 # season = 2019 # season = 2020 # season = 2021 # season = 2022 # season = 2023 season = 2024 return season test_season = get_season() # set desired week def get_chosen_week(): chosen_week = 1 return chosen_week test_chosen_week = get_chosen_week() # set desired date def get_chosen_date(): # HOCKEY # chosen_date = "2013-04-15" # NHL - 2013 (for 2012 season) chosen_date = "2021-10-25" # NHL - 2021 # BASEBALL # chosen_date = "2021-04-01" # MLB - 2021 # chosen_date = "2022-04-10" # MLB - 2022 # BASKETBALL # chosen_date = "2023-11-26" return chosen_date test_chosen_date = get_chosen_date() # set desired Yahoo Fantasy Sports game code def get_game_code(): # FOOTBALL game_code = "nfl" # NFL # HOCKEY # game_code = "nhl" # NHL # BASEBALL # game_code = "mlb" # MLB # BASKETBALL # game_code = "nba" # NBA return game_code test_game_code = get_game_code() # set desired Yahoo Fantasy Sports game ID (see the get_all_yahoo_fantasy_game_keys query to retrieve values) def get_game_id(): # FOOTBALL # game_id = 331 # NFL - 2014 # game_id = 348 # NFL - 2015 (divisions) # game_id = 359 # NFL - 2016 # game_id = 371 # NFL - 2017 # game_id = 380 # NFL - 2018 # game_id = 390 # NFL - 2019 # game_id = 399 # NFL - 2020 # game_id = 406 # NFL - 2021 # game_id = 414 # NFL - 2022 (divisions) # game_id = 423 # NFL - 2023 game_id = 449 # NFL - 2024 # HOCKEY # game_id = 303 # NHL - 2012 # game_id = 411 # NHL - 2021 # game_id = 427 # NHL - 2023 # BASEBALL # game_id = 404 # MLB - 2021 # game_id = 412 # MLB - 2022 # BASKETBALL # game_id = 428 # NBA - 2023 return game_id test_game_id = get_game_id() # set desired Yahoo Fantasy Sports game key (see the get_all_yahoo_fantasy_game_keys query to retrieve values) def get_game_key(): # FOOTBALL # game_key = "331" # NFL - 2014 # game_key = "348" # NFL - 2015 (divisions) # game_key = "359" # NFL - 2016 # game_key = "371" # NFL - 2017 # game_key = "380" # NFL - 2018 # game_key = "390" # NFL - 2019 # game_key = "399" # NFL - 2020 # game_key = "406" # NFL - 2021 # game_key = "414" # NFL - 2022 (divisions) # game_key = "423" # NFL - 2023 game_key = "449" # NFL - 2024 # HOCKEY # game_key = "303" # NHL - 2012 # game_key = "411" # NHL - 2021 # game_key = "427" # NHL - 2023 # BASEBALL # game_key = "404" # MLB - 2021 # game_key = "412" ``` -------------------------------- ### Get League ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Sets and returns the league ID for a desired fantasy sports league. The code includes commented-out examples for various leagues and seasons (NFL, NHL, MLB, NBA). ```Python def get_league_id(): # FOOTBALL # league_id = "907359" # NFL - 2015 (divisions) # league_id = "79230" # NFL - 2019 # league_id = "655434" # NFL - 2020 # league_id = "413954" # NFL - 2021 # league_id = "791337" # NFL - 2022 (divisions) # league_id = "321958" # NFL - 2023 league_id = "365083" # NFL - 2024 # HOCKEY # league_id = "69624" # NHL - 2012 # league_id = "101592" # NHL - 2021 # league_id = "6546" # NHL - 2021 (draft pick trading) # league_id = "22827" # NHL - 2023 # league_id = "1031" # NHL - 2023 (FAAB) # BASEBALL # league_id = "40134" # MLB - 2021 # BASKETBALL # league_id = "969" # NBA - 2023 # league_id = "122731" # NBA - 2023 return league_id test_league_id = get_league_id() ``` -------------------------------- ### Build PyPI Package and Docs Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Builds both the PyPI package and the MkDocs documentation. This command is used for creating distributable artifacts. ```make make docs ``` -------------------------------- ### Deploy to PyPI Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Deploys the project's PyPI packages and documentation to the official Python Package Index. This command builds the necessary artifacts and uploads them. ```make make deploy ``` -------------------------------- ### Initialize YahooFantasySportsQuery Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Initializes the YahooFantasySportsQuery object with league ID, game code, game ID, and authentication credentials. It also demonstrates how to manually override league and player keys. ```Python # configure the Yahoo Fantasy Sports query (change all_output_as_json_str=True if you want to output JSON strings) query = YahooFantasySportsQuery( test_league_id, test_game_code, game_id=test_game_id, yahoo_consumer_key=os.environ.get("YAHOO_CONSUMER_KEY"), yahoo_consumer_secret=os.environ.get("YAHOO_CONSUMER_SECRET"), # yahoo_access_token_json=os.environ.get("YAHOO_ACCESS_TOKEN_JSON"), env_file_location=project_dir, save_token_data_to_env_file=True ) # query.save_access_token_data_to_env_file(project_dir, save_json_to_var_only=True) # Manually override league key for example code to work query.league_key = f"{test_game_id}.l.{test_league_id}" # Manually override player key for example code to work test_player_key = f"{test_game_id}.p.{test_player_id}" ``` -------------------------------- ### Test PyPI Deployment Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Performs a test deployment to the Test PyPI repository. This involves building the PyPI packages, recreating documentation, and uploading to the test server. ```make make test_deploy ``` -------------------------------- ### Get League Player Limit Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Sets and returns the maximum number of players to retrieve for a league query. ```Python def get_league_player_limit(): league_player_limit = 101 return league_player_limit test_league_player_limit = get_league_player_limit() ``` -------------------------------- ### Uninstall Old Requirements Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Clears the virtual environment of existing package requirements. This is an optional step to ensure a clean slate before installing new dependencies. ```shell pip uninstall -y -r <(pip freeze) ``` -------------------------------- ### Get League Key Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves the league key for a given season. This key is fundamental for accessing all league-specific data. ```Python query.get_league_key(test_season) ``` -------------------------------- ### Get League Draft Results Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves the draft results for the entire league. This includes all picks made during the fantasy draft. ```Python query.get_league_draft_results() ``` -------------------------------- ### Retrieve Team Matchups Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves all matchups for a given fantasy team. This provides a comprehensive view of the team's head-to-head schedule. ```Python query.get_team_matchups(test_team_id) ``` -------------------------------- ### Test Python Support with Act Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Tests Python support for GitHub Actions using the `act` tool. This command simulates a GitHub Actions workflow locally. ```shell act_amd -j build ``` -------------------------------- ### Get Current User Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves information about the currently authenticated user. This provides details about the logged-in fantasy sports user. ```Python query.get_current_user() ``` -------------------------------- ### Build Docker Container Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Builds the Docker container for the YFPY project using specified compose files. This command prepares the application for containerized deployment. ```docker docker compose -f compose.yaml -f compose.build.yaml build ``` -------------------------------- ### Push Docker Image to GitHub Container Registry Source: https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md Pushes the newly built Docker image to the GitHub Container Registry with a specified version tag (X.X.X). This makes the container image available for deployment. ```docker docker push ghcr.io/uberfastman/yfpy:X.X.X ``` -------------------------------- ### Get Game Key by Season Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Finds the game key associated with a specific fantasy season. This is useful for targeting data from a particular year. ```Python query.get_game_key_by_season(test_season) ``` -------------------------------- ### Get Game Weeks by Game ID Source: https://github.com/uberfastman/yfpy/blob/main/docs/quickstart/index.html Retrieves a list of all valid weeks for a given fantasy game ID. This is essential for querying week-specific data. ```Python query.get_game_weeks_by_game_id(test_game_id) ``` -------------------------------- ### Initialize MkDocs Navigation Source: https://github.com/uberfastman/yfpy/blob/main/docs/index.html This JavaScript code initializes the navigation functionality for the MkDocs documentation site, likely using a theme like Sphinx's Read the Docs theme. It enables interactive elements within the documentation. ```javascript var base_url = "."; jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Get Current User Metadata Source: https://github.com/uberfastman/yfpy/blob/main/docs/query/index.html Retrieves metadata for the currently logged-in user. This function queries the Yahoo API to fetch user-specific information, such as their unique GUID. ```Python def get_current_user(self) -> User: """Retrieve metadata for current logged-in user. Examples: >>> from pathlib import Path >>> from yfpy.query import YahooFantasySportsQuery >>> query = YahooFantasySportsQuery(league_id="######", game_code="nfl") >>> query.get_current_user() User({ "guid": "USER_GUID_STRING" }) Returns: User: YFPY User instance. """ return ```