=============================================================================
=============================================================================
Please use this data to make some slick visualizations of just how awesome, balanced, or powerful your team and/or league is!
Data pulled from the Yahoo API is in the form of JSON. You can utilize the files
in this format if you feel comfortable working with it, or you can utilize the
Data Transformation script (Data_Transformations.py
) or the Jupyter Notebook
to convert some of the data into a more friendly CSV.
Once the data is output in .csv format you can then use those files in Excel, Tableau, or with any visualization package available in Python.
There is a Data Analysis
folder with some beginnings of automated
charts that can be created in Seaborn. This is obviously much easier and faster
in a program like Excel or Tableau, but if you're like me and like clicking one
button to extract, parse, compile, sort, and export my data, then this tool was
made for you! (Note that data viz is done in Jupyter Notebooks for ease of
displaying the graphs inline)
In order for this whole thing to run correctly, you will need to update a few key scripts, data files, and get your Yahoo API authorization tokens (very easy):
It may be easier to install a text editor like Atom to do all of these next steps in one application...that's up to you. You can easily edit JSON files by changing the extension from .json to .txt, make the desired edits, and change the extension back to .json.
Libraries needed
If using the visualizations in ./Data Analysis/
league_info_form.txt
file in the Initial_Setup
folder.league_info_form.txt
file. Default is QB,WR1,WR2,WR3,RB1,RB2,TE,W/R/T,K,DEF,BN1-6, however
10 bench spots are shown to account for overflow in either unrostered
players, or empty roster positions during the waiver/drop/add period each
week. As a rule of thumb, add 4 bench ('BN') to your roster here to
account for the unknownYahoo has not updated their API documentation for quite some time. In an effort to try and gather some raw data from my fantasy football league I pieced together 3 different libraries previously used to access the Yahoo API. This was a trial and error method since each library hadn't been updated in a few years, and there were no clear examples of input/output for a fantasy sports application. The login and authentication process used in these scripts should be applicable to every other fantasy sport league hosted on Yahoo, as long as the appropriate Game Key is utilized.
In the code you'll see the following notation used to identify your specific league:
"game_key.l.league_id"
get_league_info.py
script to find that specific key. Just specify the sport you
are looking for.__Update fantasy_stats.py__ Note: This previously needed to be input manually throughout the main script, this is no longer required. You only need to update your League ID in one location.
league_info_form.txt
file in the Initial_Setup
folder to be filled out. Game Keys for previous years can be manually overwritten by replacing the 'game_key' variable with the specific year you want to see. Note, you will also need the previous years' league_id as well. You can use the following URL to access specific seasons, or multiple: url = 'https://fantasysports.yahooapis.com/fantasy/v2/games;game_codes=nfl;seasons=2020,2021' For quick reference, the Game Key for the NFL for the last few seasons are:
Year | Game Key |
---|---|
2015 | 348 |
2016 | 359 |
2017 | 371 |
2018 | 380 |
2019 | 390 |
2020 | 399 |
2021 | 406 |
2022 | 414 |
__Update /teams/team_numbers.txx, team_mapping_full.txt, and team_mapping_initials.txt__
Register for Yahoo Developer Network and get your credentials:
App ID
, Client ID(Consumer Key)
, and Client Secret(Consumer Secret)
with a long string of random letters and numbers. Yahoo will use these
keys to allow you to access it's API via OAuth 2.0.Update the Yahoo OAuth files
./auth/
, open oauth2yahoo.json
to edit.Consumer Key
and Consumer Secret Key
into the
respective lines. After you allow access (next step), you will see 'Access
Key', 'Refresh Token', 'Token Time', and 'Token Type' automatically be
added to this file. DO NOT EDIT THIS FILE EVER AGAIN OR YOU WILL BE IN A
WORLD OF HURTleague_authorization.py
script in the Initial_Setup
folder
first in order to authorize your app. This only uses the Consumer Key
and Consumer Secret Key
where as all the other scripts utilize the
Access Key
in addition. You WILL get an error if you run anything else
before this script. There is also a jupyter notebbok for those who want to
use that instead.fantasy_stats.py
__Update Data_Transformations.py under the Data Analysis Folder__
Have fun exploring the data!
fantasy_stats.py
each week to update all data. Out-weeks will
either display 0's for everything or the exact same data as the most current
week.Resources and documentation for future development and data that can be extracted from the Yahoo API:
https://developer.yahoo.com/fantasysports/guide/
https://developer.yahoo.com/fantasysports/guide/game-resource.html#game-resource-desc