From efe0c88dd0fe01c7958c2bffe5962bbf9e873295 Mon Sep 17 00:00:00 2001 From: Joseph Armstrong <70788681+armstjc@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:08:08 -0400 Subject: [PATCH] 0.0.10: The "Metrics" Update - Implemented `cfbd_json_py.metrics.get_cfbd_pregame_win_probability_data()`, a function that allows a user to get pregame win probability data from the CFBD API. - Implemented `cfbd_json_py.metrics.get_cfbd_game_win_probability_data()`, a function that allows a user to get win probability data from a valid game ID in the CFBD API. - Implemented `cfbd_json_py.metrics.get_cfbd_player_season_ppa_data()`, a function that allows a user to get player game PPA data from the CFBD API. - Implemented `cfbd_json_py.metrics.get_cfbd_player_game_ppa_data()`, a function that allows a user to get player season PPA data from the CFBD API. - Implemented `cfbd_json_py.metrics.get_cfbd_team_game_ppa_data()`, a function that allows a user to get team game PPA data from the CFBD API. - Implemented `cfbd_json_py.metrics.get_cfbd_team_season_ppa_data()`, a function that allows a user to get team season PPA data from the CFBD API. - Implemented `cfbd_json_py.metrics.get_cfbd_predicted_ppa_from_down_distance()`, a function that allows a user to get predicted PPA values from the CFBD API, given a down and distance (like 1st and 10). - Updated the function descriptions for the following functions: - `cfbd_json_py.utls.reverse_cipher_encrypt()` - `cfbd_json_py.utls.reverse_cipher_decrypt()` - `cfbd_json_py.utls.get_cfbd_api_token()` - Updated the `README.md` file to give users a general idea on what this python package is, how to install it, and how to access this python package's docs. - Added a front page to the Docs website for this python package. - Updated the package version to `0.0.10`. --- CHANGELOG.md | 15 + README.md | 48 + cfbd_json_py/__init__.py | 99 +- cfbd_json_py/betting.py | 8 +- cfbd_json_py/coaches.py | 7 +- cfbd_json_py/conferences.py | 7 +- cfbd_json_py/draft.py | 15 +- cfbd_json_py/drives.py | 7 +- cfbd_json_py/games.py | 27 +- cfbd_json_py/metrics.py | 2394 +++++- cfbd_json_py/players.py | 3 +- cfbd_json_py/utls.py | 10 + docs/cfbd_json_py.html | 280 +- docs/cfbd_json_py/betting.html | 1550 ++-- docs/cfbd_json_py/coaches.html | 1495 ++-- docs/cfbd_json_py/conferences.html | 635 +- docs/cfbd_json_py/draft.html | 2653 ++++--- docs/cfbd_json_py/drives.html | 2125 +++-- docs/cfbd_json_py/games.html | 11359 ++++++++++++++------------- docs/cfbd_json_py/metrics.html | 6559 +++++++++++++++- docs/cfbd_json_py/players.html | 278 +- docs/cfbd_json_py/utls.html | 954 +-- docs/cfbd_json_py/venues.html | 2 +- docs/search.js | 2 +- pyproject.toml | 2 +- 25 files changed, 19632 insertions(+), 10902 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e4c49..9d7d126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ ## 0.0.10: The "Metrics" Update +- Implemented `cfbd_json_py.metrics.get_cfbd_pregame_win_probability_data()`, a function that allows a user to get pregame win probability data from the CFBD API. +- Implemented `cfbd_json_py.metrics.get_cfbd_game_win_probability_data()`, a function that allows a user to get win probability data from a valid game ID in the CFBD API. +- Implemented `cfbd_json_py.metrics.get_cfbd_player_season_ppa_data()`, a function that allows a user to get player game PPA data from the CFBD API. +- Implemented `cfbd_json_py.metrics.get_cfbd_player_game_ppa_data()`, a function that allows a user to get player season PPA data from the CFBD API. +- Implemented `cfbd_json_py.metrics.get_cfbd_team_game_ppa_data()`, a function that allows a user to get team game PPA data from the CFBD API. +- Implemented `cfbd_json_py.metrics.get_cfbd_team_season_ppa_data()`, a function that allows a user to get team season PPA data from the CFBD API. +- Implemented `cfbd_json_py.metrics.get_cfbd_predicted_ppa_from_down_distance()`, a function that allows a user to get predicted PPA values from the CFBD API, given a down and distance (like 1st and 10). +- Updated the function descriptions for the following functions: + - `cfbd_json_py.utls.reverse_cipher_encrypt()` + - `cfbd_json_py.utls.reverse_cipher_decrypt()` + - `cfbd_json_py.utls.get_cfbd_api_token()` +- Updated the `README.md` file to give users a general idea on what this python package is, how to install it, and how to access this python package's docs. +- Added a front page to the Docs website for this python package. +- Updated the package version to `0.0.10`. + ## 0.0.9: The "Bug Fixes 1" Update - Attempted another fix for the `generate_docs.yml` GitHub Workflow to allow it to call `pdoc` properly within GitHub Actions. - Removed the PyArrow package as a required package for this python package. diff --git a/README.md b/README.md index f391205..d0604d7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,50 @@ # cfbd-json-py Allows users to access the CFBD API, and get the resulting data in either a dictionary (think JSON), or in a pandas DataFrame (think spreadsheet). + +## How to Install + +This package is is available through the `pip` package manager, and can be installed through one of the following commands in your terminal/shell: + +``` +pip install cfbd_json_py +``` + +OR + +``` +python -m pip install cfbd_json_py +``` + +If you are using a Linux/Mac instance, you may need to specify `python3` when installing. + +``` +python3 -m pip install cfbd_json_py +``` + +Alternatively, `cfbd-json-py` can be installed from this GitHub repository with the following command through pip: + +``` +pip install git+https://github.com/armstjc/cfbd-json-py +``` + +OR + +``` +python -m pip install git+https://github.com/armstjc/cfbd-json-py +``` + +OR + +``` +python3 -m pip install git+https://github.com/armstjc/cfbd-json-py +``` + +## Project Staus +You can view the status of the project [by clicking on this link](https://github.com/users/armstjc/projects/4). It will be updated periodically as more features are implemented into this python package. + +## Bugs/Issues + +If you find an issue/bug while using this python package, [please feel free to raise an issue](https://github.com/armstjc/cfbd-json-py/issues), we're only human, and there will inevitably be issues found! + +## Docs +For the cfbd-json-py docs, they can be found at [armstjc.github.io/cfbd-json-py/](armstjc.github.io/cfbd-json-py/) \ No newline at end of file diff --git a/cfbd_json_py/__init__.py b/cfbd_json_py/__init__.py index 3a23d63..b7e6009 100644 --- a/cfbd_json_py/__init__.py +++ b/cfbd_json_py/__init__.py @@ -1,11 +1,107 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/06/2023 08:06 PM EDT +# Last Updated Date: 10/20/2023 02:33 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: __init__.py # Purpose: Allows for the python package to function, # by allowing you to to access functions within # this package. #################################################################################################### +""" +# Welcome! +This is the official docs page for the `cfbd_json_py` python package. + +To the left of this page are various endpoints for this python package. +- `cfbd_json_py.betting`: + Holds functions for betting lines and betting data from the CFBD API. +- `cfbd_json_py.coaches`: + Holds functions for you to get coaching data (past and present). +- `cfbd_json_py.conferences`: + Holds functions for you to get information for CFB confrences. +- `cfbd_json_py.draft`: + Holds functions for you to get NFL draft information/data for + various players in the CFBD API +- `cfbd_json_py.drives`: + Holds functions for you to get data for offensive and/or defensive drives + within the CFBD API. +- `cfbd_json_py.games`: + Holds functions for you to get various datapoints pertaining to + actual CFB games within the CFBD API. +- `cfbd_json_py.metrics`: + Holds functions to allow you to calculate or retrive various advanced metrics + from the CFBD API. +- `cfbd_json_py.players`: + Holds functions for you to get various + data endpoints related to player stats, + player information, and player data. +- `cfbd_json_py.plays`: + Holds functions for play-by-play (PBP) data for CFB games, + as well as a way to calculate stats from PBP data. +- `cfbd_json_py.rankings`: + Holds functions for various CFB team ranking polls, + and their results. +- `cfbd_json_py.ratings`: + Holds functions to allow you to get various team ratings data + (like SP+, SRS, and Elo team ratings) from the CFBD API. +- `cfbd_json_py.recruiting`: + Holds functions for you to access CFB recruting data and information, + as well as team and player ratings for recruiting. +- `cfbd_json_py.stats`: + Holds functions for you to get various team stats from the CFBD API. +- `cfbd_json_py.teams`: + Holds functions for you to get team information and data, + as well as head-to-head records and matchup history. +- `cfbd_json_py.utls`: + Various utilities that can be used from this package. + Outside of `cfbd_json_py.utls.set_cfbd_api_token()`, + you don't need to call any of these functions directly. +- `cfbd_json_py.venues`: + Holds functions for you to get information on + various venues/stadiums within the college football world. + +# Basic Setup + +If you have a CFBD API key, you have three ways to set it for this python package to use: +1. Declare the API key as a string variable in a python script (not reccomended, extreme security risk). +2. Declare the API key in your environment as `CFBD_API_KEY`. + - `cfbd_json_py` will first look for your environment, + if you don't declare the API key as a string variable, + when calling any function in this python package that uses a CFBD API call. + - If you're using GitHub Actions with this package, + just set a repository secret with the name `CFBD_API_KEY`. + Again, this package will automatically know where to look, + if you've set your API key in the environment +3. Use `cfbd_json_py.utls.set_cfbd_api_token()` to store the API key in an encrypted file on your machine. + - To set the API key for this package with this function, + run this code in a python script, + replacing `"TigersAreAwesome"` with your API key: + +``` +from cfbd_api_key.utls import set_cfbd_api_token + +cfbd_api_key = "TigersAreAwesome" # replace this with your actual API key +set_cfbd_api_token(api_key=cfbd_api_key) +``` + +> **NOTE:** *In a future version, + there will be an executable application seperate from this package + for Windows, Mac, and Linux users to effectively do the same thing + as the above code block, but with a graphical user interface (GUI).* + +If you want to see how to use this python package after setting up your API key, +click on one of the submodules on the left +to view the various functions within each submodule. +Each function has a tutorial script on the various ways you can call that function. + +# Other Notes +- If you want to see all CFBD API endpoints that are currently supported, + [click here](https://api.collegefootballdata.com/api/docs/?url=/api-docs.json#/) + to access the current Swagger docs for the entire API. +- If you want to see the source code for this package, + [click here](https://github.com/armstjc/cfbd-json-py) to see the current stable build of this python package on GitHub. +- If you want to see the active changelog for this python package, + [click here]() to view the changelog of this python package on GitHub. + +""" # Generated Functions: from cfbd_json_py._early_access import * @@ -31,3 +127,4 @@ # Utils from cfbd_json_py.utls import * + diff --git a/cfbd_json_py/betting.py b/cfbd_json_py/betting.py index 6a69c63..0fd0e33 100644 --- a/cfbd_json_py/betting.py +++ b/cfbd_json_py/betting.py @@ -1,13 +1,11 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/06/2023 07:52 PM EDT +# Last Updated Date: 10/23/2023 04:09 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: betting.py # Purpose: Houses functions pertaining to betting data within the CFBD API. #################################################################################################### -import time import warnings -# from datetime import datetime import pandas as pd import requests @@ -49,7 +47,7 @@ def get_cfbd_betting_lines( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -337,7 +335,7 @@ def get_cfbd_betting_lines( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass diff --git a/cfbd_json_py/coaches.py b/cfbd_json_py/coaches.py index 5154c85..96c083b 100644 --- a/cfbd_json_py/coaches.py +++ b/cfbd_json_py/coaches.py @@ -1,12 +1,11 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/09/2023 08:00 PM EDT +# Last Updated Date: 10/23/2023 04:09 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: coaches.py # Purpose: Houses functions pertaining to coaching data within the CFBD API. #################################################################################################### import logging -import time import pandas as pd import requests @@ -40,7 +39,7 @@ def get_cfbd_coaches_info( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -336,7 +335,7 @@ def get_cfbd_coaches_info( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass diff --git a/cfbd_json_py/conferences.py b/cfbd_json_py/conferences.py index e14dacc..087eea3 100644 --- a/cfbd_json_py/conferences.py +++ b/cfbd_json_py/conferences.py @@ -1,11 +1,10 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/06/2023 07:35 PM EDT +# Last Updated Date: 10/23/2023 04:09 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: conferences.py # Purpose: Houses functions pertaining to CFB conference data within the CFBD API. #################################################################################################### -import time import pandas as pd import requests @@ -30,7 +29,7 @@ def get_cfbd_conference_info( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -124,7 +123,7 @@ def get_cfbd_conference_info( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass diff --git a/cfbd_json_py/draft.py b/cfbd_json_py/draft.py index 3f82cf4..cf5a2ce 100644 --- a/cfbd_json_py/draft.py +++ b/cfbd_json_py/draft.py @@ -1,5 +1,5 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/07/2023 10:56 AM EDT +# Last Updated Date: 10/23/2023 04:09 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: draft.py # Purpose: Houses functions pertaining to NFL Draft data within the CFBD API. @@ -7,7 +7,6 @@ from datetime import datetime import logging -import time import pandas as pd import requests from tqdm import tqdm @@ -33,7 +32,7 @@ def get_cfbd_nfl_teams( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -128,7 +127,7 @@ def get_cfbd_nfl_teams( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -189,7 +188,7 @@ def get_cfbd_nfl_positions( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -283,7 +282,7 @@ def get_cfbd_nfl_positions( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -343,7 +342,7 @@ def get_cfbd_nfl_draft_info( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -615,7 +614,7 @@ def get_cfbd_nfl_draft_info( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass diff --git a/cfbd_json_py/drives.py b/cfbd_json_py/drives.py index a1e5aab..cb72343 100644 --- a/cfbd_json_py/drives.py +++ b/cfbd_json_py/drives.py @@ -1,5 +1,5 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/11/2023 8:58 PM EDT +# Last Updated Date: 10/23/2023 04:09 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: drives.py # Purpose: Houses functions pertaining to CFB drive data within the CFBD API. @@ -7,7 +7,6 @@ from datetime import datetime import logging -import time import pandas as pd import requests from tqdm import tqdm @@ -49,7 +48,7 @@ def get_cfbd_drives_info( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -475,7 +474,7 @@ def get_cfbd_drives_info( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass diff --git a/cfbd_json_py/games.py b/cfbd_json_py/games.py index 4ead460..6da4612 100644 --- a/cfbd_json_py/games.py +++ b/cfbd_json_py/games.py @@ -1,5 +1,5 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/19/2023 01:36 PM EDT +# Last Updated Date: 10/23/2023 04:09 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: games.py # Purpose: Houses functions pertaining to CFB game data within the CFBD API. @@ -7,7 +7,6 @@ from datetime import datetime import logging -import time import pandas as pd import requests @@ -49,7 +48,7 @@ def get_cfbd_games( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -435,7 +434,7 @@ def get_cfbd_games( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -531,7 +530,7 @@ def get_cfbd_team_records( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -737,7 +736,7 @@ def get_cfbd_team_records( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -818,7 +817,7 @@ def get_cfbd_season_weeks( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -950,7 +949,7 @@ def get_cfbd_season_weeks( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -1015,7 +1014,7 @@ def get_cfbd_game_media_info( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -1377,7 +1376,7 @@ def get_cfbd_game_media_info( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -1451,7 +1450,7 @@ def get_cfbd_player_game_stats( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -1899,7 +1898,7 @@ def get_cfbd_player_game_stats( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass @@ -3263,7 +3262,7 @@ def get_cfbd_player_advanced_game_stats( `api_key_dir` (str, optional): Optional argument. - If `api_key` is set to a string non-empty string, this variable is ignored. + If `api_key` is set to am empty string, this variable is ignored. If `api_key_dir` is null, and `api_key` is null, this function will try to find a CFBD API key file in this user's home directory. If `api_key_dir` is set to a string, and `api_key` is null, @@ -3381,7 +3380,7 @@ def get_cfbd_player_advanced_game_stats( } response = requests.get(url, headers=headers) - time.sleep(0.1) + if response.status_code == 200: pass diff --git a/cfbd_json_py/metrics.py b/cfbd_json_py/metrics.py index 985eef3..9f1ab80 100644 --- a/cfbd_json_py/metrics.py +++ b/cfbd_json_py/metrics.py @@ -1,24 +1,262 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/19/2023 01:48 PM EDT +# Last Updated Date: 10/27/2023 10:54 AM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: metrics.py # Purpose: Houses functions pertaining to various CFB stats within the CFBD API. #################################################################################################### +from datetime import datetime +import logging +import pandas as pd +import requests +from tqdm import tqdm + +from cfbd_json_py.utls import get_cfbd_api_token + + def get_cfbd_predicted_ppa_from_down_distance( down: int, distance: int, api_key: str = None, - api_key_dir: str = None): + api_key_dir: str = None, + return_as_dict: bool = False): """ + Given a down and distance, + this function will attempt to get the predicted + PPA value for that down and distance, + at every yard line possible for that down and distance. + + PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + + For this endpoint, + [`yardLine`] is the number of yards from 1 (offense has the ball on their side, + at their 1 yard line), to 99 + (offense with the ball with a X and goal situation on the opponent's 1 yard line. + + Parameters + ---------- + `down` (int, mandatory): + Mandatory argument. + This is the down (a number between 1 and 4 in normal situations) + for this play you want PPA for. + + `distance` (int, mandatory): + Mandatory argument. + This variable should be set to the number of yards between + the line of scrimage (LOS), and the first down line on the field. + + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_predicted_ppa_from_down_distance + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get the predicted PPA for a 1st and 10 play, + # in every possible situation. + print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10, + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10, + api_key=cfbd_key, + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + + # Get the predicted PPA for a 1st and 10 play, + # in every possible situation. + print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10 + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10, + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with a calculated PPA from a dwon and distance, + or (if `return_as_dict` is set to `True`) + a dictionary object with a calculated PPA from a dwon and distance. + + """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + # now = datetime.now() + ppa_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/ppa/predicted" + + ######################################################################################################################################################################################################## + + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + + if down >= 1 and down <= 4: + # This is normal, so pass. + pass + elif down == 5: + # Due to a Missouri-Colorado game in the 90s + # being won by Colorado on a mythical "5th down", + # we cannot reject this down outright, + # but we have to convey to the person calling this + # function that setting `down = 5` + # is not something they should be doing. + logging.warn( + "There is a very limited number of \"5th down\" situations " + + "in American Football history. " + + "Do not expect anything back when calling this function, " + + "and setting`down` to `5`." + ) + else: + raise ValueError( + "Invalid `down` inputted! Valid inputs are:\n" + + "\n\t- `1`" + + "\n\t- `2`" + + "\n\t- `3`" + + "\n\t- `4`" + + f"\nYou entered: \t`{down}`" + + + ) + + if distance == 0: + raise ValueError( + "If you want \"X and inches\" predicted PPA data, " + + "set `down` to `1` when calling this function." + ) + elif distance >= 100 and distance <= 110: + raise ValueError( + "The CFBD API cannot calculate predicted PPA for " + + "U-Sports (Canada) football." + ) + elif distance >= 1 and distance <= 99: + # While numbers beyond 30 are rare, + # there are some situations IRL that caused the distance + # in "down and distance" to exceed 90 + # (most famously a 2017 game between + # Mississippi State and Louisiana Tech). + pass + + # URL builder + ######################################################################################################################################################################################################## + # Required by API + url += f"?down={down}&distance={distance}" -def get_cfbd_team_ppa_data( + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for dnd in json_data: + row_df = pd.DataFrame( + { + "down": down, + "distance": distance, + + }, + index=[0] + ) + row_df['predicted_points'] = dnd['predictedPoints'] + row_df['yard_line'] = dnd['yardLine'] + ppa_df = pd.concat([ppa_df, row_df], ignore_index=True) + + return ppa_df + + +def get_cfbd_team_season_ppa_data( api_key: str = None, api_key_dir: str = None, season: int = None, @@ -26,18 +264,343 @@ def get_cfbd_team_ppa_data( # `year` and/or `team` must be not null for this function to work. conference_abv: str = None, exclude_garbage_time: bool = False, - return_as_dict: bool = False): """ + Allows you to get team PPA data, + over an entire season, + with or without garbage time plays, + for a specificed team and/or time period. + + PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + + Parameters + ---------- + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `season` (int, optional): + Semi-optional argument. + Specifies the season you want team PPA data from. + You MUST set `season` or `team` to a non-null value for + this function to work. If you don't, a `ValueError()` + will be raised. + + `team` (str, optional): + Semi-ptional argument. + If you only want team PPA data for a specific team, + set `team` to the name of the team you want team PPA data from. + You MUST set `season` or `team` to a non-null value for + this function to work. If you don't, a `ValueError()` + will be raised. + + `conference_abv` (str, optional): + Optional argument. + If you only want team PPA data from games + involving teams from a specific confrence, + set `conference_abv` to the abbreviation + of the conference you want team PPA data from. + For a list of confrences, + use the `cfbd_json_py.conferences.get_cfbd_conference_info()` + function. + + `exclude_garbage_time` (bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + set `exclude_garbage_time = True`. + Default behavior is that this variable is set to + `False` when this function is called. + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_team_ppa_data + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get team season PPA data for the 2020 CFB season. + print("Get team PPA data for the 2020 CFB season.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes. + print("Get team season PPA data for the 2020 Ohio State Buckeyes.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + team="Ohio State" + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes, + # but exclude garbage time plays when making the PPA calculations. + print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + team="Ohio State", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. + print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="B1G" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="B1G", + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get team season PPA data for the 2020 CFB season. + print("Get team PPA data for the 2020 CFB season.") + json_data = get_cfbd_team_ppa_data( + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes. + print("Get team season PPA data for the 2020 Ohio State Buckeyes.") + json_data = get_cfbd_team_ppa_data( + season=2020, + team="Ohio State" + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes, + # but exclude garbage time plays when making the PPA calculations. + print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") + json_data = get_cfbd_team_ppa_data( + season=2020, + team="Ohio State", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. + print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") + json_data = get_cfbd_team_ppa_data( + season=2020, + conference_abv="B1G" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_ppa_data( + season=2020, + conference_abv="B1G", + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with team season PPA data, + or (if `return_as_dict` is set to `True`) + a dictionary object with a team season PPA data. """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + now = datetime.now() + ppa_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/ppa/teams" + + ######################################################################################################################################################################################################## + + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + + if season == None and team == None: + raise ValueError( + "To use this function, `season` and/or `team` must be set to a " + + "non-null variable." + ) + + if season == None: + # Rare, but in this endpoint, + # you don't need to input the season. + pass + elif season > now.year: + raise ValueError(f"`season` cannot be greater than {season}.") + elif season < 1869: + raise ValueError(f"`season` cannot be less than 1869.") + + gt_str = "" + if exclude_garbage_time == True: + gt_str = "true" + elif exclude_garbage_time == False: + gt_str = "false" + + # URL builder + ######################################################################################################################################################################################################## + url_elements = 0 + + if season != None and url_elements == 0: + url += f"?year={season}" + url_elements += 1 + elif season != None: + url += f"&year={season}" + url_elements += 1 + + if team != None and url_elements == 0: + url += f"?team={team}" + url_elements += 1 + elif team != None: + url += f"&team={team}" + url_elements += 1 + + if conference_abv != None and url_elements == 0: + url += f"?conference={conference_abv}" + url_elements += 1 + elif conference_abv != None: + url += f"&conference={conference_abv}" + url_elements += 1 + + if exclude_garbage_time != None and url_elements == 0: + url += f"?excludeGarbageTime={gt_str}" + url_elements += 1 + elif exclude_garbage_time != None: + url += f"&excludeGarbageTime={gt_str}" + url_elements += 1 + + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for team in tqdm(json_data): + t_season = team['season'] + t_conference = team['conference'] + t_name = team['team'] + + row_df = pd.DataFrame( + { + "season": t_season, + "team_name": t_name, + "team_conference": t_conference + }, + index=[0] + ) + + # Team offense + row_df['offensive_ppa_overall'] = team['offense']['overall'] + row_df['offensive_ppa_passing'] = team['offense']['passing'] + row_df['offensive_ppa_rushing'] = team['offense']['rushing'] + row_df['offensive_ppa_first_down'] = team['offense']['firstDown'] + row_df['offensive_ppa_second_down'] = team['offense']['secondDown'] + row_df['offensive_ppa_third_down'] = team['offense']['thirdDown'] + row_df['offensive_ppa_cumulative'] = team['offense']['cumulative']['total'] + row_df['offensive_ppa_cumulative_passing'] = team['offense']['cumulative']['passing'] + row_df['offensive_ppa_cumulative_rushing'] = team['offense']['cumulative']['rushing'] + + # Team defense + row_df['defensive_ppa_overall'] = team['defense']['overall'] + row_df['defensive_ppa_passing'] = team['defense']['passing'] + row_df['defensive_ppa_rushing'] = team['defense']['rushing'] + row_df['defensive_ppa_first_down'] = team['defense']['firstDown'] + row_df['defensive_ppa_second_down'] = team['defense']['secondDown'] + row_df['defensive_ppa_third_down'] = team['defense']['thirdDown'] + row_df['defensive_ppa_cumulative'] = team['defense']['cumulative']['total'] + row_df['defensive_ppa_cumulative_passing'] = team['defense']['cumulative']['passing'] + row_df['defensive_ppa_cumulative_rushing'] = team['defense']['cumulative']['rushing'] + + ppa_df = pd.concat([ppa_df, row_df], ignore_index=True) + + del t_season, t_conference, t_name + del row_df + return ppa_df -def get_cfbd_game_ppa_data( + +def get_cfbd_team_game_ppa_data( season: int, api_key: str = None, api_key_dir: str = None, @@ -46,21 +609,394 @@ def get_cfbd_game_ppa_data( conference_abv: str = None, exclude_garbage_time: bool = False, season_type: str = "regular", # "regular" or "postseason" - return_as_dict: bool = False): """ + Allows you to get team PPA data, + at a game level, + with or without garbage time plays, + for a specificed team and/or time period. + + PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + + Parameters + ---------- + `season` (int, mandatory): + Required argument. + Specifies the season you want team game PPA data information from. + This must be specified, otherwise this package, and by extension + the CFBD API, will not accept the request to get team game PPA data information. + + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `week` (int, optional): + Optional argument. + If `week` is set to an integer, this function will attempt + to load team game PPA data from games in that season, and in that week. + + `team` (str, optional): + Optional argument. + If you only want team game PPA data for a team, + regardless if they are the home/away team, + set `team` to the name of the team you want team game PPA data from. + + `conference_abv` (str, optional): + Optional argument. + If you only want team game PPA data from games + involving teams a specific confrence, + set `conference_abv` to the abbreviation + of the conference you want team game PPA data from. + + `exclude_garbage_time` (bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + set `exclude_garbage_time = True`. + Default behavior is that this variable is set to + `False` when this function is called. + + `season_type` (str, semi-optional): + Semi-optional argument. + By defualt, this will be set to "regular", for the CFB regular season. + If you want team game PPA data for non-regular season games, + set `season_type` to "postseason". + If `season_type` is set to anything but "regular" or "postseason", + a `ValueError()` will be raised. + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_team_game_ppa_data + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get team PPA data for individual games within the 2020 CFB season. + print("Get team PPA data for individual games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for week 10 games within the 2020 CFB season. + print("Get team PPA data for week 10 games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for + # University of Cincinnati football games within the 2020 CFB season. + print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season, but exclude plays that occur in garbage time. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="SEC", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for postseason games in the 2020 CFB season. + print("Get team PPA data for postseason games in the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Cincinnati", + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get team PPA data for individual games within the 2020 CFB season. + print("Get team PPA data for individual games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for week 10 games within the 2020 CFB season. + print("Get team PPA data for week 10 games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for + # University of Cincinnati football games within the 2020 CFB season. + print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season, but exclude plays that occur in garbage time. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + conference_abv="SEC", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for postseason games in the 2020 CFB season. + print("Get team PPA data for postseason games in the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + team="Cincinnati", + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with team PPA data, + or (if `return_as_dict` is set to `True`) + a dictionary object with team PPA data. """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + now = datetime.now() + cfb_games_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/ppa/games" + ######################################################################################################################################################################################################## -def get_cfbd_game_player_ppa_data( - season: int, + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + + if season == None: + # This should never happen without user tampering, but if it does, + # we need to raise an error, because the CFBD API will refuse this call without a valid season. + raise SystemError( + "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + + " and the function got to this point in the code." + + "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + + "https://github.com/armstjc/cfbd-json-py/issues" + ) + elif season > now.year: + raise ValueError(f"`season` cannot be greater than {season}.") + elif season < 1869: + raise ValueError(f"`season` cannot be less than 1869.") + + if season_type != "regular" and season_type != "postseason": + raise ValueError( + "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + + if week != None and week < 0: + raise ValueError( + "`week` must be a positive number." + ) + + if season_type != "regular" and season_type != "postseason": + raise ValueError( + "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + + gt_str = "" + if exclude_garbage_time == True: + gt_str = "true" + elif exclude_garbage_time == False: + gt_str = "false" + + # URL builder + ######################################################################################################################################################################################################## + + # Required by API + url += f"?seasonType={season_type}" + url += f"&year={season}" + + if week != None: + url += f"&week={week}" + + if team != None: + url += f"&team={team}" + + if conference_abv != None: + url += f"&conference={conference_abv}" + + if exclude_garbage_time != None: + url += f"&excludeGarbageTime={gt_str}" + + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for game in tqdm(json_data): + g_season = game['season'] + g_gid = game['gameId'] + g_week = game['week'] + g_tm = game['team'] + g_conf = game['conference'] + g_opp = game['opponent'] + + row_df = pd.DataFrame( + { + "season": g_season, + "game_id": g_gid, + "week": g_week, + "team": g_tm, + "conference": g_conf, + "opponent": g_opp + }, + index=[0] + ) + + # Team Offense + row_df['ppa_offense_overall'] = game['offense']['overall'] + row_df['ppa_offense_passing'] = game['offense']['passing'] + row_df['ppa_offense_rushing'] = game['offense']['rushing'] + row_df['ppa_offense_first_down'] = game['offense']['firstDown'] + row_df['ppa_offense_second_down'] = game['offense']['secondDown'] + row_df['ppa_offense_third_down'] = game['offense']['thirdDown'] + + # Team Defense + row_df['ppa_defense_overall'] = game['defense']['overall'] + row_df['ppa_defense_passing'] = game['defense']['passing'] + row_df['ppa_defense_rushing'] = game['defense']['rushing'] + row_df['ppa_defense_first_down'] = game['defense']['firstDown'] + row_df['ppa_defense_second_down'] = game['defense']['secondDown'] + row_df['ppa_defense_third_down'] = game['defense']['thirdDown'] + + cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) + + del row_df + del g_gid, g_season, g_week,\ + g_conf, g_tm, g_opp + + return cfb_games_df + + +def get_cfbd_player_game_ppa_data( api_key: str = None, api_key_dir: str = None, + season: int = None, week: int = None, team: str = None, # A week or team must be specified @@ -69,49 +1005,1136 @@ def get_cfbd_game_player_ppa_data( play_threshold: int = None, exclude_garbage_time: bool = False, season_type: str = "regular", # "regular" or "postseason" - return_as_dict: bool = False): """ + Allows you to get player PPA data, + at a game level, + with or without garbage time plays, + for a specificed time period and/or team. + + PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + + Parameters + ---------- + + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `season` (int, semi-optional): + Semi-Optional argument. + Specifies the season you want player game PPA data information from. + This must be specified, otherwise this package, and by extension + the CFBD API, will not accept the request to get player game PPA data information. + + `week` (int, semi-optional): + Semi-Optional argument. + If `week` is set to an integer, this function will attempt + to load player game PPA data from games in that season, and in that week. + `week` and/or `team` must be set to a non-null value for this function + to work. + + `team` (str, semi-optional): + Semi-Optional argument. + If you only want player game PPA data for players of a specific team, + regardless if they are the home/away team, + set `team` to the name of the team you want player game PPA data from. + `week` and/or `team` must be set to a non-null value for this function + to work. + + `position` (str, optional): + Optional argument. + If you only want player game PPA data for players of a specific position, + set `position` to the position you want player game PPA data from. + + `player_id` (int, optional): + Optional argument. + If you only want PPA data for a specific player ID, + set this variable to the player ID of the player you want PPA data from. + + `play_threshold` + Optional argument. + If you only want PPA data for players + who touched the ball for *X* number of plays in a game, + set `play_threshold = x`, where `x` is + your specified minimum number of plays. + + `exclude_garbage_time` (bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + set `exclude_garbage_time = True`. + Default behavior is that this variable is set to + `False` when this function is called. + + `season_type` (str, semi-optional): + Semi-optional argument. + By defualt, this will be set to "regular", for the CFB regular season. + If you want player game PPA data for non-regular season games, + set `season_type` to "postseason". + If `season_type` is set to anything but "regular" or "postseason", + a `ValueError()` will be raised. + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_player_game_ppa_data + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get player game PPA data for week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for players of the + # 2020 University of Cincinnati Football team. + print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, + # but exclude plays in garbage time. + print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + position="QB", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for week 10 of the 2020 CFB season, + # where a player touched the ball for at least 25 plays. + print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + play_threshold=25 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data the 2020 Alabama Crimson Tide Football team, + # during their postseason. + print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Alabama", + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get player game PPA data for week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for players of the + # 2020 University of Cincinnati Football team. + print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, + # but exclude plays in garbage time. + print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + position="QB", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for week 10 of the 2020 CFB season, + # where a player touched the ball for at least 25 plays. + print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + play_threshold=25 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data the 2020 Alabama Crimson Tide Football team, + # during their postseason. + print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + team="Alabama", + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with player PPA data, + or (if `return_as_dict` is set to `True`) + a dictionary object with player PPA data. """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + now = datetime.now() + cfb_games_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/ppa/players/games" + ######################################################################################################################################################################################################## -def get_cfbd_season_player_ppa_data( - season: int, + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + + if season == None: + # This should never happen without user tampering, but if it does, + # we need to raise an error, because the CFBD API will refuse this call without a valid season. + raise SystemError( + "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + + " and the function got to this point in the code." + + "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + + "https://github.com/armstjc/cfbd-json-py/issues" + ) + elif season > now.year: + raise ValueError(f"`season` cannot be greater than {season}.") + elif season < 1869: + raise ValueError(f"`season` cannot be less than 1869.") + + if week == None and team == None: + raise ValueError( + "To call this function, you must set `week` and/or `team` " + + "to a non-null value." + ) + + if season_type != "regular" and season_type != "postseason": + raise ValueError( + "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + + if week != None and week < 0: + raise ValueError( + "`week` must be a positive number." + ) + + if season_type != "regular" and season_type != "postseason": + raise ValueError( + "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + + if play_threshold != None and play_threshold < 0: + raise ValueError( + "`play_threshold` must be an integer at or greater than 0." + ) + + gt_str = "" + if exclude_garbage_time == True: + gt_str = "true" + elif exclude_garbage_time == False: + gt_str = "false" + + # URL builder + ######################################################################################################################################################################################################## + url_elements = 0 + + if season != None and url_elements == 0: + url += f"?year={season}" + url_elements += 1 + elif season != None: + url += f"&year={season}" + url_elements += 1 + + if week != None and url_elements == 0: + url += f"?week={week}" + url_elements += 1 + elif week != None: + url += f"&week={week}" + url_elements += 1 + + if team != None and url_elements == 0: + url += f"?team={team}" + url_elements += 1 + elif team != None: + url += f"&team={team}" + url_elements += 1 + + if position != None and url_elements == 0: + url += f"?position={position}" + url_elements += 1 + elif position != None: + url += f"&position={position}" + url_elements += 1 + + if player_id != None and url_elements == 0: + url += f"?playerId={player_id}" + url_elements += 1 + elif player_id != None: + url += f"&playerId={player_id}" + url_elements += 1 + + if play_threshold != None and url_elements == 0: + url += f"?threshold={play_threshold}" + url_elements += 1 + elif play_threshold != None: + url += f"&threshold={play_threshold}" + url_elements += 1 + + if exclude_garbage_time != None and url_elements == 0: + url += f"?excludeGarbageTime={gt_str}" + url_elements += 1 + elif exclude_garbage_time != None: + url += f"&excludeGarbageTime={gt_str}" + url_elements += 1 + + if season_type != None and url_elements == 0: + url += f"?seasonType={season_type}" + url_elements += 1 + elif season_type != None: + url += f"&seasonType={season_type}" + url_elements += 1 + + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for player in tqdm(json_data): + p_season = player['season'] + row_df = pd.DataFrame( + { + "season": p_season + }, + index=[0] + ) + + row_df['week'] = player['week'] + row_df['player_name'] = player['name'] + row_df['player_position'] = player['position'] + row_df['team'] = player['team'] + row_df['opponent'] = player['opponent'] + + row_df['avg_ppa_all'] = player['averagePPA']['all'] + row_df['avg_ppa_pass'] = player['averagePPA']['pass'] + row_df['avg_ppa_rush'] = player['averagePPA']['rush'] + + # Have to do this because of a FutureWarning that is raised + # starting in pandas 2.1.1, when using pd.concat(), + # and a column datatype mismatch is found. + row_df = row_df.astype( + { + "avg_ppa_all": "float", + "avg_ppa_pass": "float", + "avg_ppa_rush": "float", + } + ) + + cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) + + del row_df + del p_season + + return cfb_games_df + + +def get_cfbd_player_season_ppa_data( api_key: str = None, api_key_dir: str = None, + season: int = None, team: str = None, conference_abv: str = None, position: str = None, player_id: int = None, play_threshold: int = None, exclude_garbage_time: bool = False, - return_as_dict: bool = False): """ + Allows you to get player PPA data, + at a season level, + with or without garbage time plays, + for a specificed time period and/or team. + + PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + + Parameters + ---------- + + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `season` (int, semi-optional): + Semi-Optional argument. + Specifies the season you want player season PPA data information from. + This must be specified, otherwise this package, and by extension + the CFBD API, will not accept the request to get player season PPA data information. + + + `team` (str, semi-optional): + Semi-Optional argument. + If you only want player season PPA data for players of a specific team, + regardless if they are the home/away team, + set `team` to the name of the team you want player season PPA data from. + `week` and/or `team` must be set to a non-null value for this function + to work. + + `conference_abv` (str, optional): + Optional argument. + If you only want player season PPA data from games + involving teams from a specific confrence, + set `conference_abv` to the abbreviation + of the conference you want player season PPA data from. + For a list of confrences, + use the `cfbd_json_py.conferences.get_cfbd_conference_info()` + function. + + `position` (str, optional): + Optional argument. + If you only want player season PPA data for players of a specific position, + set `position` to the position you want player season PPA data from. + + `player_id` (int, optional): + Optional argument. + If you only want PPA data for a specific player ID, + set this variable to the player ID of the player you want PPA data from. + + `play_threshold` + Optional argument. + If you only want PPA data for players + who touched the ball for *X* number of plays in a game, + set `play_threshold = x`, where `x` is + your specified minimum number of plays. + + `exclude_garbage_time` (bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + set `exclude_garbage_time = True`. + Default behavior is that this variable is set to + `False` when this function is called. + + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_player_season_ppa_data + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get player season PPA data for the 2020 CFB season. + print("Get player season PPA data for the 2020 CFB season.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 Ohio Bobcats Football Team. + print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + team="Ohio" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data for players who played on + # teams within the Southeastern Conference (SEC) for the + # 2020 CFB Season. + print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from QBs in the 2020 CFB Season. + print("Get player season PPA data from QBs in the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511). + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + player_id=3915511 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511), + # but exclude plays that occured in garbage time. + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + player_id=3915511, + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 CFB Season, + # for players with at least 100 plays/touches. + print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + play_threshold=100 + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get player season PPA data for the 2020 CFB season. + print("Get player season PPA data for the 2020 CFB season.") + json_data = get_cfbd_player_season_ppa_data( + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 Ohio Bobcats Football Team. + print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + team="Ohio" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data for players who played on + # teams within the Southeastern Conference (SEC) for the + # 2020 CFB Season. + print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from QBs in the 2020 CFB Season. + print("Get player season PPA data from QBs in the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511). + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") + json_data = get_cfbd_player_season_ppa_data( + player_id=3915511 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511), + # but exclude plays that occured in garbage time. + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") + json_data = get_cfbd_player_season_ppa_data( + player_id=3915511, + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 CFB Season, + # for players with at least 100 plays/touches. + print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + play_threshold=100 + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with player PPA data, + or (if `return_as_dict` is set to `True`) + a dictionary object with player PPA data. """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + now = datetime.now() + cfb_games_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/ppa/players/season" + + ######################################################################################################################################################################################################## + + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + + if season == None: + pass + elif season > now.year: + raise ValueError(f"`season` cannot be greater than {season}.") + elif season < 1869: + raise ValueError(f"`season` cannot be less than 1869.") + + if play_threshold != None and play_threshold < 0: + raise ValueError( + "`play_threshold` must be an integer at or greater than 0." + ) + + gt_str = "" + if exclude_garbage_time == True: + gt_str = "true" + elif exclude_garbage_time == False: + gt_str = "false" + + # URL builder + ######################################################################################################################################################################################################## + url_elements = 0 + + if season != None and url_elements == 0: + url += f"?year={season}" + url_elements += 1 + elif season != None: + url += f"&year={season}" + url_elements += 1 + + if team != None and url_elements == 0: + url += f"?team={team}" + url_elements += 1 + elif team != None: + url += f"&team={team}" + url_elements += 1 + + if conference_abv != None and url_elements == 0: + url += f"?conference={conference_abv}" + url_elements += 1 + elif conference_abv != None: + url += f"&conference={conference_abv}" + url_elements += 1 + + if position != None and url_elements == 0: + url += f"?position={position}" + url_elements += 1 + elif position != None: + url += f"&position={position}" + url_elements += 1 + + if player_id != None and url_elements == 0: + url += f"?playerId={player_id}" + url_elements += 1 + elif player_id != None: + url += f"&playerId={player_id}" + url_elements += 1 + + if play_threshold != None and url_elements == 0: + url += f"?threshold={play_threshold}" + url_elements += 1 + elif play_threshold != None: + url += f"&threshold={play_threshold}" + url_elements += 1 + + if exclude_garbage_time != None and url_elements == 0: + url += f"?excludeGarbageTime={gt_str}" + url_elements += 1 + elif exclude_garbage_time != None: + url += f"&excludeGarbageTime={gt_str}" + url_elements += 1 + + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for player in tqdm(json_data): + p_season = player['season'] + row_df = pd.DataFrame( + {"season": p_season}, + index=[0] + ) + row_df['player_id'] = player['id'] + row_df['player_name'] = player['name'] + row_df['player_position'] = player['position'] + row_df['team'] = player['team'] + row_df['conference'] = player['conference'] + row_df['countable_plays'] = player['countablePlays'] + + # Average PPA + row_df['average_ppa_all'] = player['averagePPA']['all'] + row_df['average_ppa_pass'] = player['averagePPA']['pass'] + row_df['average_ppa_rush'] = player['averagePPA']['rush'] + row_df['average_ppa_first_down'] = player['averagePPA']['firstDown'] + row_df['average_ppa_second_down'] = player['averagePPA']['secondDown'] + row_df['average_ppa_third_down'] = player['averagePPA']['thirdDown'] + row_df['average_ppa_standard_downs'] = player['averagePPA']['standardDowns'] + row_df['average_ppa_passing_downs'] = player['averagePPA']['passingDowns'] + + # Total PPA + row_df['total_ppa_all'] = player['totalPPA']['all'] + row_df['total_ppa_pass'] = player['totalPPA']['pass'] + row_df['total_ppa_rush'] = player['totalPPA']['rush'] + row_df['total_ppa_first_down'] = player['totalPPA']['firstDown'] + row_df['total_ppa_second_down'] = player['totalPPA']['secondDown'] + row_df['total_ppa_third_down'] = player['totalPPA']['thirdDown'] + row_df['total_ppa_standard_downs'] = player['totalPPA']['standardDowns'] + row_df['total_ppa_passing_downs'] = player['totalPPA']['passingDowns'] + + # Have to do this because of a FutureWarning that is raised + # starting in pandas 2.1.1, when using pd.concat(), + # and a column datatype mismatch is found. + row_df = row_df.astype( + { + "average_ppa_all": "float", + "average_ppa_pass": "float", + "average_ppa_rush": "float", + "average_ppa_first_down": "float", + "average_ppa_second_down": "float", + "average_ppa_third_down": "float", + "average_ppa_standard_downs": "float", + "average_ppa_passing_downs": "float", + + "total_ppa_all": "float", + "total_ppa_pass": "float", + "total_ppa_rush": "float", + "total_ppa_first_down": "float", + "total_ppa_second_down": "float", + "total_ppa_third_down": "float", + "total_ppa_standard_downs": "float", + "total_ppa_passing_downs": "float" + } + ) + + cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) + del row_df + del p_season + + return cfb_games_df def get_cfbd_game_win_probability_data( game_id: int, api_key: str = None, api_key_dir: str = None, - return_as_dict: bool = False): """ + Allows one to get win probabliity data for a given game ID. + + Parameters + ---------- + + `game_id` (int, mandatory): + Mandatory argument. + This is the game ID for the game you want win probability data from, + at the play-by-play level. + + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_game_win_probability_data + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get the win probablility data for a 2017 game between + # the University of Cincinnati and UConn (game ID #400941851). + print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") + json_data = get_cfbd_game_win_probability_data( + api_key=cfbd_key, + game_id=400941851 + ) + print(json_data) + time.sleep(5) + + # Get the win probablility data for a 2023 game between + # the University of Duke and the University of Louisville (game ID #401525535). + print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") + json_data = get_cfbd_game_win_probability_data( + api_key=cfbd_key, + game_id=401525535 + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_game_win_probability_data( + api_key=cfbd_key, + game_id=400941851, + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get win probablility data for a 2017 game between + # the University of Cincinnati and UConn (game ID #400941851). + print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") + json_data = get_cfbd_game_win_probability_data( + game_id=400941851 + ) + print(json_data) + time.sleep(5) + + # Get win probablility data for a 2023 game between + # the University of Duke and the University of Louisville (game ID #401525535). + print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") + json_data = get_cfbd_game_win_probability_data( + game_id=401525535 + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_game_win_probability_data( + game_id=400941851, + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with win probability data at the play-by-play level, + or (if `return_as_dict` is set to `True`) + a dictionary object with win probability data at the play-by-play level. """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + + wp_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/metrics/wp" + + ######################################################################################################################################################################################################## + + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + # URL builder + ######################################################################################################################################################################################################## + + # Required by API + url += f"?gameId={game_id}" + + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for play in tqdm(json_data): + row_df = pd.DataFrame( + {"game_id": game_id}, + index=[0] + ) + row_df['play_id'] = play['playId'] + row_df['play_text'] = play['playText'] + row_df['home_id'] = play['homeId'] + row_df['home_team_name'] = play['home'] + row_df['away_id'] = play['awayId'] + row_df['away_team_name'] = play['away'] + row_df['spread'] = play['spread'] + row_df['home_team_has_ball'] = play['homeBall'] + row_df['home_score'] = play['homeScore'] + row_df['away_score'] = play['awayScore'] + row_df['down'] = play['down'] + row_df['distance'] = play['distance'] + row_df['home_win_probability'] = play['homeWinProb'] + row_df['play_number'] = play['playNumber'] + + wp_df = pd.concat([wp_df, row_df], ignore_index=True) + + if len(wp_df) == 0: + logging.error( + "The CFBD API accepted your inputs, " + + "but found no data within your specified input paramaters." + + " Please double check your input paramaters." + ) + else: + wp_df = wp_df.astype( + {"home_win_probability": "float"} + ) + wp_df['away_win_probability'] = 1 - wp_df['home_win_probability'] + + return wp_df def get_cfbd_pregame_win_probability_data( @@ -121,11 +2144,312 @@ def get_cfbd_pregame_win_probability_data( week: int = None, team: str = None, season_type: str = "regular", # "regular" or "postseason" - return_as_dict: bool = False): """ + Allows you to get pregame win probability data for games within a timeframe. + + Parameters + ---------- + `api_key` (str, optional): + Semi-optional argument. + If `api_key` is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + If `api_key` is not null, this function will automatically assume that the + inputted `api_key` is a valid CFBD API key. + + `api_key_dir` (str, optional): + Optional argument. + If `api_key` is set to am empty string, this variable is ignored. + If `api_key_dir` is null, and `api_key` is null, + this function will try to find a CFBD API key file in this user's home directory. + If `api_key_dir` is set to a string, and `api_key` is null, + this function will assume that `api_key_dir` is a directory, + and will try to find a CFBD API key file in that directory. + + `season` (int, optional): + Semi-optional argument. + Specifies the season you want pregame win probability data. + + `week` (int, optional): + Optional argument. + If `week` is set to an integer, this function will attempt + to load CFB game data from games in that season, and in that week. + + `team` (str, optional): + Semi-ptional argument. + If you only want pregame win probability data for a specific team, + set `team` to the name of the team you want pregame win probability data from. + + `season_type` (str, semi-optional): + Semi-optional argument. + By defualt, this will be set to "regular", for the CFB regular season. + If you want CFB game information for non-regular season games, + set `season_type` to "postseason". + If `season_type` is set to anything but "regular" or "postseason", + a `ValueError()` will be raised. + + `return_as_dict` (bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandas `DataFrame` object, + set `return_as_dict` to `True`. + + Usage + ---------- + ``` + import time + + from cfbd_json_py.metrics import get_cfbd_pregame_win_probability_data + + + cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get pregame win probabilities for games in the 2023 CFB season. + print("Get pregame win probabilities for games in the 2023 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2023 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games in week 10 of the 2021 CFB season. + print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. + print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for postseason games in the 2020 CFB season. + print("Get pregame win probabilities for postseason games in the 2020 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2023, + week=10, + return_as_dict=True + ) + print(json_data) + + else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get pregame win probabilities for games in the 2023 CFB season. + print("Get pregame win probabilities for games in the 2023 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + season=2023 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games in week 10 of the 2021 CFB season. + print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. + print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") + json_data = get_cfbd_pregame_win_probability_data( + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for postseason games in the 2020 CFB season. + print("Get pregame win probabilities for postseason games in the 2020 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_pregame_win_probability_data( + season=2023, + week=10, + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with pregame win probability data, + or (if `return_as_dict` is set to `True`) + a dictionary object with a pregame win probability data. """ - raise NotImplementedError( - 'This function has yet to be implemented by this version.' - ) + now = datetime.now() + wp_df = pd.DataFrame() + row_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/metrics/wp/pregame" + + ######################################################################################################################################################################################################## + + if api_key != None: + real_api_key = api_key + del api_key + else: + real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + + if real_api_key == "tigersAreAwsome": + raise ValueError( + "You actually need to change `cfbd_key` to your CFBD API key.") + elif "Bearer " in real_api_key: + pass + elif "Bearer" in real_api_key: + real_api_key = real_api_key.replace('Bearer', 'Bearer ') + else: + real_api_key = "Bearer " + real_api_key + + if season == None: + pass + elif season > now.year: + raise ValueError(f"`season` cannot be greater than {season}.") + elif season < 1869: + raise ValueError(f"`season` cannot be less than 1869.") + + if week != None and week < 0: + raise ValueError( + "`week` must be an integer greater than 0." + ) + + if season_type != "regular" and season_type != "postseason": + raise ValueError( + "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + + + + # URL builder + ######################################################################################################################################################################################################## + url_elements = 0 + + if season != None and url_elements == 0: + url += f"?year={season}" + url_elements += 1 + elif season != None: + url += f"&year={season}" + url_elements += 1 + + if week != None and url_elements == 0: + url += f"?week={week}" + url_elements += 1 + elif week != None: + url += f"&week={week}" + url_elements += 1 + + if team != None and url_elements == 0: + url += f"?team={team}" + url_elements += 1 + elif team != None: + url += f"&team={team}" + url_elements += 1 + + if season_type != None and url_elements == 0: + url += f"?seasonType={season_type}" + url_elements += 1 + elif season_type != None: + url += f"&seasonType={season_type}" + url_elements += 1 + + + headers = { + 'Authorization': f'{real_api_key}', + 'accept': 'application/json' + } + + response = requests.get(url, headers=headers) + + if response.status_code == 200: + pass + elif response.status_code == 401: + raise ConnectionRefusedError( + f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + ) + else: + raise ConnectionError( + f'Could not connect.\nHTTP Status code {response.status_code}' + ) + + json_data = response.json() + + if return_as_dict == True: + return json_data + + for game in tqdm(json_data): + g_season = game['season'] + row_df = pd.DataFrame( + {"season":g_season}, + index=[0] + ) + row_df['week'] = game['week'] + row_df['season_type'] = game['seasonType'] + row_df['game_id'] = game['gameId'] + row_df['home_team_name'] = game['homeTeam'] + row_df['away_team_name'] = game['awayTeam'] + row_df['spread'] = game['spread'] + row_df['home_win_probability'] = game['homeWinProb'] + + wp_df = pd.concat([wp_df,row_df],ignore_index=True) + del row_df + del g_season + + if len(wp_df) == 0: + logging.error( + "The CFBD API accepted your inputs, " + + "but found no data within your specified input paramaters." + + " Please double check your input paramaters." + ) + else: + wp_df = wp_df.astype( + {"home_win_probability": "float"} + ) + wp_df['away_win_probability'] = 1 - wp_df['home_win_probability'] + + return wp_df \ No newline at end of file diff --git a/cfbd_json_py/players.py b/cfbd_json_py/players.py index 08ed86a..7807ea5 100644 --- a/cfbd_json_py/players.py +++ b/cfbd_json_py/players.py @@ -1,5 +1,5 @@ # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 10/06/2023 07:53 PM EDT +# Last Updated Date: 10/26/2023 07:45 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: players.py # Purpose: Houses functions pertaining to CFB player data within the CFBD API. @@ -13,7 +13,6 @@ def cfbd_player_search( position: str = None, team: str = None, season: int = None, - return_as_dict: bool = False): """ diff --git a/cfbd_json_py/utls.py b/cfbd_json_py/utls.py index 32f421d..cd6ef2a 100644 --- a/cfbd_json_py/utls.py +++ b/cfbd_json_py/utls.py @@ -13,6 +13,8 @@ def reverse_cipher_encrypt(plain_text_str: str): """ + NOT INTENDED TO BE CALLED BY THE USER! + Implements a reverse cipher encription to a plain text string. Parameters @@ -37,6 +39,8 @@ def reverse_cipher_encrypt(plain_text_str: str): def reverse_cipher_decrypt(encrypted_text_str: str): """ + NOT INTENDED TO BE CALLED BY THE USER! + Decrypts a string that was presumed to be encrypted by a reverse cipher encryption. Parameters @@ -64,6 +68,12 @@ def reverse_cipher_decrypt(encrypted_text_str: str): def get_cfbd_api_token(api_key_dir: str = None): """ + NOT INTENDED TO BE CALLED BY THE USER! + + If you've already set the API key using + `cfbd_json_py.utls.set_cfbd_api_token()`, + you don't need to use this function. + If the CFBD API key exists in the environment, or is in a file, this function retrives the CFBD API key, and returns it as a string. diff --git a/docs/cfbd_json_py.html b/docs/cfbd_json_py.html index fecaa73..65903b7 100644 --- a/docs/cfbd_json_py.html +++ b/docs/cfbd_json_py.html @@ -21,6 +21,13 @@ +
This is the official docs page for the cfbd_json_py
python package.
To the left of this page are various endpoints for this python package.
+ +cfbd_json_py.betting
:
+Holds functions for betting lines and betting data from the CFBD API.cfbd_json_py.coaches
:
+Holds functions for you to get coaching data (past and present).cfbd_json_py.conferences
:
+Holds functions for you to get information for CFB confrences.cfbd_json_py.draft
:
+Holds functions for you to get NFL draft information/data for
+various players in the CFBD APIcfbd_json_py.drives
:
+Holds functions for you to get data for offensive and/or defensive drives
+within the CFBD API.cfbd_json_py.games
:
+Holds functions for you to get various datapoints pertaining to
+actual CFB games within the CFBD API.cfbd_json_py.metrics
:
+Holds functions to allow you to calculate or retrive various advanced metrics
+from the CFBD API.cfbd_json_py.players
:
+Holds functions for you to get various
+data endpoints related to player stats,
+player information, and player data.cfbd_json_py.plays
:
+Holds functions for play-by-play (PBP) data for CFB games,
+as well as a way to calculate stats from PBP data.cfbd_json_py.rankings
:
+Holds functions for various CFB team ranking polls,
+and their results.cfbd_json_py.ratings
:
+Holds functions to allow you to get various team ratings data
+(like SP+, SRS, and Elo team ratings) from the CFBD API.cfbd_json_py.recruiting
:
+Holds functions for you to access CFB recruting data and information,
+as well as team and player ratings for recruiting.cfbd_json_py.stats
:
+Holds functions for you to get various team stats from the CFBD API.cfbd_json_py.teams
:
+Holds functions for you to get team information and data,
+as well as head-to-head records and matchup history.cfbd_json_py.utls
:
+Various utilities that can be used from this package.
+Outside of cfbd_json_py.utls.set_cfbd_api_token()
,
+you don't need to call any of these functions directly.cfbd_json_py.venues
:
+Holds functions for you to get information on
+various venues/stadiums within the college football world.If you have a CFBD API key, you have three ways to set it for this python package to use:
+ +CFBD_API_KEY
.
+cfbd_json_py
will first look for your environment,
+if you don't declare the API key as a string variable,
+when calling any function in this python package that uses a CFBD API call.CFBD_API_KEY
.
+Again, this package will automatically know where to look,
+if you've set your API key in the environment cfbd_json_py.utls.set_cfbd_api_token()
to store the API key in an encrypted file on your machine.
+"TigersAreAwesome"
with your API key:from cfbd_api_key.utls import set_cfbd_api_token
+
+cfbd_api_key = "TigersAreAwesome" # replace this with your actual API key
+set_cfbd_api_token(api_key=cfbd_api_key)
+
+
+++ +NOTE: In a future version, + there will be an executable application seperate from this package + for Windows, Mac, and Linux users to effectively do the same thing + as the above code block, but with a graphical user interface (GUI).
+
If you want to see how to use this python package after setting up your API key, +click on one of the submodules on the left +to view the various functions within each submodule. +Each function has a tutorial script on the various ways you can call that function.
+ +1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/06/2023 08:06 PM EDT - 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) - 4# File Name: __init__.py - 5# Purpose: Allows for the python package to function, - 6# by allowing you to to access functions within - 7# this package. - 8#################################################################################################### - 9 -10# Generated Functions: -11from cfbd_json_py._early_access import * -12 -13 -14# Fully Implemented Functions: -15from cfbd_json_py.betting import * -16from cfbd_json_py.coaches import * -17from cfbd_json_py.conferences import * -18from cfbd_json_py.draft import * -19from cfbd_json_py.drives import * -20from cfbd_json_py.games import * -21from cfbd_json_py.metrics import * -22from cfbd_json_py.players import * -23from cfbd_json_py.plays import * -24from cfbd_json_py.rankings import * -25from cfbd_json_py.ratings import * -26from cfbd_json_py.recruiting import * -27from cfbd_json_py.stats import * -28from cfbd_json_py.teams import * -29from cfbd_json_py.venues import * -30 -31# Utils -32 -33from cfbd_json_py.utls import * +diff --git a/docs/cfbd_json_py/betting.html b/docs/cfbd_json_py/betting.html index 66ed8d7..c8fa133 100644 --- a/docs/cfbd_json_py/betting.html +++ b/docs/cfbd_json_py/betting.html @@ -55,408 +55,406 @@1# Creation Date: 08/30/2023 01:13 EDT + 2# Last Updated Date: 10/20/2023 02:33 PM EDT + 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) + 4# File Name: __init__.py + 5# Purpose: Allows for the python package to function, + 6# by allowing you to to access functions within + 7# this package. + 8#################################################################################################### + 9""" + 10# Welcome! + 11This is the official docs page for the `cfbd_json_py` python package. + 12 + 13To the left of this page are various endpoints for this python package. + 14- `cfbd_json_py.betting`: + 15 Holds functions for betting lines and betting data from the CFBD API. + 16- `cfbd_json_py.coaches`: + 17 Holds functions for you to get coaching data (past and present). + 18- `cfbd_json_py.conferences`: + 19 Holds functions for you to get information for CFB confrences. + 20- `cfbd_json_py.draft`: + 21 Holds functions for you to get NFL draft information/data for + 22 various players in the CFBD API + 23- `cfbd_json_py.drives`: + 24 Holds functions for you to get data for offensive and/or defensive drives + 25 within the CFBD API. + 26- `cfbd_json_py.games`: + 27 Holds functions for you to get various datapoints pertaining to + 28 actual CFB games within the CFBD API. + 29- `cfbd_json_py.metrics`: + 30 Holds functions to allow you to calculate or retrive various advanced metrics + 31 from the CFBD API. + 32- `cfbd_json_py.players`: + 33 Holds functions for you to get various + 34 data endpoints related to player stats, + 35 player information, and player data. + 36- `cfbd_json_py.plays`: + 37 Holds functions for play-by-play (PBP) data for CFB games, + 38 as well as a way to calculate stats from PBP data. + 39- `cfbd_json_py.rankings`: + 40 Holds functions for various CFB team ranking polls, + 41 and their results. + 42- `cfbd_json_py.ratings`: + 43 Holds functions to allow you to get various team ratings data + 44 (like SP+, SRS, and Elo team ratings) from the CFBD API. + 45- `cfbd_json_py.recruiting`: + 46 Holds functions for you to access CFB recruting data and information, + 47 as well as team and player ratings for recruiting. + 48- `cfbd_json_py.stats`: + 49 Holds functions for you to get various team stats from the CFBD API. + 50- `cfbd_json_py.teams`: + 51 Holds functions for you to get team information and data, + 52 as well as head-to-head records and matchup history. + 53- `cfbd_json_py.utls`: + 54 Various utilities that can be used from this package. + 55 Outside of `cfbd_json_py.utls.set_cfbd_api_token()`, + 56 you don't need to call any of these functions directly. + 57- `cfbd_json_py.venues`: + 58 Holds functions for you to get information on + 59 various venues/stadiums within the college football world. + 60 + 61# Basic Setup + 62 + 63If you have a CFBD API key, you have three ways to set it for this python package to use: + 641. Declare the API key as a string variable in a python script (not reccomended, extreme security risk). + 652. Declare the API key in your environment as `CFBD_API_KEY`. + 66 - `cfbd_json_py` will first look for your environment, + 67 if you don't declare the API key as a string variable, + 68 when calling any function in this python package that uses a CFBD API call. + 69 - If you're using GitHub Actions with this package, + 70 just set a repository secret with the name `CFBD_API_KEY`. + 71 Again, this package will automatically know where to look, + 72 if you've set your API key in the environment + 733. Use `cfbd_json_py.utls.set_cfbd_api_token()` to store the API key in an encrypted file on your machine. + 74 - To set the API key for this package with this function, + 75 run this code in a python script, + 76 replacing `"TigersAreAwesome"` with your API key: + 77 + 78``` + 79from cfbd_api_key.utls import set_cfbd_api_token + 80 + 81cfbd_api_key = "TigersAreAwesome" # replace this with your actual API key + 82set_cfbd_api_token(api_key=cfbd_api_key) + 83``` + 84 + 85> **NOTE:** *In a future version, + 86 there will be an executable application seperate from this package + 87 for Windows, Mac, and Linux users to effectively do the same thing + 88 as the above code block, but with a graphical user interface (GUI).* + 89 + 90If you want to see how to use this python package after setting up your API key, + 91click on one of the submodules on the left + 92to view the various functions within each submodule. + 93Each function has a tutorial script on the various ways you can call that function. + 94 + 95# Other Notes + 96- If you want to see all CFBD API endpoints that are currently supported, + 97 [click here](https://api.collegefootballdata.com/api/docs/?url=/api-docs.json#/) + 98 to access the current Swagger docs for the entire API. + 99- If you want to see the source code for this package, +100 [click here](https://github.com/armstjc/cfbd-json-py) to see the current stable build of this python package on GitHub. +101- If you want to see the active changelog for this python package, +102 [click here]() to view the changelog of this python package on GitHub. +103 +104""" +105 +106# Generated Functions: +107from cfbd_json_py._early_access import * +108 +109 +110# Fully Implemented Functions: +111from cfbd_json_py.betting import * +112from cfbd_json_py.coaches import * +113from cfbd_json_py.conferences import * +114from cfbd_json_py.draft import * +115from cfbd_json_py.drives import * +116from cfbd_json_py.games import * +117from cfbd_json_py.metrics import * +118from cfbd_json_py.players import * +119from cfbd_json_py.plays import * +120from cfbd_json_py.rankings import * +121from cfbd_json_py.ratings import * +122from cfbd_json_py.recruiting import * +123from cfbd_json_py.stats import * +124from cfbd_json_py.teams import * +125from cfbd_json_py.venues import * +126 +127# Utils +128 +129from cfbd_json_py.utls import *
@@ -472,391 +470,391 @@1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/06/2023 07:52 PM EDT + 2# Last Updated Date: 10/23/2023 04:09 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: betting.py 5# Purpose: Houses functions pertaining to betting data within the CFBD API. 6#################################################################################################### 7 - 8import time - 9import warnings - 10# from datetime import datetime - 11 - 12import pandas as pd - 13import requests - 14from tqdm import tqdm + 8import warnings + 9 + 10import pandas as pd + 11import requests + 12from tqdm import tqdm + 13 + 14from cfbd_json_py.utls import get_cfbd_api_token 15 - 16from cfbd_json_py.utls import get_cfbd_api_token - 17 - 18 - 19def get_cfbd_betting_lines( - 20 season: int, - 21 api_key: str = None, - 22 api_key_dir: str = None, - 23 game_id: int = None, - 24 week: int = None, - 25 season_type: str = "regular", # "regular" or "postseason" - 26 team: str = None, - 27 home_team: str = None, - 28 away_team: str = None, - 29 conference_abv: str = None, - 30 # cache_data: bool = False, - 31 # cache_dir: str = None, - 32 return_as_dict: bool = False): - 33 """ - 34 Retrives betting information from the CFBD API for a given season, - 35 or you could only get betting information for a single game. - 36 - 37 Parameters - 38 ---------- - 39 - 40 `season` (int, mandatory): - 41 The season you want to retrive betting information from. - 42 - 43 `api_key` (str, optional): - 44 Semi-optional argument. - 45 If `api_key` is null, this function will attempt to load a CFBD API key - 46 from the python environment, or from a file on this computer. - 47 If `api_key` is not null, this function will automatically assume that the - 48 inputted `api_key` is a valid CFBD API key. - 49 - 50 `api_key_dir` (str, optional): - 51 Optional argument. - 52 If `api_key` is set to a string non-empty string, this variable is ignored. - 53 If `api_key_dir` is null, and `api_key` is null, - 54 this function will try to find a CFBD API key file in this user's home directory. - 55 If `api_key_dir` is set to a string, and `api_key` is null, - 56 this function will assume that `api_key_dir` is a directory, - 57 and will try to find a CFBD API key file in that directory. - 58 - 59 `game_id` (int, optional): - 60 Optional argument. - 61 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get - 62 all betting informaiton for that game ID. - 63 - 64 `week` (int, optional): - 65 Optional argument. - 66 If `week` is set to an integer, this function will attempt - 67 to load betting data from games in that season, and that week. - 68 - 69 `season_type` (str, semi-optional): - 70 Semi-optional argument. - 71 By defualt, this will be set to "regular", for the CFB regular season. - 72 If you want postseason betting data, set `season_type` to "postseason". - 73 If `season_type` is set to anything but "regular" or "postseason", - 74 a `ValueError()` will be raised. - 75 - 76 `team` (str, optional): - 77 Optional argument. - 78 If you only want betting information for a team, - 79 regardless if they are the home/away team, - 80 set `team` to the name of the team you want game-level betting data from. - 81 - 82 `home_team` (str, optional): - 83 Optional argument. - 84 If you only want betting information for a team, - 85 where that team was the home team in this season, - 86 set `home_team` to the name of the team you want game-level betting data from. - 87 - 88 `away_team` (str, optional): - 89 Optional argument. - 90 If you only want betting information for a team, - 91 where that team was the away team in this season, - 92 set `away_team` to the name of the team you want game-level betting data from. - 93 - 94 `conference_abv` (str, optional): - 95 Optional argument. - 96 If you only want betting information from games - 97 involving teams a specific confrence, - 98 set `conference_abv` to the abbreviation - 99 of the conference you want betting informaiton from. -100 -101 `return_as_dict` (bool, semi-optional): -102 Semi-optional argument. -103 If you want this function to return the data as a dictionary (read: JSON object), -104 instead of a pandas `DataFrame` object, -105 set `return_as_dict` to `True`. -106 -107 Usage -108 ---------- -109 ``` -110 import time + 16 + 17def get_cfbd_betting_lines( + 18 season: int, + 19 api_key: str = None, + 20 api_key_dir: str = None, + 21 game_id: int = None, + 22 week: int = None, + 23 season_type: str = "regular", # "regular" or "postseason" + 24 team: str = None, + 25 home_team: str = None, + 26 away_team: str = None, + 27 conference_abv: str = None, + 28 # cache_data: bool = False, + 29 # cache_dir: str = None, + 30 return_as_dict: bool = False): + 31 """ + 32 Retrives betting information from the CFBD API for a given season, + 33 or you could only get betting information for a single game. + 34 + 35 Parameters + 36 ---------- + 37 + 38 `season` (int, mandatory): + 39 The season you want to retrive betting information from. + 40 + 41 `api_key` (str, optional): + 42 Semi-optional argument. + 43 If `api_key` is null, this function will attempt to load a CFBD API key + 44 from the python environment, or from a file on this computer. + 45 If `api_key` is not null, this function will automatically assume that the + 46 inputted `api_key` is a valid CFBD API key. + 47 + 48 `api_key_dir` (str, optional): + 49 Optional argument. + 50 If `api_key` is set to am empty string, this variable is ignored. + 51 If `api_key_dir` is null, and `api_key` is null, + 52 this function will try to find a CFBD API key file in this user's home directory. + 53 If `api_key_dir` is set to a string, and `api_key` is null, + 54 this function will assume that `api_key_dir` is a directory, + 55 and will try to find a CFBD API key file in that directory. + 56 + 57 `game_id` (int, optional): + 58 Optional argument. + 59 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get + 60 all betting informaiton for that game ID. + 61 + 62 `week` (int, optional): + 63 Optional argument. + 64 If `week` is set to an integer, this function will attempt + 65 to load betting data from games in that season, and that week. + 66 + 67 `season_type` (str, semi-optional): + 68 Semi-optional argument. + 69 By defualt, this will be set to "regular", for the CFB regular season. + 70 If you want postseason betting data, set `season_type` to "postseason". + 71 If `season_type` is set to anything but "regular" or "postseason", + 72 a `ValueError()` will be raised. + 73 + 74 `team` (str, optional): + 75 Optional argument. + 76 If you only want betting information for a team, + 77 regardless if they are the home/away team, + 78 set `team` to the name of the team you want game-level betting data from. + 79 + 80 `home_team` (str, optional): + 81 Optional argument. + 82 If you only want betting information for a team, + 83 where that team was the home team in this season, + 84 set `home_team` to the name of the team you want game-level betting data from. + 85 + 86 `away_team` (str, optional): + 87 Optional argument. + 88 If you only want betting information for a team, + 89 where that team was the away team in this season, + 90 set `away_team` to the name of the team you want game-level betting data from. + 91 + 92 `conference_abv` (str, optional): + 93 Optional argument. + 94 If you only want betting information from games + 95 involving teams a specific confrence, + 96 set `conference_abv` to the abbreviation + 97 of the conference you want betting informaiton from. + 98 + 99 `return_as_dict` (bool, semi-optional): +100 Semi-optional argument. +101 If you want this function to return the data as a dictionary (read: JSON object), +102 instead of a pandas `DataFrame` object, +103 set `return_as_dict` to `True`. +104 +105 Usage +106 ---------- +107 ``` +108 import time +109 +110 from cfbd_json_py.betting import get_cfbd_betting_lines 111 -112 from cfbd_json_py.betting import get_cfbd_betting_lines +112 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. 113 -114 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -115 -116 if cfbd_key != "tigersAreAwsome": -117 print("Using the user's API key declared in this script for this example.") -118 -119 # Gets all available betting info for the 2020 CFB season. -120 print("Gets all available betting info for the 2020 CFB season.") -121 json_data = get_cfbd_betting_lines( -122 api_key=cfbd_key, -123 season=2020 -124 ) -125 print(json_data) -126 time.sleep(5) -127 -128 # Gets all available betting info for the 2020 CFB season, in week 2. -129 print("Gets all available betting info for the 2020 CFB season, in week 2.") -130 json_data = get_cfbd_betting_lines( -131 api_key=cfbd_key, -132 season=2020, -133 week=2 -134 ) -135 print(json_data) -136 time.sleep(5) -137 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). -138 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") -139 json_data = get_cfbd_betting_lines( -140 api_key=cfbd_key, -141 season=2020, -142 season_type="postseason" -143 ) -144 print(json_data) -145 time.sleep(5) -146 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. -147 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") -148 json_data = get_cfbd_betting_lines( -149 api_key=cfbd_key, -150 season=2020, -151 team="Cincinnati" -152 ) -153 print(json_data) -154 time.sleep(5) -155 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. -156 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") -157 json_data = get_cfbd_betting_lines( -158 api_key=cfbd_key, -159 season=2020, -160 home_team="Ohio" -161 ) -162 print(json_data) -163 time.sleep(5) -164 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. -165 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") -166 json_data = get_cfbd_betting_lines( -167 api_key=cfbd_key, -168 season=2020, -169 away_team="Ohio State" -170 ) -171 -172 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. -173 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") -174 json_data = get_cfbd_betting_lines( -175 api_key=cfbd_key, -176 season=2020, -177 conference_abv="ACC" -178 ) -179 print(json_data) -180 time.sleep(5) -181 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -182 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -183 json_data = get_cfbd_betting_lines( -184 api_key=cfbd_key, -185 season=2020, -186 return_as_dict=True -187 ) -188 print(json_data) -189 -190 else: -191 # Alternatively, if the CFBD API key exists in this python environment, -192 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -193 # you could just call these functions directly, without setting the API key -194 # in the script. -195 print("Using the user's API key suposedly loaded into this python environment for this example.") -196 -197 # Gets all available betting info for the 2020 CFB season. -198 print("Gets all available betting info for the 2020 CFB season.") -199 json_data = get_cfbd_betting_lines( -200 season=2020 -201 ) -202 print(json_data) -203 time.sleep(5) -204 # Gets all available betting info for the 2020 CFB season, in week 2. -205 print("Gets all available betting info for the 2020 CFB season, in week 2.") -206 json_data = get_cfbd_betting_lines( -207 season=2020, -208 week=2 -209 ) -210 print(json_data) -211 time.sleep(5) -212 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). -213 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") -214 json_data = get_cfbd_betting_lines( -215 season=2020, -216 season_type="postseason" -217 ) -218 print(json_data) -219 time.sleep(5) -220 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. -221 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") -222 json_data = get_cfbd_betting_lines( -223 season=2020, -224 team="Cincinnati" -225 ) -226 print(json_data) -227 time.sleep(5) -228 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. -229 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") -230 json_data = get_cfbd_betting_lines( -231 season=2020, -232 home_team="Ohio" -233 ) -234 print(json_data) -235 time.sleep(5) -236 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. -237 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") -238 json_data = get_cfbd_betting_lines( -239 -240 season=2020, -241 away_team="Ohio State" -242 ) -243 -244 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. -245 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") -246 json_data = get_cfbd_betting_lines( -247 season=2020, -248 conference_abv="ACC" -249 ) -250 print(json_data) -251 time.sleep(5) -252 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -253 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -254 json_data = get_cfbd_betting_lines( -255 season=2020, -256 return_as_dict=True -257 ) -258 print(json_data) -259 -260 -261 ``` -262 Returns -263 ---------- -264 A pandas `DataFrame` object with college football betting data, -265 or (if `return_as_dict` is set to `True`) -266 a dictionary object with college football betting data. -267 """ -268 -269 # now = datetime.now() -270 betting_df = pd.DataFrame() -271 row_df = pd.DataFrame() -272 url = "https://api.collegefootballdata.com/lines?" -273 -274 # Input validation -275 ######################################################################################################################################################################################################## -276 if game_id != None and season != None: -277 warnings.warn( -278 "If you are getting betting information for a single game, only set `game_id` to the game ID, and leave `season` as `NULL`.") -279 -280 if season_type == "regular" or season_type == "postseason": -281 url += f"seasonType={season_type}" -282 else: -283 raise ValueError( -284 "`season_type` must be set to either \"regular\" or \"postseason\".") -285 -286 if (game_id == None) and (season == None) and (week != None): -287 raise ValueError( -288 "When setting a value for `week`, `season` cannot be null.") -289 -290 # if cache_data == True and ((team != None) or (home_team != None) or (away_team != None) or (conference_abv != None)): -291 # logging.warning( -292 # "When caching data is enabled for this function, the following inputs are ignored when making the API call:\n-`team`\n-`home_team`\n-`away_team`\n-`conference_abv`") -293 -294 if api_key != None: -295 real_api_key = api_key -296 del api_key -297 else: -298 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -299 -300 if real_api_key == "tigersAreAwsome": -301 raise ValueError( -302 "You actually need to change `cfbd_key` to your CFBD API key.") -303 elif "Bearer " in real_api_key: -304 pass -305 elif "Bearer" in real_api_key: -306 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -307 else: -308 real_api_key = "Bearer " + real_api_key -309 -310 # URL builder -311 ######################################################################################################################################################################################################## -312 -313 if game_id != None: -314 url += f"&gameId={game_id}" -315 -316 if season != None: -317 url += f"&year={season}" -318 -319 if week != None: -320 url += f"&week={week}" -321 -322 if team != None: -323 url += f"&team={team}" -324 -325 if home_team != None: -326 url += f"&home={home_team}" -327 -328 if away_team != None: -329 url += f"&away={away_team}" -330 -331 if conference_abv != None: -332 url += f"&conference={conference_abv}" -333 -334 headers = { -335 'Authorization': f'{real_api_key}', -336 'accept': 'application/json' -337 } -338 -339 response = requests.get(url, headers=headers) -340 time.sleep(0.1) -341 -342 if response.status_code == 200: -343 pass -344 elif response.status_code == 401: -345 raise ConnectionRefusedError( -346 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -347 ) -348 else: -349 raise ConnectionError( -350 f'Could not connect.\nHTTP Status code {response.status_code}' -351 ) +114 if cfbd_key != "tigersAreAwsome": +115 print("Using the user's API key declared in this script for this example.") +116 +117 # Gets all available betting info for the 2020 CFB season. +118 print("Gets all available betting info for the 2020 CFB season.") +119 json_data = get_cfbd_betting_lines( +120 api_key=cfbd_key, +121 season=2020 +122 ) +123 print(json_data) +124 time.sleep(5) +125 +126 # Gets all available betting info for the 2020 CFB season, in week 2. +127 print("Gets all available betting info for the 2020 CFB season, in week 2.") +128 json_data = get_cfbd_betting_lines( +129 api_key=cfbd_key, +130 season=2020, +131 week=2 +132 ) +133 print(json_data) +134 time.sleep(5) +135 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). +136 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") +137 json_data = get_cfbd_betting_lines( +138 api_key=cfbd_key, +139 season=2020, +140 season_type="postseason" +141 ) +142 print(json_data) +143 time.sleep(5) +144 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. +145 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") +146 json_data = get_cfbd_betting_lines( +147 api_key=cfbd_key, +148 season=2020, +149 team="Cincinnati" +150 ) +151 print(json_data) +152 time.sleep(5) +153 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. +154 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") +155 json_data = get_cfbd_betting_lines( +156 api_key=cfbd_key, +157 season=2020, +158 home_team="Ohio" +159 ) +160 print(json_data) +161 time.sleep(5) +162 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. +163 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") +164 json_data = get_cfbd_betting_lines( +165 api_key=cfbd_key, +166 season=2020, +167 away_team="Ohio State" +168 ) +169 +170 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. +171 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") +172 json_data = get_cfbd_betting_lines( +173 api_key=cfbd_key, +174 season=2020, +175 conference_abv="ACC" +176 ) +177 print(json_data) +178 time.sleep(5) +179 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +180 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +181 json_data = get_cfbd_betting_lines( +182 api_key=cfbd_key, +183 season=2020, +184 return_as_dict=True +185 ) +186 print(json_data) +187 +188 else: +189 # Alternatively, if the CFBD API key exists in this python environment, +190 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +191 # you could just call these functions directly, without setting the API key +192 # in the script. +193 print("Using the user's API key suposedly loaded into this python environment for this example.") +194 +195 # Gets all available betting info for the 2020 CFB season. +196 print("Gets all available betting info for the 2020 CFB season.") +197 json_data = get_cfbd_betting_lines( +198 season=2020 +199 ) +200 print(json_data) +201 time.sleep(5) +202 # Gets all available betting info for the 2020 CFB season, in week 2. +203 print("Gets all available betting info for the 2020 CFB season, in week 2.") +204 json_data = get_cfbd_betting_lines( +205 season=2020, +206 week=2 +207 ) +208 print(json_data) +209 time.sleep(5) +210 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). +211 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") +212 json_data = get_cfbd_betting_lines( +213 season=2020, +214 season_type="postseason" +215 ) +216 print(json_data) +217 time.sleep(5) +218 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. +219 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") +220 json_data = get_cfbd_betting_lines( +221 season=2020, +222 team="Cincinnati" +223 ) +224 print(json_data) +225 time.sleep(5) +226 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. +227 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") +228 json_data = get_cfbd_betting_lines( +229 season=2020, +230 home_team="Ohio" +231 ) +232 print(json_data) +233 time.sleep(5) +234 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. +235 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") +236 json_data = get_cfbd_betting_lines( +237 +238 season=2020, +239 away_team="Ohio State" +240 ) +241 +242 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. +243 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") +244 json_data = get_cfbd_betting_lines( +245 season=2020, +246 conference_abv="ACC" +247 ) +248 print(json_data) +249 time.sleep(5) +250 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +251 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +252 json_data = get_cfbd_betting_lines( +253 season=2020, +254 return_as_dict=True +255 ) +256 print(json_data) +257 +258 +259 ``` +260 Returns +261 ---------- +262 A pandas `DataFrame` object with college football betting data, +263 or (if `return_as_dict` is set to `True`) +264 a dictionary object with college football betting data. +265 """ +266 +267 # now = datetime.now() +268 betting_df = pd.DataFrame() +269 row_df = pd.DataFrame() +270 url = "https://api.collegefootballdata.com/lines?" +271 +272 # Input validation +273 ######################################################################################################################################################################################################## +274 if game_id != None and season != None: +275 warnings.warn( +276 "If you are getting betting information for a single game, only set `game_id` to the game ID, and leave `season` as `NULL`.") +277 +278 if season_type == "regular" or season_type == "postseason": +279 url += f"seasonType={season_type}" +280 else: +281 raise ValueError( +282 "`season_type` must be set to either \"regular\" or \"postseason\".") +283 +284 if (game_id == None) and (season == None) and (week != None): +285 raise ValueError( +286 "When setting a value for `week`, `season` cannot be null.") +287 +288 # if cache_data == True and ((team != None) or (home_team != None) or (away_team != None) or (conference_abv != None)): +289 # logging.warning( +290 # "When caching data is enabled for this function, the following inputs are ignored when making the API call:\n-`team`\n-`home_team`\n-`away_team`\n-`conference_abv`") +291 +292 if api_key != None: +293 real_api_key = api_key +294 del api_key +295 else: +296 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +297 +298 if real_api_key == "tigersAreAwsome": +299 raise ValueError( +300 "You actually need to change `cfbd_key` to your CFBD API key.") +301 elif "Bearer " in real_api_key: +302 pass +303 elif "Bearer" in real_api_key: +304 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +305 else: +306 real_api_key = "Bearer " + real_api_key +307 +308 # URL builder +309 ######################################################################################################################################################################################################## +310 +311 if game_id != None: +312 url += f"&gameId={game_id}" +313 +314 if season != None: +315 url += f"&year={season}" +316 +317 if week != None: +318 url += f"&week={week}" +319 +320 if team != None: +321 url += f"&team={team}" +322 +323 if home_team != None: +324 url += f"&home={home_team}" +325 +326 if away_team != None: +327 url += f"&away={away_team}" +328 +329 if conference_abv != None: +330 url += f"&conference={conference_abv}" +331 +332 headers = { +333 'Authorization': f'{real_api_key}', +334 'accept': 'application/json' +335 } +336 +337 response = requests.get(url, headers=headers) +338 +339 +340 if response.status_code == 200: +341 pass +342 elif response.status_code == 401: +343 raise ConnectionRefusedError( +344 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +345 ) +346 else: +347 raise ConnectionError( +348 f'Could not connect.\nHTTP Status code {response.status_code}' +349 ) +350 +351 json_data = response.json() 352 -353 json_data = response.json() -354 -355 if return_as_dict == True: -356 return json_data -357 -358 for game in tqdm(json_data): -359 gameId = game['id'] -360 season = game['id'] -361 seasonType = game['seasonType'] -362 startDate = game['startDate'] -363 homeTeam = game['homeTeam'] -364 homeConference = game['homeConference'] -365 homeScore = game['homeScore'] -366 awayTeam = game['awayTeam'] -367 awayConference = game['awayConference'] -368 awayScore = game['awayScore'] -369 -370 for line in game['lines']: -371 row_df = pd.DataFrame( -372 { -373 "game_id": gameId, -374 "season": season, -375 "season_type": seasonType, -376 "start_date": startDate, -377 "home_team": homeTeam, -378 "home_conference": homeConference, -379 "home_score": homeScore, -380 "away_team": awayTeam, -381 "away_conference": awayConference, -382 "away_score": awayScore -383 }, -384 index=[0] -385 ) -386 -387 row_df["line_provider"] = line['provider'] -388 row_df["spread"] = line['spread'] -389 row_df["formatted_spread"] = line['formattedSpread'] -390 row_df["spread_open"] = line['spreadOpen'] -391 row_df["over_under"] = line['overUnder'] -392 row_df["over_under_open"] = line['overUnderOpen'] -393 row_df["home_moneyline"] = line['homeMoneyline'] -394 row_df["away_moneyline"] = line['awayMoneyline'] -395 -396 betting_df = pd.concat([betting_df, row_df], ignore_index=True) -397 del row_df -398 -399 del gameId, seasonType, startDate, homeTeam, \ -400 homeConference, homeScore, awayTeam, \ -401 awayConference, awayScore -402 -403 return betting_df +353 if return_as_dict == True: +354 return json_data +355 +356 for game in tqdm(json_data): +357 gameId = game['id'] +358 season = game['id'] +359 seasonType = game['seasonType'] +360 startDate = game['startDate'] +361 homeTeam = game['homeTeam'] +362 homeConference = game['homeConference'] +363 homeScore = game['homeScore'] +364 awayTeam = game['awayTeam'] +365 awayConference = game['awayConference'] +366 awayScore = game['awayScore'] +367 +368 for line in game['lines']: +369 row_df = pd.DataFrame( +370 { +371 "game_id": gameId, +372 "season": season, +373 "season_type": seasonType, +374 "start_date": startDate, +375 "home_team": homeTeam, +376 "home_conference": homeConference, +377 "home_score": homeScore, +378 "away_team": awayTeam, +379 "away_conference": awayConference, +380 "away_score": awayScore +381 }, +382 index=[0] +383 ) +384 +385 row_df["line_provider"] = line['provider'] +386 row_df["spread"] = line['spread'] +387 row_df["formatted_spread"] = line['formattedSpread'] +388 row_df["spread_open"] = line['spreadOpen'] +389 row_df["over_under"] = line['overUnder'] +390 row_df["over_under_open"] = line['overUnderOpen'] +391 row_df["home_moneyline"] = line['homeMoneyline'] +392 row_df["away_moneyline"] = line['awayMoneyline'] +393 +394 betting_df = pd.concat([betting_df, row_df], ignore_index=True) +395 del row_df +396 +397 del gameId, seasonType, startDate, homeTeam, \ +398 homeConference, homeScore, awayTeam, \ +399 awayConference, awayScore +400 +401 return betting_df
20def get_cfbd_betting_lines( - 21 season: int, - 22 api_key: str = None, - 23 api_key_dir: str = None, - 24 game_id: int = None, - 25 week: int = None, - 26 season_type: str = "regular", # "regular" or "postseason" - 27 team: str = None, - 28 home_team: str = None, - 29 away_team: str = None, - 30 conference_abv: str = None, - 31 # cache_data: bool = False, - 32 # cache_dir: str = None, - 33 return_as_dict: bool = False): - 34 """ - 35 Retrives betting information from the CFBD API for a given season, - 36 or you could only get betting information for a single game. - 37 - 38 Parameters - 39 ---------- - 40 - 41 `season` (int, mandatory): - 42 The season you want to retrive betting information from. - 43 - 44 `api_key` (str, optional): - 45 Semi-optional argument. - 46 If `api_key` is null, this function will attempt to load a CFBD API key - 47 from the python environment, or from a file on this computer. - 48 If `api_key` is not null, this function will automatically assume that the - 49 inputted `api_key` is a valid CFBD API key. - 50 - 51 `api_key_dir` (str, optional): - 52 Optional argument. - 53 If `api_key` is set to a string non-empty string, this variable is ignored. - 54 If `api_key_dir` is null, and `api_key` is null, - 55 this function will try to find a CFBD API key file in this user's home directory. - 56 If `api_key_dir` is set to a string, and `api_key` is null, - 57 this function will assume that `api_key_dir` is a directory, - 58 and will try to find a CFBD API key file in that directory. - 59 - 60 `game_id` (int, optional): - 61 Optional argument. - 62 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get - 63 all betting informaiton for that game ID. - 64 - 65 `week` (int, optional): - 66 Optional argument. - 67 If `week` is set to an integer, this function will attempt - 68 to load betting data from games in that season, and that week. - 69 - 70 `season_type` (str, semi-optional): - 71 Semi-optional argument. - 72 By defualt, this will be set to "regular", for the CFB regular season. - 73 If you want postseason betting data, set `season_type` to "postseason". - 74 If `season_type` is set to anything but "regular" or "postseason", - 75 a `ValueError()` will be raised. - 76 - 77 `team` (str, optional): - 78 Optional argument. - 79 If you only want betting information for a team, - 80 regardless if they are the home/away team, - 81 set `team` to the name of the team you want game-level betting data from. - 82 - 83 `home_team` (str, optional): - 84 Optional argument. - 85 If you only want betting information for a team, - 86 where that team was the home team in this season, - 87 set `home_team` to the name of the team you want game-level betting data from. - 88 - 89 `away_team` (str, optional): - 90 Optional argument. - 91 If you only want betting information for a team, - 92 where that team was the away team in this season, - 93 set `away_team` to the name of the team you want game-level betting data from. - 94 - 95 `conference_abv` (str, optional): - 96 Optional argument. - 97 If you only want betting information from games - 98 involving teams a specific confrence, - 99 set `conference_abv` to the abbreviation -100 of the conference you want betting informaiton from. -101 -102 `return_as_dict` (bool, semi-optional): -103 Semi-optional argument. -104 If you want this function to return the data as a dictionary (read: JSON object), -105 instead of a pandas `DataFrame` object, -106 set `return_as_dict` to `True`. -107 -108 Usage -109 ---------- -110 ``` -111 import time +@@ -877,7 +875,7 @@18def get_cfbd_betting_lines( + 19 season: int, + 20 api_key: str = None, + 21 api_key_dir: str = None, + 22 game_id: int = None, + 23 week: int = None, + 24 season_type: str = "regular", # "regular" or "postseason" + 25 team: str = None, + 26 home_team: str = None, + 27 away_team: str = None, + 28 conference_abv: str = None, + 29 # cache_data: bool = False, + 30 # cache_dir: str = None, + 31 return_as_dict: bool = False): + 32 """ + 33 Retrives betting information from the CFBD API for a given season, + 34 or you could only get betting information for a single game. + 35 + 36 Parameters + 37 ---------- + 38 + 39 `season` (int, mandatory): + 40 The season you want to retrive betting information from. + 41 + 42 `api_key` (str, optional): + 43 Semi-optional argument. + 44 If `api_key` is null, this function will attempt to load a CFBD API key + 45 from the python environment, or from a file on this computer. + 46 If `api_key` is not null, this function will automatically assume that the + 47 inputted `api_key` is a valid CFBD API key. + 48 + 49 `api_key_dir` (str, optional): + 50 Optional argument. + 51 If `api_key` is set to am empty string, this variable is ignored. + 52 If `api_key_dir` is null, and `api_key` is null, + 53 this function will try to find a CFBD API key file in this user's home directory. + 54 If `api_key_dir` is set to a string, and `api_key` is null, + 55 this function will assume that `api_key_dir` is a directory, + 56 and will try to find a CFBD API key file in that directory. + 57 + 58 `game_id` (int, optional): + 59 Optional argument. + 60 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get + 61 all betting informaiton for that game ID. + 62 + 63 `week` (int, optional): + 64 Optional argument. + 65 If `week` is set to an integer, this function will attempt + 66 to load betting data from games in that season, and that week. + 67 + 68 `season_type` (str, semi-optional): + 69 Semi-optional argument. + 70 By defualt, this will be set to "regular", for the CFB regular season. + 71 If you want postseason betting data, set `season_type` to "postseason". + 72 If `season_type` is set to anything but "regular" or "postseason", + 73 a `ValueError()` will be raised. + 74 + 75 `team` (str, optional): + 76 Optional argument. + 77 If you only want betting information for a team, + 78 regardless if they are the home/away team, + 79 set `team` to the name of the team you want game-level betting data from. + 80 + 81 `home_team` (str, optional): + 82 Optional argument. + 83 If you only want betting information for a team, + 84 where that team was the home team in this season, + 85 set `home_team` to the name of the team you want game-level betting data from. + 86 + 87 `away_team` (str, optional): + 88 Optional argument. + 89 If you only want betting information for a team, + 90 where that team was the away team in this season, + 91 set `away_team` to the name of the team you want game-level betting data from. + 92 + 93 `conference_abv` (str, optional): + 94 Optional argument. + 95 If you only want betting information from games + 96 involving teams a specific confrence, + 97 set `conference_abv` to the abbreviation + 98 of the conference you want betting informaiton from. + 99 +100 `return_as_dict` (bool, semi-optional): +101 Semi-optional argument. +102 If you want this function to return the data as a dictionary (read: JSON object), +103 instead of a pandas `DataFrame` object, +104 set `return_as_dict` to `True`. +105 +106 Usage +107 ---------- +108 ``` +109 import time +110 +111 from cfbd_json_py.betting import get_cfbd_betting_lines 112 -113 from cfbd_json_py.betting import get_cfbd_betting_lines +113 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. 114 -115 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -116 -117 if cfbd_key != "tigersAreAwsome": -118 print("Using the user's API key declared in this script for this example.") -119 -120 # Gets all available betting info for the 2020 CFB season. -121 print("Gets all available betting info for the 2020 CFB season.") -122 json_data = get_cfbd_betting_lines( -123 api_key=cfbd_key, -124 season=2020 -125 ) -126 print(json_data) -127 time.sleep(5) -128 -129 # Gets all available betting info for the 2020 CFB season, in week 2. -130 print("Gets all available betting info for the 2020 CFB season, in week 2.") -131 json_data = get_cfbd_betting_lines( -132 api_key=cfbd_key, -133 season=2020, -134 week=2 -135 ) -136 print(json_data) -137 time.sleep(5) -138 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). -139 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") -140 json_data = get_cfbd_betting_lines( -141 api_key=cfbd_key, -142 season=2020, -143 season_type="postseason" -144 ) -145 print(json_data) -146 time.sleep(5) -147 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. -148 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") -149 json_data = get_cfbd_betting_lines( -150 api_key=cfbd_key, -151 season=2020, -152 team="Cincinnati" -153 ) -154 print(json_data) -155 time.sleep(5) -156 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. -157 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") -158 json_data = get_cfbd_betting_lines( -159 api_key=cfbd_key, -160 season=2020, -161 home_team="Ohio" -162 ) -163 print(json_data) -164 time.sleep(5) -165 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. -166 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") -167 json_data = get_cfbd_betting_lines( -168 api_key=cfbd_key, -169 season=2020, -170 away_team="Ohio State" -171 ) -172 -173 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. -174 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") -175 json_data = get_cfbd_betting_lines( -176 api_key=cfbd_key, -177 season=2020, -178 conference_abv="ACC" -179 ) -180 print(json_data) -181 time.sleep(5) -182 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -183 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -184 json_data = get_cfbd_betting_lines( -185 api_key=cfbd_key, -186 season=2020, -187 return_as_dict=True -188 ) -189 print(json_data) -190 -191 else: -192 # Alternatively, if the CFBD API key exists in this python environment, -193 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -194 # you could just call these functions directly, without setting the API key -195 # in the script. -196 print("Using the user's API key suposedly loaded into this python environment for this example.") -197 -198 # Gets all available betting info for the 2020 CFB season. -199 print("Gets all available betting info for the 2020 CFB season.") -200 json_data = get_cfbd_betting_lines( -201 season=2020 -202 ) -203 print(json_data) -204 time.sleep(5) -205 # Gets all available betting info for the 2020 CFB season, in week 2. -206 print("Gets all available betting info for the 2020 CFB season, in week 2.") -207 json_data = get_cfbd_betting_lines( -208 season=2020, -209 week=2 -210 ) -211 print(json_data) -212 time.sleep(5) -213 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). -214 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") -215 json_data = get_cfbd_betting_lines( -216 season=2020, -217 season_type="postseason" -218 ) -219 print(json_data) -220 time.sleep(5) -221 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. -222 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") -223 json_data = get_cfbd_betting_lines( -224 season=2020, -225 team="Cincinnati" -226 ) -227 print(json_data) -228 time.sleep(5) -229 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. -230 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") -231 json_data = get_cfbd_betting_lines( -232 season=2020, -233 home_team="Ohio" -234 ) -235 print(json_data) -236 time.sleep(5) -237 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. -238 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") -239 json_data = get_cfbd_betting_lines( -240 -241 season=2020, -242 away_team="Ohio State" -243 ) -244 -245 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. -246 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") -247 json_data = get_cfbd_betting_lines( -248 season=2020, -249 conference_abv="ACC" -250 ) -251 print(json_data) -252 time.sleep(5) -253 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -254 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -255 json_data = get_cfbd_betting_lines( -256 season=2020, -257 return_as_dict=True -258 ) -259 print(json_data) -260 -261 -262 ``` -263 Returns -264 ---------- -265 A pandas `DataFrame` object with college football betting data, -266 or (if `return_as_dict` is set to `True`) -267 a dictionary object with college football betting data. -268 """ -269 -270 # now = datetime.now() -271 betting_df = pd.DataFrame() -272 row_df = pd.DataFrame() -273 url = "https://api.collegefootballdata.com/lines?" -274 -275 # Input validation -276 ######################################################################################################################################################################################################## -277 if game_id != None and season != None: -278 warnings.warn( -279 "If you are getting betting information for a single game, only set `game_id` to the game ID, and leave `season` as `NULL`.") -280 -281 if season_type == "regular" or season_type == "postseason": -282 url += f"seasonType={season_type}" -283 else: -284 raise ValueError( -285 "`season_type` must be set to either \"regular\" or \"postseason\".") -286 -287 if (game_id == None) and (season == None) and (week != None): -288 raise ValueError( -289 "When setting a value for `week`, `season` cannot be null.") -290 -291 # if cache_data == True and ((team != None) or (home_team != None) or (away_team != None) or (conference_abv != None)): -292 # logging.warning( -293 # "When caching data is enabled for this function, the following inputs are ignored when making the API call:\n-`team`\n-`home_team`\n-`away_team`\n-`conference_abv`") -294 -295 if api_key != None: -296 real_api_key = api_key -297 del api_key -298 else: -299 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -300 -301 if real_api_key == "tigersAreAwsome": -302 raise ValueError( -303 "You actually need to change `cfbd_key` to your CFBD API key.") -304 elif "Bearer " in real_api_key: -305 pass -306 elif "Bearer" in real_api_key: -307 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -308 else: -309 real_api_key = "Bearer " + real_api_key -310 -311 # URL builder -312 ######################################################################################################################################################################################################## -313 -314 if game_id != None: -315 url += f"&gameId={game_id}" -316 -317 if season != None: -318 url += f"&year={season}" -319 -320 if week != None: -321 url += f"&week={week}" -322 -323 if team != None: -324 url += f"&team={team}" -325 -326 if home_team != None: -327 url += f"&home={home_team}" -328 -329 if away_team != None: -330 url += f"&away={away_team}" -331 -332 if conference_abv != None: -333 url += f"&conference={conference_abv}" -334 -335 headers = { -336 'Authorization': f'{real_api_key}', -337 'accept': 'application/json' -338 } -339 -340 response = requests.get(url, headers=headers) -341 time.sleep(0.1) -342 -343 if response.status_code == 200: -344 pass -345 elif response.status_code == 401: -346 raise ConnectionRefusedError( -347 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -348 ) -349 else: -350 raise ConnectionError( -351 f'Could not connect.\nHTTP Status code {response.status_code}' -352 ) +115 if cfbd_key != "tigersAreAwsome": +116 print("Using the user's API key declared in this script for this example.") +117 +118 # Gets all available betting info for the 2020 CFB season. +119 print("Gets all available betting info for the 2020 CFB season.") +120 json_data = get_cfbd_betting_lines( +121 api_key=cfbd_key, +122 season=2020 +123 ) +124 print(json_data) +125 time.sleep(5) +126 +127 # Gets all available betting info for the 2020 CFB season, in week 2. +128 print("Gets all available betting info for the 2020 CFB season, in week 2.") +129 json_data = get_cfbd_betting_lines( +130 api_key=cfbd_key, +131 season=2020, +132 week=2 +133 ) +134 print(json_data) +135 time.sleep(5) +136 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). +137 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") +138 json_data = get_cfbd_betting_lines( +139 api_key=cfbd_key, +140 season=2020, +141 season_type="postseason" +142 ) +143 print(json_data) +144 time.sleep(5) +145 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. +146 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") +147 json_data = get_cfbd_betting_lines( +148 api_key=cfbd_key, +149 season=2020, +150 team="Cincinnati" +151 ) +152 print(json_data) +153 time.sleep(5) +154 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. +155 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") +156 json_data = get_cfbd_betting_lines( +157 api_key=cfbd_key, +158 season=2020, +159 home_team="Ohio" +160 ) +161 print(json_data) +162 time.sleep(5) +163 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. +164 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") +165 json_data = get_cfbd_betting_lines( +166 api_key=cfbd_key, +167 season=2020, +168 away_team="Ohio State" +169 ) +170 +171 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. +172 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") +173 json_data = get_cfbd_betting_lines( +174 api_key=cfbd_key, +175 season=2020, +176 conference_abv="ACC" +177 ) +178 print(json_data) +179 time.sleep(5) +180 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +181 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +182 json_data = get_cfbd_betting_lines( +183 api_key=cfbd_key, +184 season=2020, +185 return_as_dict=True +186 ) +187 print(json_data) +188 +189 else: +190 # Alternatively, if the CFBD API key exists in this python environment, +191 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +192 # you could just call these functions directly, without setting the API key +193 # in the script. +194 print("Using the user's API key suposedly loaded into this python environment for this example.") +195 +196 # Gets all available betting info for the 2020 CFB season. +197 print("Gets all available betting info for the 2020 CFB season.") +198 json_data = get_cfbd_betting_lines( +199 season=2020 +200 ) +201 print(json_data) +202 time.sleep(5) +203 # Gets all available betting info for the 2020 CFB season, in week 2. +204 print("Gets all available betting info for the 2020 CFB season, in week 2.") +205 json_data = get_cfbd_betting_lines( +206 season=2020, +207 week=2 +208 ) +209 print(json_data) +210 time.sleep(5) +211 # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.). +212 print("Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).") +213 json_data = get_cfbd_betting_lines( +214 season=2020, +215 season_type="postseason" +216 ) +217 print(json_data) +218 time.sleep(5) +219 # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season. +220 print("Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.") +221 json_data = get_cfbd_betting_lines( +222 season=2020, +223 team="Cincinnati" +224 ) +225 print(json_data) +226 time.sleep(5) +227 # Gets all betting info for Ohio Bobcats home games the 2020 CFB season. +228 print("Gets all betting info for Ohio Bobcats home games the 2020 CFB season.") +229 json_data = get_cfbd_betting_lines( +230 season=2020, +231 home_team="Ohio" +232 ) +233 print(json_data) +234 time.sleep(5) +235 # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season. +236 print("Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.") +237 json_data = get_cfbd_betting_lines( +238 +239 season=2020, +240 away_team="Ohio State" +241 ) +242 +243 # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season. +244 print("Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.") +245 json_data = get_cfbd_betting_lines( +246 season=2020, +247 conference_abv="ACC" +248 ) +249 print(json_data) +250 time.sleep(5) +251 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +252 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +253 json_data = get_cfbd_betting_lines( +254 season=2020, +255 return_as_dict=True +256 ) +257 print(json_data) +258 +259 +260 ``` +261 Returns +262 ---------- +263 A pandas `DataFrame` object with college football betting data, +264 or (if `return_as_dict` is set to `True`) +265 a dictionary object with college football betting data. +266 """ +267 +268 # now = datetime.now() +269 betting_df = pd.DataFrame() +270 row_df = pd.DataFrame() +271 url = "https://api.collegefootballdata.com/lines?" +272 +273 # Input validation +274 ######################################################################################################################################################################################################## +275 if game_id != None and season != None: +276 warnings.warn( +277 "If you are getting betting information for a single game, only set `game_id` to the game ID, and leave `season` as `NULL`.") +278 +279 if season_type == "regular" or season_type == "postseason": +280 url += f"seasonType={season_type}" +281 else: +282 raise ValueError( +283 "`season_type` must be set to either \"regular\" or \"postseason\".") +284 +285 if (game_id == None) and (season == None) and (week != None): +286 raise ValueError( +287 "When setting a value for `week`, `season` cannot be null.") +288 +289 # if cache_data == True and ((team != None) or (home_team != None) or (away_team != None) or (conference_abv != None)): +290 # logging.warning( +291 # "When caching data is enabled for this function, the following inputs are ignored when making the API call:\n-`team`\n-`home_team`\n-`away_team`\n-`conference_abv`") +292 +293 if api_key != None: +294 real_api_key = api_key +295 del api_key +296 else: +297 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +298 +299 if real_api_key == "tigersAreAwsome": +300 raise ValueError( +301 "You actually need to change `cfbd_key` to your CFBD API key.") +302 elif "Bearer " in real_api_key: +303 pass +304 elif "Bearer" in real_api_key: +305 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +306 else: +307 real_api_key = "Bearer " + real_api_key +308 +309 # URL builder +310 ######################################################################################################################################################################################################## +311 +312 if game_id != None: +313 url += f"&gameId={game_id}" +314 +315 if season != None: +316 url += f"&year={season}" +317 +318 if week != None: +319 url += f"&week={week}" +320 +321 if team != None: +322 url += f"&team={team}" +323 +324 if home_team != None: +325 url += f"&home={home_team}" +326 +327 if away_team != None: +328 url += f"&away={away_team}" +329 +330 if conference_abv != None: +331 url += f"&conference={conference_abv}" +332 +333 headers = { +334 'Authorization': f'{real_api_key}', +335 'accept': 'application/json' +336 } +337 +338 response = requests.get(url, headers=headers) +339 +340 +341 if response.status_code == 200: +342 pass +343 elif response.status_code == 401: +344 raise ConnectionRefusedError( +345 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +346 ) +347 else: +348 raise ConnectionError( +349 f'Could not connect.\nHTTP Status code {response.status_code}' +350 ) +351 +352 json_data = response.json() 353 -354 json_data = response.json() -355 -356 if return_as_dict == True: -357 return json_data -358 -359 for game in tqdm(json_data): -360 gameId = game['id'] -361 season = game['id'] -362 seasonType = game['seasonType'] -363 startDate = game['startDate'] -364 homeTeam = game['homeTeam'] -365 homeConference = game['homeConference'] -366 homeScore = game['homeScore'] -367 awayTeam = game['awayTeam'] -368 awayConference = game['awayConference'] -369 awayScore = game['awayScore'] -370 -371 for line in game['lines']: -372 row_df = pd.DataFrame( -373 { -374 "game_id": gameId, -375 "season": season, -376 "season_type": seasonType, -377 "start_date": startDate, -378 "home_team": homeTeam, -379 "home_conference": homeConference, -380 "home_score": homeScore, -381 "away_team": awayTeam, -382 "away_conference": awayConference, -383 "away_score": awayScore -384 }, -385 index=[0] -386 ) -387 -388 row_df["line_provider"] = line['provider'] -389 row_df["spread"] = line['spread'] -390 row_df["formatted_spread"] = line['formattedSpread'] -391 row_df["spread_open"] = line['spreadOpen'] -392 row_df["over_under"] = line['overUnder'] -393 row_df["over_under_open"] = line['overUnderOpen'] -394 row_df["home_moneyline"] = line['homeMoneyline'] -395 row_df["away_moneyline"] = line['awayMoneyline'] -396 -397 betting_df = pd.concat([betting_df, row_df], ignore_index=True) -398 del row_df -399 -400 del gameId, seasonType, startDate, homeTeam, \ -401 homeConference, homeScore, awayTeam, \ -402 awayConference, awayScore -403 -404 return betting_df +354 if return_as_dict == True: +355 return json_data +356 +357 for game in tqdm(json_data): +358 gameId = game['id'] +359 season = game['id'] +360 seasonType = game['seasonType'] +361 startDate = game['startDate'] +362 homeTeam = game['homeTeam'] +363 homeConference = game['homeConference'] +364 homeScore = game['homeScore'] +365 awayTeam = game['awayTeam'] +366 awayConference = game['awayConference'] +367 awayScore = game['awayScore'] +368 +369 for line in game['lines']: +370 row_df = pd.DataFrame( +371 { +372 "game_id": gameId, +373 "season": season, +374 "season_type": seasonType, +375 "start_date": startDate, +376 "home_team": homeTeam, +377 "home_conference": homeConference, +378 "home_score": homeScore, +379 "away_team": awayTeam, +380 "away_conference": awayConference, +381 "away_score": awayScore +382 }, +383 index=[0] +384 ) +385 +386 row_df["line_provider"] = line['provider'] +387 row_df["spread"] = line['spread'] +388 row_df["formatted_spread"] = line['formattedSpread'] +389 row_df["spread_open"] = line['spreadOpen'] +390 row_df["over_under"] = line['overUnder'] +391 row_df["over_under_open"] = line['overUnderOpen'] +392 row_df["home_moneyline"] = line['homeMoneyline'] +393 row_df["away_moneyline"] = line['awayMoneyline'] +394 +395 betting_df = pd.concat([betting_df, row_df], ignore_index=True) +396 del row_df +397 +398 del gameId, seasonType, startDate, homeTeam, \ +399 homeConference, homeScore, awayTeam, \ +400 awayConference, awayScore +401 +402 return betting_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, diff --git a/docs/cfbd_json_py/coaches.html b/docs/cfbd_json_py/coaches.html index 960b0eb..9dadb67 100644 --- a/docs/cfbd_json_py/coaches.html +++ b/docs/cfbd_json_py/coaches.html @@ -55,401 +55,400 @@
@@ -465,385 +464,385 @@1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/09/2023 08:00 PM EDT + 2# Last Updated Date: 10/23/2023 04:09 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: coaches.py 5# Purpose: Houses functions pertaining to coaching data within the CFBD API. 6#################################################################################################### 7 8import logging - 9import time - 10 - 11import pandas as pd - 12import requests - 13from tqdm import tqdm - 14 - 15from cfbd_json_py.utls import get_cfbd_api_token + 9 + 10import pandas as pd + 11import requests + 12from tqdm import tqdm + 13 + 14from cfbd_json_py.utls import get_cfbd_api_token + 15 16 - 17 - 18def get_cfbd_coaches_info( - 19 api_key: str = None, - 20 api_key_dir: str = None, - 21 first_name: str = None, - 22 last_name: str = None, - 23 team: str = None, - 24 season: int = None, - 25 min_season: int = None, - 26 max_season: int = None, - 27 - 28 return_as_dict: bool = False): - 29 """ - 30 Retrives information from the CFBD API on CFB Head Coaches. - 31 - 32 Parameters - 33 ---------- - 34 `api_key` (str, optional): - 35 Semi-optional argument. - 36 If `api_key` is null, this function will attempt to load a CFBD API key - 37 from the python environment, or from a file on this computer. - 38 If `api_key` is not null, this function will automatically assume that the - 39 inputted `api_key` is a valid CFBD API key. - 40 - 41 `api_key_dir` (str, optional): - 42 Optional argument. - 43 If `api_key` is set to a string non-empty string, this variable is ignored. - 44 If `api_key_dir` is null, and `api_key` is null, - 45 this function will try to find a CFBD API key file in this user's home directory. - 46 If `api_key_dir` is set to a string, and `api_key` is null, - 47 this function will assume that `api_key_dir` is a directory, - 48 and will try to find a CFBD API key file in that directory. - 49 - 50 `first_name` (str, optional): - 51 Optional argument. - 52 If you want to only look up coaches with a specific first name, - 53 set this variable to that specific first name, and this function - 54 will attempt to look up coaches with that specific first name. - 55 - 56 `last_name` (str, optional): - 57 Optional argument. - 58 If you want to only look up coaches with a specific last name, - 59 set this variable to that specific first name, and this function - 60 will attempt to look up coaches with that specific last name. - 61 - 62 `team` (str, optional): - 63 Optional argument. - 64 If you want to filter and drill down to coaches who coached a specific - 65 CFB team, set this - 66 - 67 `season` (int, optional): - 68 Optional argument. - 69 If you only want coaches from a specific season, set this variable to that season. - 70 - 71 `min_season` (int, optional): - 72 Optional argument. - 73 Similar to `year`, but used in tandem with `max_season` to get coaches who coached with in a range of seasons. - 74 - 75 `max_season` (int, optional): - 76 Optional argument. - 77 Similar to `year`, but used in tandem with `min_season` to get coaches who coached with in a range of seasons. - 78 - 79 `return_as_dict` (bool, semi-optional): - 80 Semi-optional argument. - 81 If you want this function to return the data as a dictionary (read: JSON object), - 82 instead of a pandas `DataFrame` object, - 83 set `return_as_dict` to `True`. - 84 - 85 Usage - 86 ---------- - 87 ``` - 88 import time - 89 - 90 from cfbd_json_py.coaches import get_cfbd_coaches_info - 91 - 92 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 93 - 94 if cfbd_key != "tigersAreAwsome": - 95 print("Using the user's API key declared in this script for this example.") - 96 - 97 # Getting all coaches in the 2020 CFB season - 98 print("Getting every coach in the 2020 CFB season.") - 99 json_data = get_cfbd_coaches_info( -100 api_key=cfbd_key, -101 season=2020 -102 ) -103 print(f"{json_data}") -104 time.sleep(5) -105 -106 # Getting all coaches in the 2020 CFB season, with a first name of "Luke" -107 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") -108 json_data = get_cfbd_coaches_info( -109 api_key=cfbd_key, -110 season=2020, -111 first_name="Luke" -112 ) -113 print(f"{json_data}") -114 time.sleep(5) + 17def get_cfbd_coaches_info( + 18 api_key: str = None, + 19 api_key_dir: str = None, + 20 first_name: str = None, + 21 last_name: str = None, + 22 team: str = None, + 23 season: int = None, + 24 min_season: int = None, + 25 max_season: int = None, + 26 + 27 return_as_dict: bool = False): + 28 """ + 29 Retrives information from the CFBD API on CFB Head Coaches. + 30 + 31 Parameters + 32 ---------- + 33 `api_key` (str, optional): + 34 Semi-optional argument. + 35 If `api_key` is null, this function will attempt to load a CFBD API key + 36 from the python environment, or from a file on this computer. + 37 If `api_key` is not null, this function will automatically assume that the + 38 inputted `api_key` is a valid CFBD API key. + 39 + 40 `api_key_dir` (str, optional): + 41 Optional argument. + 42 If `api_key` is set to am empty string, this variable is ignored. + 43 If `api_key_dir` is null, and `api_key` is null, + 44 this function will try to find a CFBD API key file in this user's home directory. + 45 If `api_key_dir` is set to a string, and `api_key` is null, + 46 this function will assume that `api_key_dir` is a directory, + 47 and will try to find a CFBD API key file in that directory. + 48 + 49 `first_name` (str, optional): + 50 Optional argument. + 51 If you want to only look up coaches with a specific first name, + 52 set this variable to that specific first name, and this function + 53 will attempt to look up coaches with that specific first name. + 54 + 55 `last_name` (str, optional): + 56 Optional argument. + 57 If you want to only look up coaches with a specific last name, + 58 set this variable to that specific first name, and this function + 59 will attempt to look up coaches with that specific last name. + 60 + 61 `team` (str, optional): + 62 Optional argument. + 63 If you want to filter and drill down to coaches who coached a specific + 64 CFB team, set this + 65 + 66 `season` (int, optional): + 67 Optional argument. + 68 If you only want coaches from a specific season, set this variable to that season. + 69 + 70 `min_season` (int, optional): + 71 Optional argument. + 72 Similar to `year`, but used in tandem with `max_season` to get coaches who coached with in a range of seasons. + 73 + 74 `max_season` (int, optional): + 75 Optional argument. + 76 Similar to `year`, but used in tandem with `min_season` to get coaches who coached with in a range of seasons. + 77 + 78 `return_as_dict` (bool, semi-optional): + 79 Semi-optional argument. + 80 If you want this function to return the data as a dictionary (read: JSON object), + 81 instead of a pandas `DataFrame` object, + 82 set `return_as_dict` to `True`. + 83 + 84 Usage + 85 ---------- + 86 ``` + 87 import time + 88 + 89 from cfbd_json_py.coaches import get_cfbd_coaches_info + 90 + 91 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 92 + 93 if cfbd_key != "tigersAreAwsome": + 94 print("Using the user's API key declared in this script for this example.") + 95 + 96 # Getting all coaches in the 2020 CFB season + 97 print("Getting every coach in the 2020 CFB season.") + 98 json_data = get_cfbd_coaches_info( + 99 api_key=cfbd_key, +100 season=2020 +101 ) +102 print(f"{json_data}") +103 time.sleep(5) +104 +105 # Getting all coaches in the 2020 CFB season, with a first name of "Luke" +106 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") +107 json_data = get_cfbd_coaches_info( +108 api_key=cfbd_key, +109 season=2020, +110 first_name="Luke" +111 ) +112 print(f"{json_data}") +113 time.sleep(5) +114 115 -116 -117 # Getting all coaches in the 2020 CFB season, with a last name of "Day" -118 print("Getting all coaches in the 2020 CFB season, with a last name of \"Day\".") -119 json_data = get_cfbd_coaches_info( -120 api_key=cfbd_key, -121 season=2020, -122 last_name="Day" -123 ) -124 print(f"{json_data}") -125 time.sleep(5) +116 # Getting all coaches in the 2020 CFB season, with a last name of "Day" +117 print("Getting all coaches in the 2020 CFB season, with a last name of \"Day\".") +118 json_data = get_cfbd_coaches_info( +119 api_key=cfbd_key, +120 season=2020, +121 last_name="Day" +122 ) +123 print(f"{json_data}") +124 time.sleep(5) +125 126 -127 -128 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles -129 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") -130 json_data = get_cfbd_coaches_info( -131 api_key=cfbd_key, -132 season=2020, -133 team="Southern Mississippi" -134 ) -135 print(f"{json_data}") -136 time.sleep(5) +127 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles +128 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") +129 json_data = get_cfbd_coaches_info( +130 api_key=cfbd_key, +131 season=2020, +132 team="Southern Mississippi" +133 ) +134 print(f"{json_data}") +135 time.sleep(5) +136 137 -138 -139 # Getting every head coach between the 2019 and 2022 CFB seasons -140 print("Getting every head coach between the 2019 and 2022 CFB seasons") -141 json_data = get_cfbd_coaches_info( -142 api_key=cfbd_key, -143 min_season=2019, -144 max_season=2022 -145 ) -146 print(f"{json_data}") -147 time.sleep(5) +138 # Getting every head coach between the 2019 and 2022 CFB seasons +139 print("Getting every head coach between the 2019 and 2022 CFB seasons") +140 json_data = get_cfbd_coaches_info( +141 api_key=cfbd_key, +142 min_season=2019, +143 max_season=2022 +144 ) +145 print(f"{json_data}") +146 time.sleep(5) +147 148 -149 -150 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -151 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -152 json_data = get_cfbd_coaches_info( -153 api_key=cfbd_key, -154 season=2022, -155 team="Cincinnati", -156 return_as_dict=True -157 ) -158 print(f"{json_data}") -159 -160 else: -161 # Alternatively, if the CFBD API key exists in this python environment, -162 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -163 # you could just call these functions directly, without setting the API key -164 # in the script. -165 print("Using the user's API key suposedly loaded into this python environment for this example.") -166 -167 # Getting every coach in the 2020 CFB season. -168 print("Getting every coach in the 2020 CFB season.") -169 json_data = get_cfbd_coaches_info(season=2020) -170 print(f"{json_data}") -171 time.sleep(5) +149 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +150 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +151 json_data = get_cfbd_coaches_info( +152 api_key=cfbd_key, +153 season=2022, +154 team="Cincinnati", +155 return_as_dict=True +156 ) +157 print(f"{json_data}") +158 +159 else: +160 # Alternatively, if the CFBD API key exists in this python environment, +161 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +162 # you could just call these functions directly, without setting the API key +163 # in the script. +164 print("Using the user's API key suposedly loaded into this python environment for this example.") +165 +166 # Getting every coach in the 2020 CFB season. +167 print("Getting every coach in the 2020 CFB season.") +168 json_data = get_cfbd_coaches_info(season=2020) +169 print(f"{json_data}") +170 time.sleep(5) +171 172 -173 -174 # Getting every coach in the 2020 CFB season, with a first name of "Luke". -175 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") -176 json_data = get_cfbd_coaches_info( -177 season=2020, -178 first_name="Luke" -179 ) -180 print(f"{json_data}") -181 time.sleep(5) +173 # Getting every coach in the 2020 CFB season, with a first name of "Luke". +174 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") +175 json_data = get_cfbd_coaches_info( +176 season=2020, +177 first_name="Luke" +178 ) +179 print(f"{json_data}") +180 time.sleep(5) +181 182 -183 -184 # Getting every coach in the 2020 CFB season, with a last name of "Day". -185 print("Getting every coach in the 2020 CFB season, with a last name of \"Day\".") -186 json_data = get_cfbd_coaches_info( -187 season=2020, -188 last_name="Day" -189 ) -190 print(f"{json_data}") -191 time.sleep(5) +183 # Getting every coach in the 2020 CFB season, with a last name of "Day". +184 print("Getting every coach in the 2020 CFB season, with a last name of \"Day\".") +185 json_data = get_cfbd_coaches_info( +186 season=2020, +187 last_name="Day" +188 ) +189 print(f"{json_data}") +190 time.sleep(5) +191 192 -193 -194 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles. -195 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") -196 json_data = get_cfbd_coaches_info( -197 season=2020, -198 team="Southern Mississippi" -199 ) -200 print(f"{json_data}") -201 time.sleep(5) +193 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles. +194 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") +195 json_data = get_cfbd_coaches_info( +196 season=2020, +197 team="Southern Mississippi" +198 ) +199 print(f"{json_data}") +200 time.sleep(5) +201 202 -203 -204 # Getting every head coach between the 2019 and 2022 CFB seasons. -205 print("Getting every head coach between the 2019 and 2022 CFB seasons.") -206 json_data = get_cfbd_coaches_info( -207 min_season=2019, -208 max_season=2022 -209 ) -210 print(f"{json_data}") -211 time.sleep(5) +203 # Getting every head coach between the 2019 and 2022 CFB seasons. +204 print("Getting every head coach between the 2019 and 2022 CFB seasons.") +205 json_data = get_cfbd_coaches_info( +206 min_season=2019, +207 max_season=2022 +208 ) +209 print(f"{json_data}") +210 time.sleep(5) +211 212 -213 -214 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -215 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -216 json_data = get_cfbd_coaches_info( -217 season=2022, -218 team="Cincinnati", -219 return_as_dict=True -220 ) -221 print(f"{json_data}") +213 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +214 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +215 json_data = get_cfbd_coaches_info( +216 season=2022, +217 team="Cincinnati", +218 return_as_dict=True +219 ) +220 print(f"{json_data}") +221 222 -223 -224 ``` -225 Returns -226 ---------- -227 A pandas `DataFrame` object with CFB head coach data, -228 or (if `return_as_dict` is set to `True`) -229 a dictionary object with CFB head coach data. -230 """ -231 coaches_df = pd.DataFrame() -232 row_df = pd.DataFrame() -233 url = "https://api.collegefootballdata.com/coaches" -234 -235 # Input validation -236 ######################################################################################################################################################################################################## -237 -238 if api_key != None: -239 real_api_key = api_key -240 del api_key -241 else: -242 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -243 -244 if real_api_key == "tigersAreAwsome": -245 raise ValueError( -246 "You actually need to change `cfbd_key` to your CFBD API key.") -247 elif "Bearer " in real_api_key: -248 pass -249 elif "Bearer" in real_api_key: -250 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -251 else: -252 real_api_key = "Bearer " + real_api_key -253 -254 if min_season != None and max_season == None: -255 if season != None and min_season != season: -256 raise LookupError( -257 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + -258 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + -259 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") -260 elif season != None and min_season == season: -261 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -262 min_season = None -263 elif season == None: -264 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -265 season = min_season -266 min_season = None -267 -268 elif min_season == None and max_season != None: -269 if season != None and max_season != season: -270 raise LookupError( -271 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + -272 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + -273 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") -274 elif season != None and max_season == season: -275 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -276 min_season = None -277 elif season == None: -278 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -279 season = max_season -280 max_season = None -281 -282 if min_season != None and max_season != None: -283 if season != None: -284 raise LookupError( -285 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + -286 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + -287 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") -288 elif min_season > max_season: -289 raise ValueError( -290 '`min_season` cannot be greater than `max_season`.') -291 -292 # URL builder -293 ######################################################################################################################################################################################################## -294 url_elements = 0 -295 -296 if first_name != None and url_elements == 0: -297 url += f"?firstName={first_name}" -298 url_elements += 1 -299 elif first_name != None: -300 url += f"&firstName={first_name}" -301 url_elements += 1 -302 -303 if last_name != None and url_elements == 0: -304 url += f"?lastName={last_name}" -305 url_elements += 1 -306 elif last_name != None: -307 url += f"&lastName={last_name}" -308 url_elements += 1 -309 -310 if team != None and url_elements == 0: -311 url += f"?team={team}" -312 url_elements += 1 -313 elif team != None: -314 url += f"&team={team}" -315 url_elements += 1 -316 -317 if season != None: -318 if season != None and url_elements == 0: -319 url += f"?year={season}" -320 url_elements += 1 -321 elif season != None: -322 url += f"&year={season}" -323 url_elements += 1 -324 -325 elif min_season != None and max_season != None: -326 if url_elements == 0: -327 url += f"?minYear={min_season}&maxYear={max_season}" -328 url_elements += 1 -329 else: -330 url += f"&minYear={min_season}&maxYear={max_season}" -331 url_elements += 1 -332 -333 headers = { -334 'Authorization': f'{real_api_key}', -335 'accept': 'application/json' -336 } -337 -338 response = requests.get(url, headers=headers) -339 time.sleep(0.1) -340 -341 if response.status_code == 200: -342 pass -343 elif response.status_code == 401: -344 raise ConnectionRefusedError( -345 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -346 ) -347 else: -348 raise ConnectionError( -349 f'Could not connect.\nHTTP Status code {response.status_code}' -350 ) -351 -352 json_data = response.json() -353 -354 if return_as_dict == True: -355 return json_data -356 -357 for coach in tqdm(json_data): -358 coach_first_name = coach['first_name'] -359 coach_last_name = coach['last_name'] -360 coach_hire_date = coach['hire_date'] -361 -362 for coach_season in coach['seasons']: -363 row_df = pd.DataFrame( -364 { -365 "coach_first_name": coach_first_name, -366 "coach_last_name": coach_last_name, -367 "coach_hire_date": coach_hire_date -368 }, index=[0] -369 ) -370 row_df['school_name'] = coach_season['school'] -371 -372 if season != None and min_season == None and max_season == None: -373 row_df['season'] = season -374 else: -375 try: -376 row_df['season'] = coach_season['season'] -377 except: -378 row_df['season'] = None -379 -380 row_df['games'] = coach_season['games'] -381 row_df['wins'] = coach_season['wins'] -382 row_df['losses'] = coach_season['losses'] -383 row_df['ties'] = coach_season['ties'] -384 row_df['preseason_rank'] = coach_season['preseason_rank'] -385 row_df['postseason_rank'] = coach_season['postseason_rank'] -386 row_df['srs'] = coach_season['srs'] -387 row_df['sp_overall'] = coach_season['sp_overall'] -388 row_df['sp_offense'] = coach_season['sp_offense'] -389 row_df['sp_defense'] = coach_season['sp_defense'] -390 -391 coaches_df = pd.concat([coaches_df, row_df], ignore_index=True) -392 del row_df -393 -394 del coach_first_name, coach_last_name, coach_hire_date -395 -396 return coaches_df +223 ``` +224 Returns +225 ---------- +226 A pandas `DataFrame` object with CFB head coach data, +227 or (if `return_as_dict` is set to `True`) +228 a dictionary object with CFB head coach data. +229 """ +230 coaches_df = pd.DataFrame() +231 row_df = pd.DataFrame() +232 url = "https://api.collegefootballdata.com/coaches" +233 +234 # Input validation +235 ######################################################################################################################################################################################################## +236 +237 if api_key != None: +238 real_api_key = api_key +239 del api_key +240 else: +241 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +242 +243 if real_api_key == "tigersAreAwsome": +244 raise ValueError( +245 "You actually need to change `cfbd_key` to your CFBD API key.") +246 elif "Bearer " in real_api_key: +247 pass +248 elif "Bearer" in real_api_key: +249 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +250 else: +251 real_api_key = "Bearer " + real_api_key +252 +253 if min_season != None and max_season == None: +254 if season != None and min_season != season: +255 raise LookupError( +256 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + +257 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + +258 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") +259 elif season != None and min_season == season: +260 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +261 min_season = None +262 elif season == None: +263 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +264 season = min_season +265 min_season = None +266 +267 elif min_season == None and max_season != None: +268 if season != None and max_season != season: +269 raise LookupError( +270 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + +271 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + +272 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") +273 elif season != None and max_season == season: +274 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +275 min_season = None +276 elif season == None: +277 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +278 season = max_season +279 max_season = None +280 +281 if min_season != None and max_season != None: +282 if season != None: +283 raise LookupError( +284 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + +285 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + +286 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") +287 elif min_season > max_season: +288 raise ValueError( +289 '`min_season` cannot be greater than `max_season`.') +290 +291 # URL builder +292 ######################################################################################################################################################################################################## +293 url_elements = 0 +294 +295 if first_name != None and url_elements == 0: +296 url += f"?firstName={first_name}" +297 url_elements += 1 +298 elif first_name != None: +299 url += f"&firstName={first_name}" +300 url_elements += 1 +301 +302 if last_name != None and url_elements == 0: +303 url += f"?lastName={last_name}" +304 url_elements += 1 +305 elif last_name != None: +306 url += f"&lastName={last_name}" +307 url_elements += 1 +308 +309 if team != None and url_elements == 0: +310 url += f"?team={team}" +311 url_elements += 1 +312 elif team != None: +313 url += f"&team={team}" +314 url_elements += 1 +315 +316 if season != None: +317 if season != None and url_elements == 0: +318 url += f"?year={season}" +319 url_elements += 1 +320 elif season != None: +321 url += f"&year={season}" +322 url_elements += 1 +323 +324 elif min_season != None and max_season != None: +325 if url_elements == 0: +326 url += f"?minYear={min_season}&maxYear={max_season}" +327 url_elements += 1 +328 else: +329 url += f"&minYear={min_season}&maxYear={max_season}" +330 url_elements += 1 +331 +332 headers = { +333 'Authorization': f'{real_api_key}', +334 'accept': 'application/json' +335 } +336 +337 response = requests.get(url, headers=headers) +338 +339 +340 if response.status_code == 200: +341 pass +342 elif response.status_code == 401: +343 raise ConnectionRefusedError( +344 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +345 ) +346 else: +347 raise ConnectionError( +348 f'Could not connect.\nHTTP Status code {response.status_code}' +349 ) +350 +351 json_data = response.json() +352 +353 if return_as_dict == True: +354 return json_data +355 +356 for coach in tqdm(json_data): +357 coach_first_name = coach['first_name'] +358 coach_last_name = coach['last_name'] +359 coach_hire_date = coach['hire_date'] +360 +361 for coach_season in coach['seasons']: +362 row_df = pd.DataFrame( +363 { +364 "coach_first_name": coach_first_name, +365 "coach_last_name": coach_last_name, +366 "coach_hire_date": coach_hire_date +367 }, index=[0] +368 ) +369 row_df['school_name'] = coach_season['school'] +370 +371 if season != None and min_season == None and max_season == None: +372 row_df['season'] = season +373 else: +374 try: +375 row_df['season'] = coach_season['season'] +376 except: +377 row_df['season'] = None +378 +379 row_df['games'] = coach_season['games'] +380 row_df['wins'] = coach_season['wins'] +381 row_df['losses'] = coach_season['losses'] +382 row_df['ties'] = coach_season['ties'] +383 row_df['preseason_rank'] = coach_season['preseason_rank'] +384 row_df['postseason_rank'] = coach_season['postseason_rank'] +385 row_df['srs'] = coach_season['srs'] +386 row_df['sp_overall'] = coach_season['sp_overall'] +387 row_df['sp_offense'] = coach_season['sp_offense'] +388 row_df['sp_defense'] = coach_season['sp_defense'] +389 +390 coaches_df = pd.concat([coaches_df, row_df], ignore_index=True) +391 del row_df +392 +393 del coach_first_name, coach_last_name, coach_hire_date +394 +395 return coaches_df
19def get_cfbd_coaches_info( - 20 api_key: str = None, - 21 api_key_dir: str = None, - 22 first_name: str = None, - 23 last_name: str = None, - 24 team: str = None, - 25 season: int = None, - 26 min_season: int = None, - 27 max_season: int = None, - 28 - 29 return_as_dict: bool = False): - 30 """ - 31 Retrives information from the CFBD API on CFB Head Coaches. - 32 - 33 Parameters - 34 ---------- - 35 `api_key` (str, optional): - 36 Semi-optional argument. - 37 If `api_key` is null, this function will attempt to load a CFBD API key - 38 from the python environment, or from a file on this computer. - 39 If `api_key` is not null, this function will automatically assume that the - 40 inputted `api_key` is a valid CFBD API key. - 41 - 42 `api_key_dir` (str, optional): - 43 Optional argument. - 44 If `api_key` is set to a string non-empty string, this variable is ignored. - 45 If `api_key_dir` is null, and `api_key` is null, - 46 this function will try to find a CFBD API key file in this user's home directory. - 47 If `api_key_dir` is set to a string, and `api_key` is null, - 48 this function will assume that `api_key_dir` is a directory, - 49 and will try to find a CFBD API key file in that directory. - 50 - 51 `first_name` (str, optional): - 52 Optional argument. - 53 If you want to only look up coaches with a specific first name, - 54 set this variable to that specific first name, and this function - 55 will attempt to look up coaches with that specific first name. - 56 - 57 `last_name` (str, optional): - 58 Optional argument. - 59 If you want to only look up coaches with a specific last name, - 60 set this variable to that specific first name, and this function - 61 will attempt to look up coaches with that specific last name. - 62 - 63 `team` (str, optional): - 64 Optional argument. - 65 If you want to filter and drill down to coaches who coached a specific - 66 CFB team, set this - 67 - 68 `season` (int, optional): - 69 Optional argument. - 70 If you only want coaches from a specific season, set this variable to that season. - 71 - 72 `min_season` (int, optional): - 73 Optional argument. - 74 Similar to `year`, but used in tandem with `max_season` to get coaches who coached with in a range of seasons. - 75 - 76 `max_season` (int, optional): - 77 Optional argument. - 78 Similar to `year`, but used in tandem with `min_season` to get coaches who coached with in a range of seasons. - 79 - 80 `return_as_dict` (bool, semi-optional): - 81 Semi-optional argument. - 82 If you want this function to return the data as a dictionary (read: JSON object), - 83 instead of a pandas `DataFrame` object, - 84 set `return_as_dict` to `True`. - 85 - 86 Usage - 87 ---------- - 88 ``` - 89 import time - 90 - 91 from cfbd_json_py.coaches import get_cfbd_coaches_info - 92 - 93 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 94 - 95 if cfbd_key != "tigersAreAwsome": - 96 print("Using the user's API key declared in this script for this example.") - 97 - 98 # Getting all coaches in the 2020 CFB season - 99 print("Getting every coach in the 2020 CFB season.") -100 json_data = get_cfbd_coaches_info( -101 api_key=cfbd_key, -102 season=2020 -103 ) -104 print(f"{json_data}") -105 time.sleep(5) -106 -107 # Getting all coaches in the 2020 CFB season, with a first name of "Luke" -108 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") -109 json_data = get_cfbd_coaches_info( -110 api_key=cfbd_key, -111 season=2020, -112 first_name="Luke" -113 ) -114 print(f"{json_data}") -115 time.sleep(5) +@@ -860,7 +859,7 @@18def get_cfbd_coaches_info( + 19 api_key: str = None, + 20 api_key_dir: str = None, + 21 first_name: str = None, + 22 last_name: str = None, + 23 team: str = None, + 24 season: int = None, + 25 min_season: int = None, + 26 max_season: int = None, + 27 + 28 return_as_dict: bool = False): + 29 """ + 30 Retrives information from the CFBD API on CFB Head Coaches. + 31 + 32 Parameters + 33 ---------- + 34 `api_key` (str, optional): + 35 Semi-optional argument. + 36 If `api_key` is null, this function will attempt to load a CFBD API key + 37 from the python environment, or from a file on this computer. + 38 If `api_key` is not null, this function will automatically assume that the + 39 inputted `api_key` is a valid CFBD API key. + 40 + 41 `api_key_dir` (str, optional): + 42 Optional argument. + 43 If `api_key` is set to am empty string, this variable is ignored. + 44 If `api_key_dir` is null, and `api_key` is null, + 45 this function will try to find a CFBD API key file in this user's home directory. + 46 If `api_key_dir` is set to a string, and `api_key` is null, + 47 this function will assume that `api_key_dir` is a directory, + 48 and will try to find a CFBD API key file in that directory. + 49 + 50 `first_name` (str, optional): + 51 Optional argument. + 52 If you want to only look up coaches with a specific first name, + 53 set this variable to that specific first name, and this function + 54 will attempt to look up coaches with that specific first name. + 55 + 56 `last_name` (str, optional): + 57 Optional argument. + 58 If you want to only look up coaches with a specific last name, + 59 set this variable to that specific first name, and this function + 60 will attempt to look up coaches with that specific last name. + 61 + 62 `team` (str, optional): + 63 Optional argument. + 64 If you want to filter and drill down to coaches who coached a specific + 65 CFB team, set this + 66 + 67 `season` (int, optional): + 68 Optional argument. + 69 If you only want coaches from a specific season, set this variable to that season. + 70 + 71 `min_season` (int, optional): + 72 Optional argument. + 73 Similar to `year`, but used in tandem with `max_season` to get coaches who coached with in a range of seasons. + 74 + 75 `max_season` (int, optional): + 76 Optional argument. + 77 Similar to `year`, but used in tandem with `min_season` to get coaches who coached with in a range of seasons. + 78 + 79 `return_as_dict` (bool, semi-optional): + 80 Semi-optional argument. + 81 If you want this function to return the data as a dictionary (read: JSON object), + 82 instead of a pandas `DataFrame` object, + 83 set `return_as_dict` to `True`. + 84 + 85 Usage + 86 ---------- + 87 ``` + 88 import time + 89 + 90 from cfbd_json_py.coaches import get_cfbd_coaches_info + 91 + 92 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 93 + 94 if cfbd_key != "tigersAreAwsome": + 95 print("Using the user's API key declared in this script for this example.") + 96 + 97 # Getting all coaches in the 2020 CFB season + 98 print("Getting every coach in the 2020 CFB season.") + 99 json_data = get_cfbd_coaches_info( +100 api_key=cfbd_key, +101 season=2020 +102 ) +103 print(f"{json_data}") +104 time.sleep(5) +105 +106 # Getting all coaches in the 2020 CFB season, with a first name of "Luke" +107 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") +108 json_data = get_cfbd_coaches_info( +109 api_key=cfbd_key, +110 season=2020, +111 first_name="Luke" +112 ) +113 print(f"{json_data}") +114 time.sleep(5) +115 116 -117 -118 # Getting all coaches in the 2020 CFB season, with a last name of "Day" -119 print("Getting all coaches in the 2020 CFB season, with a last name of \"Day\".") -120 json_data = get_cfbd_coaches_info( -121 api_key=cfbd_key, -122 season=2020, -123 last_name="Day" -124 ) -125 print(f"{json_data}") -126 time.sleep(5) +117 # Getting all coaches in the 2020 CFB season, with a last name of "Day" +118 print("Getting all coaches in the 2020 CFB season, with a last name of \"Day\".") +119 json_data = get_cfbd_coaches_info( +120 api_key=cfbd_key, +121 season=2020, +122 last_name="Day" +123 ) +124 print(f"{json_data}") +125 time.sleep(5) +126 127 -128 -129 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles -130 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") -131 json_data = get_cfbd_coaches_info( -132 api_key=cfbd_key, -133 season=2020, -134 team="Southern Mississippi" -135 ) -136 print(f"{json_data}") -137 time.sleep(5) +128 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles +129 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") +130 json_data = get_cfbd_coaches_info( +131 api_key=cfbd_key, +132 season=2020, +133 team="Southern Mississippi" +134 ) +135 print(f"{json_data}") +136 time.sleep(5) +137 138 -139 -140 # Getting every head coach between the 2019 and 2022 CFB seasons -141 print("Getting every head coach between the 2019 and 2022 CFB seasons") -142 json_data = get_cfbd_coaches_info( -143 api_key=cfbd_key, -144 min_season=2019, -145 max_season=2022 -146 ) -147 print(f"{json_data}") -148 time.sleep(5) +139 # Getting every head coach between the 2019 and 2022 CFB seasons +140 print("Getting every head coach between the 2019 and 2022 CFB seasons") +141 json_data = get_cfbd_coaches_info( +142 api_key=cfbd_key, +143 min_season=2019, +144 max_season=2022 +145 ) +146 print(f"{json_data}") +147 time.sleep(5) +148 149 -150 -151 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -152 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -153 json_data = get_cfbd_coaches_info( -154 api_key=cfbd_key, -155 season=2022, -156 team="Cincinnati", -157 return_as_dict=True -158 ) -159 print(f"{json_data}") -160 -161 else: -162 # Alternatively, if the CFBD API key exists in this python environment, -163 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -164 # you could just call these functions directly, without setting the API key -165 # in the script. -166 print("Using the user's API key suposedly loaded into this python environment for this example.") -167 -168 # Getting every coach in the 2020 CFB season. -169 print("Getting every coach in the 2020 CFB season.") -170 json_data = get_cfbd_coaches_info(season=2020) -171 print(f"{json_data}") -172 time.sleep(5) +150 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +151 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +152 json_data = get_cfbd_coaches_info( +153 api_key=cfbd_key, +154 season=2022, +155 team="Cincinnati", +156 return_as_dict=True +157 ) +158 print(f"{json_data}") +159 +160 else: +161 # Alternatively, if the CFBD API key exists in this python environment, +162 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +163 # you could just call these functions directly, without setting the API key +164 # in the script. +165 print("Using the user's API key suposedly loaded into this python environment for this example.") +166 +167 # Getting every coach in the 2020 CFB season. +168 print("Getting every coach in the 2020 CFB season.") +169 json_data = get_cfbd_coaches_info(season=2020) +170 print(f"{json_data}") +171 time.sleep(5) +172 173 -174 -175 # Getting every coach in the 2020 CFB season, with a first name of "Luke". -176 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") -177 json_data = get_cfbd_coaches_info( -178 season=2020, -179 first_name="Luke" -180 ) -181 print(f"{json_data}") -182 time.sleep(5) +174 # Getting every coach in the 2020 CFB season, with a first name of "Luke". +175 print("Getting every coach in the 2020 CFB season, with a first name of \"Luke\".") +176 json_data = get_cfbd_coaches_info( +177 season=2020, +178 first_name="Luke" +179 ) +180 print(f"{json_data}") +181 time.sleep(5) +182 183 -184 -185 # Getting every coach in the 2020 CFB season, with a last name of "Day". -186 print("Getting every coach in the 2020 CFB season, with a last name of \"Day\".") -187 json_data = get_cfbd_coaches_info( -188 season=2020, -189 last_name="Day" -190 ) -191 print(f"{json_data}") -192 time.sleep(5) +184 # Getting every coach in the 2020 CFB season, with a last name of "Day". +185 print("Getting every coach in the 2020 CFB season, with a last name of \"Day\".") +186 json_data = get_cfbd_coaches_info( +187 season=2020, +188 last_name="Day" +189 ) +190 print(f"{json_data}") +191 time.sleep(5) +192 193 -194 -195 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles. -196 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") -197 json_data = get_cfbd_coaches_info( -198 season=2020, -199 team="Southern Mississippi" -200 ) -201 print(f"{json_data}") -202 time.sleep(5) +194 # Getting every head coach for the 2020 Southern Mississippi Golden Eagles. +195 print("Getting every head coach for the 2020 Southern Mississippi Golden Eagles.") +196 json_data = get_cfbd_coaches_info( +197 season=2020, +198 team="Southern Mississippi" +199 ) +200 print(f"{json_data}") +201 time.sleep(5) +202 203 -204 -205 # Getting every head coach between the 2019 and 2022 CFB seasons. -206 print("Getting every head coach between the 2019 and 2022 CFB seasons.") -207 json_data = get_cfbd_coaches_info( -208 min_season=2019, -209 max_season=2022 -210 ) -211 print(f"{json_data}") -212 time.sleep(5) +204 # Getting every head coach between the 2019 and 2022 CFB seasons. +205 print("Getting every head coach between the 2019 and 2022 CFB seasons.") +206 json_data = get_cfbd_coaches_info( +207 min_season=2019, +208 max_season=2022 +209 ) +210 print(f"{json_data}") +211 time.sleep(5) +212 213 -214 -215 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -216 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -217 json_data = get_cfbd_coaches_info( -218 season=2022, -219 team="Cincinnati", -220 return_as_dict=True -221 ) -222 print(f"{json_data}") +214 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +215 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +216 json_data = get_cfbd_coaches_info( +217 season=2022, +218 team="Cincinnati", +219 return_as_dict=True +220 ) +221 print(f"{json_data}") +222 223 -224 -225 ``` -226 Returns -227 ---------- -228 A pandas `DataFrame` object with CFB head coach data, -229 or (if `return_as_dict` is set to `True`) -230 a dictionary object with CFB head coach data. -231 """ -232 coaches_df = pd.DataFrame() -233 row_df = pd.DataFrame() -234 url = "https://api.collegefootballdata.com/coaches" -235 -236 # Input validation -237 ######################################################################################################################################################################################################## -238 -239 if api_key != None: -240 real_api_key = api_key -241 del api_key -242 else: -243 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -244 -245 if real_api_key == "tigersAreAwsome": -246 raise ValueError( -247 "You actually need to change `cfbd_key` to your CFBD API key.") -248 elif "Bearer " in real_api_key: -249 pass -250 elif "Bearer" in real_api_key: -251 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -252 else: -253 real_api_key = "Bearer " + real_api_key -254 -255 if min_season != None and max_season == None: -256 if season != None and min_season != season: -257 raise LookupError( -258 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + -259 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + -260 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") -261 elif season != None and min_season == season: -262 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -263 min_season = None -264 elif season == None: -265 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -266 season = min_season -267 min_season = None -268 -269 elif min_season == None and max_season != None: -270 if season != None and max_season != season: -271 raise LookupError( -272 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + -273 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + -274 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") -275 elif season != None and max_season == season: -276 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -277 min_season = None -278 elif season == None: -279 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") -280 season = max_season -281 max_season = None -282 -283 if min_season != None and max_season != None: -284 if season != None: -285 raise LookupError( -286 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + -287 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + -288 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") -289 elif min_season > max_season: -290 raise ValueError( -291 '`min_season` cannot be greater than `max_season`.') -292 -293 # URL builder -294 ######################################################################################################################################################################################################## -295 url_elements = 0 -296 -297 if first_name != None and url_elements == 0: -298 url += f"?firstName={first_name}" -299 url_elements += 1 -300 elif first_name != None: -301 url += f"&firstName={first_name}" -302 url_elements += 1 -303 -304 if last_name != None and url_elements == 0: -305 url += f"?lastName={last_name}" -306 url_elements += 1 -307 elif last_name != None: -308 url += f"&lastName={last_name}" -309 url_elements += 1 -310 -311 if team != None and url_elements == 0: -312 url += f"?team={team}" -313 url_elements += 1 -314 elif team != None: -315 url += f"&team={team}" -316 url_elements += 1 -317 -318 if season != None: -319 if season != None and url_elements == 0: -320 url += f"?year={season}" -321 url_elements += 1 -322 elif season != None: -323 url += f"&year={season}" -324 url_elements += 1 -325 -326 elif min_season != None and max_season != None: -327 if url_elements == 0: -328 url += f"?minYear={min_season}&maxYear={max_season}" -329 url_elements += 1 -330 else: -331 url += f"&minYear={min_season}&maxYear={max_season}" -332 url_elements += 1 -333 -334 headers = { -335 'Authorization': f'{real_api_key}', -336 'accept': 'application/json' -337 } -338 -339 response = requests.get(url, headers=headers) -340 time.sleep(0.1) -341 -342 if response.status_code == 200: -343 pass -344 elif response.status_code == 401: -345 raise ConnectionRefusedError( -346 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -347 ) -348 else: -349 raise ConnectionError( -350 f'Could not connect.\nHTTP Status code {response.status_code}' -351 ) -352 -353 json_data = response.json() -354 -355 if return_as_dict == True: -356 return json_data -357 -358 for coach in tqdm(json_data): -359 coach_first_name = coach['first_name'] -360 coach_last_name = coach['last_name'] -361 coach_hire_date = coach['hire_date'] -362 -363 for coach_season in coach['seasons']: -364 row_df = pd.DataFrame( -365 { -366 "coach_first_name": coach_first_name, -367 "coach_last_name": coach_last_name, -368 "coach_hire_date": coach_hire_date -369 }, index=[0] -370 ) -371 row_df['school_name'] = coach_season['school'] -372 -373 if season != None and min_season == None and max_season == None: -374 row_df['season'] = season -375 else: -376 try: -377 row_df['season'] = coach_season['season'] -378 except: -379 row_df['season'] = None -380 -381 row_df['games'] = coach_season['games'] -382 row_df['wins'] = coach_season['wins'] -383 row_df['losses'] = coach_season['losses'] -384 row_df['ties'] = coach_season['ties'] -385 row_df['preseason_rank'] = coach_season['preseason_rank'] -386 row_df['postseason_rank'] = coach_season['postseason_rank'] -387 row_df['srs'] = coach_season['srs'] -388 row_df['sp_overall'] = coach_season['sp_overall'] -389 row_df['sp_offense'] = coach_season['sp_offense'] -390 row_df['sp_defense'] = coach_season['sp_defense'] -391 -392 coaches_df = pd.concat([coaches_df, row_df], ignore_index=True) -393 del row_df -394 -395 del coach_first_name, coach_last_name, coach_hire_date -396 -397 return coaches_df +224 ``` +225 Returns +226 ---------- +227 A pandas `DataFrame` object with CFB head coach data, +228 or (if `return_as_dict` is set to `True`) +229 a dictionary object with CFB head coach data. +230 """ +231 coaches_df = pd.DataFrame() +232 row_df = pd.DataFrame() +233 url = "https://api.collegefootballdata.com/coaches" +234 +235 # Input validation +236 ######################################################################################################################################################################################################## +237 +238 if api_key != None: +239 real_api_key = api_key +240 del api_key +241 else: +242 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +243 +244 if real_api_key == "tigersAreAwsome": +245 raise ValueError( +246 "You actually need to change `cfbd_key` to your CFBD API key.") +247 elif "Bearer " in real_api_key: +248 pass +249 elif "Bearer" in real_api_key: +250 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +251 else: +252 real_api_key = "Bearer " + real_api_key +253 +254 if min_season != None and max_season == None: +255 if season != None and min_season != season: +256 raise LookupError( +257 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + +258 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + +259 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") +260 elif season != None and min_season == season: +261 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +262 min_season = None +263 elif season == None: +264 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +265 season = min_season +266 min_season = None +267 +268 elif min_season == None and max_season != None: +269 if season != None and max_season != season: +270 raise LookupError( +271 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + +272 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + +273 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") +274 elif season != None and max_season == season: +275 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +276 min_season = None +277 elif season == None: +278 logging.warning("If you only want coaching information for a single season, and not for a range of seasons, only set `year` to the seaon you want coaching info for, and leave `min_season` and `max_season` as `None` (NULL).") +279 season = max_season +280 max_season = None +281 +282 if min_season != None and max_season != None: +283 if season != None: +284 raise LookupError( +285 "It is ambiguous which year you want coaching information from, because you set the following values for the following variables:" + +286 f"\n- `year`: {season}\n- `min_season`: {min_season}\n`max_season`: {max_season}" + +287 "\nIf you want to get coaches who coached in a specified range of seasons, set `min_season` and `max_season` to the range of seasons you want coaching information from.") +288 elif min_season > max_season: +289 raise ValueError( +290 '`min_season` cannot be greater than `max_season`.') +291 +292 # URL builder +293 ######################################################################################################################################################################################################## +294 url_elements = 0 +295 +296 if first_name != None and url_elements == 0: +297 url += f"?firstName={first_name}" +298 url_elements += 1 +299 elif first_name != None: +300 url += f"&firstName={first_name}" +301 url_elements += 1 +302 +303 if last_name != None and url_elements == 0: +304 url += f"?lastName={last_name}" +305 url_elements += 1 +306 elif last_name != None: +307 url += f"&lastName={last_name}" +308 url_elements += 1 +309 +310 if team != None and url_elements == 0: +311 url += f"?team={team}" +312 url_elements += 1 +313 elif team != None: +314 url += f"&team={team}" +315 url_elements += 1 +316 +317 if season != None: +318 if season != None and url_elements == 0: +319 url += f"?year={season}" +320 url_elements += 1 +321 elif season != None: +322 url += f"&year={season}" +323 url_elements += 1 +324 +325 elif min_season != None and max_season != None: +326 if url_elements == 0: +327 url += f"?minYear={min_season}&maxYear={max_season}" +328 url_elements += 1 +329 else: +330 url += f"&minYear={min_season}&maxYear={max_season}" +331 url_elements += 1 +332 +333 headers = { +334 'Authorization': f'{real_api_key}', +335 'accept': 'application/json' +336 } +337 +338 response = requests.get(url, headers=headers) +339 +340 +341 if response.status_code == 200: +342 pass +343 elif response.status_code == 401: +344 raise ConnectionRefusedError( +345 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +346 ) +347 else: +348 raise ConnectionError( +349 f'Could not connect.\nHTTP Status code {response.status_code}' +350 ) +351 +352 json_data = response.json() +353 +354 if return_as_dict == True: +355 return json_data +356 +357 for coach in tqdm(json_data): +358 coach_first_name = coach['first_name'] +359 coach_last_name = coach['last_name'] +360 coach_hire_date = coach['hire_date'] +361 +362 for coach_season in coach['seasons']: +363 row_df = pd.DataFrame( +364 { +365 "coach_first_name": coach_first_name, +366 "coach_last_name": coach_last_name, +367 "coach_hire_date": coach_hire_date +368 }, index=[0] +369 ) +370 row_df['school_name'] = coach_season['school'] +371 +372 if season != None and min_season == None and max_season == None: +373 row_df['season'] = season +374 else: +375 try: +376 row_df['season'] = coach_season['season'] +377 except: +378 row_df['season'] = None +379 +380 row_df['games'] = coach_season['games'] +381 row_df['wins'] = coach_season['wins'] +382 row_df['losses'] = coach_season['losses'] +383 row_df['ties'] = coach_season['ties'] +384 row_df['preseason_rank'] = coach_season['preseason_rank'] +385 row_df['postseason_rank'] = coach_season['postseason_rank'] +386 row_df['srs'] = coach_season['srs'] +387 row_df['sp_overall'] = coach_season['sp_overall'] +388 row_df['sp_offense'] = coach_season['sp_offense'] +389 row_df['sp_defense'] = coach_season['sp_defense'] +390 +391 coaches_df = pd.concat([coaches_df, row_df], ignore_index=True) +392 del row_df +393 +394 del coach_first_name, coach_last_name, coach_hire_date +395 +396 return coaches_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, diff --git a/docs/cfbd_json_py/conferences.html b/docs/cfbd_json_py/conferences.html index b95cdc9..abd1637 100644 --- a/docs/cfbd_json_py/conferences.html +++ b/docs/cfbd_json_py/conferences.html @@ -55,174 +55,173 @@
@@ -238,161 +237,161 @@1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/06/2023 07:35 PM EDT + 2# Last Updated Date: 10/23/2023 04:09 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: conferences.py 5# Purpose: Houses functions pertaining to CFB conference data within the CFBD API. 6#################################################################################################### 7 - 8import time - 9import pandas as pd - 10import requests - 11 - 12from cfbd_json_py.utls import get_cfbd_api_token + 8import pandas as pd + 9import requests + 10 + 11from cfbd_json_py.utls import get_cfbd_api_token + 12 13 - 14 - 15def get_cfbd_conference_info( - 16 api_key: str = None, - 17 api_key_dir: str = None, - 18 return_as_dict: bool = False): - 19 """ - 20 Retrives a list of CFB conferences from the CFBD API. - 21 - 22 Parameters - 23 ---------- - 24 `api_key` (str, optional): - 25 Semi-optional argument. - 26 If `api_key` is null, this function will attempt to load a CFBD API key - 27 from the python environment, or from a file on this computer. - 28 If `api_key` is not null, this function will automatically assume that the - 29 inputted `api_key` is a valid CFBD API key. - 30 - 31 `api_key_dir` (str, optional): - 32 Optional argument. - 33 If `api_key` is set to a string non-empty string, this variable is ignored. - 34 If `api_key_dir` is null, and `api_key` is null, - 35 this function will try to find a CFBD API key file in this user's home directory. - 36 If `api_key_dir` is set to a string, and `api_key` is null, - 37 this function will assume that `api_key_dir` is a directory, - 38 and will try to find a CFBD API key file in that directory. - 39 - 40 `return_as_dict` (bool, semi-optional): - 41 Semi-optional argument. - 42 If you want this function to return the data as a dictionary (read: JSON object), - 43 instead of a pandas `DataFrame` object, - 44 set `return_as_dict` to `True`. - 45 - 46 Usage - 47 ---------- - 48 ``` - 49 import time - 50 - 51 from cfbd_json_py.conferences import get_cfbd_conference_info - 52 - 53 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 54 - 55 if cfbd_key != "tigersAreAwsome": - 56 print("Using the user's API key declared in this script for this example.") - 57 - 58 # Gets CFB confrence info from the CFBD API. - 59 print("Gets CFB confrence info from the CFBD API.") - 60 json_data = get_cfbd_conference_info(api_key=cfbd_key) - 61 print(json_data) - 62 time.sleep(5) - 63 - 64 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 65 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 66 json_data = get_cfbd_conference_info( - 67 api_key=cfbd_key, - 68 return_as_dict=True) - 69 print(json_data) - 70 - 71 else: - 72 # Alternatively, if the CFBD API key exists in this python environment, - 73 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 74 # you could just call these functions directly, without setting the API key - 75 # in the script. - 76 print("Using the user's API key suposedly loaded into this python environment for this example.") - 77 - 78 # Gets CFB confrence info from the CFBD API. - 79 print("Gets CFB confrence info from the CFBD API.") - 80 json_data = get_cfbd_conference_info() - 81 print(json_data) - 82 time.sleep(5) - 83 - 84 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 85 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 86 json_data = get_cfbd_conference_info(return_as_dict=True) - 87 print(json_data) - 88 - 89 ``` - 90 - 91 Returns - 92 ---------- - 93 A pandas `DataFrame` object with CFB conference data, - 94 or (if `return_as_dict` is set to `True`) - 95 a dictionary object with CFB conference data. - 96 """ - 97 - 98 conference_df = pd.DataFrame() - 99 row_df = pd.DataFrame() -100 url = "https://api.collegefootballdata.com/conferences" -101 -102 # Input validation -103 ######################################################################################################################################################################################################## -104 -105 if api_key != None: -106 real_api_key = api_key -107 del api_key -108 else: -109 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -110 -111 if real_api_key == "tigersAreAwsome": -112 raise ValueError( -113 "You actually need to change `cfbd_key` to your CFBD API key.") -114 elif "Bearer " in real_api_key: -115 pass -116 elif "Bearer" in real_api_key: -117 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -118 else: -119 real_api_key = "Bearer " + real_api_key -120 -121 headers = { -122 'Authorization': f'{real_api_key}', -123 'accept': 'application/json' -124 } -125 -126 response = requests.get(url, headers=headers) -127 time.sleep(0.1) -128 -129 if response.status_code == 200: -130 pass -131 elif response.status_code == 401: -132 raise ConnectionRefusedError( -133 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -134 ) -135 else: -136 raise ConnectionError( -137 f'Could not connect.\nHTTP Status code {response.status_code}' -138 ) -139 -140 json_data = response.json() -141 -142 if return_as_dict == True: -143 return json_data -144 -145 for conference in json_data: -146 conference_id = conference['id'] -147 conference_name = conference['name'] -148 conference_short_name = conference['short_name'] -149 conference_abbreviation = conference['abbreviation'] -150 ncaa_classification = conference['classification'] -151 -152 row_df = pd.DataFrame( -153 { -154 "conference_id": conference_id, -155 "conference_name": conference_name, -156 "conference_short_name": conference_short_name, -157 "conference_abbreviation": conference_abbreviation, -158 "ncaa_classification": ncaa_classification -159 }, index=[0] -160 ) -161 -162 conference_df = pd.concat([conference_df, row_df], ignore_index=True) -163 del conference_id, conference_name, \ -164 conference_short_name, conference_abbreviation, \ -165 ncaa_classification -166 -167 del row_df -168 -169 return conference_df + 14def get_cfbd_conference_info( + 15 api_key: str = None, + 16 api_key_dir: str = None, + 17 return_as_dict: bool = False): + 18 """ + 19 Retrives a list of CFB conferences from the CFBD API. + 20 + 21 Parameters + 22 ---------- + 23 `api_key` (str, optional): + 24 Semi-optional argument. + 25 If `api_key` is null, this function will attempt to load a CFBD API key + 26 from the python environment, or from a file on this computer. + 27 If `api_key` is not null, this function will automatically assume that the + 28 inputted `api_key` is a valid CFBD API key. + 29 + 30 `api_key_dir` (str, optional): + 31 Optional argument. + 32 If `api_key` is set to am empty string, this variable is ignored. + 33 If `api_key_dir` is null, and `api_key` is null, + 34 this function will try to find a CFBD API key file in this user's home directory. + 35 If `api_key_dir` is set to a string, and `api_key` is null, + 36 this function will assume that `api_key_dir` is a directory, + 37 and will try to find a CFBD API key file in that directory. + 38 + 39 `return_as_dict` (bool, semi-optional): + 40 Semi-optional argument. + 41 If you want this function to return the data as a dictionary (read: JSON object), + 42 instead of a pandas `DataFrame` object, + 43 set `return_as_dict` to `True`. + 44 + 45 Usage + 46 ---------- + 47 ``` + 48 import time + 49 + 50 from cfbd_json_py.conferences import get_cfbd_conference_info + 51 + 52 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 53 + 54 if cfbd_key != "tigersAreAwsome": + 55 print("Using the user's API key declared in this script for this example.") + 56 + 57 # Gets CFB confrence info from the CFBD API. + 58 print("Gets CFB confrence info from the CFBD API.") + 59 json_data = get_cfbd_conference_info(api_key=cfbd_key) + 60 print(json_data) + 61 time.sleep(5) + 62 + 63 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 64 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 65 json_data = get_cfbd_conference_info( + 66 api_key=cfbd_key, + 67 return_as_dict=True) + 68 print(json_data) + 69 + 70 else: + 71 # Alternatively, if the CFBD API key exists in this python environment, + 72 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 73 # you could just call these functions directly, without setting the API key + 74 # in the script. + 75 print("Using the user's API key suposedly loaded into this python environment for this example.") + 76 + 77 # Gets CFB confrence info from the CFBD API. + 78 print("Gets CFB confrence info from the CFBD API.") + 79 json_data = get_cfbd_conference_info() + 80 print(json_data) + 81 time.sleep(5) + 82 + 83 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 84 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 85 json_data = get_cfbd_conference_info(return_as_dict=True) + 86 print(json_data) + 87 + 88 ``` + 89 + 90 Returns + 91 ---------- + 92 A pandas `DataFrame` object with CFB conference data, + 93 or (if `return_as_dict` is set to `True`) + 94 a dictionary object with CFB conference data. + 95 """ + 96 + 97 conference_df = pd.DataFrame() + 98 row_df = pd.DataFrame() + 99 url = "https://api.collegefootballdata.com/conferences" +100 +101 # Input validation +102 ######################################################################################################################################################################################################## +103 +104 if api_key != None: +105 real_api_key = api_key +106 del api_key +107 else: +108 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +109 +110 if real_api_key == "tigersAreAwsome": +111 raise ValueError( +112 "You actually need to change `cfbd_key` to your CFBD API key.") +113 elif "Bearer " in real_api_key: +114 pass +115 elif "Bearer" in real_api_key: +116 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +117 else: +118 real_api_key = "Bearer " + real_api_key +119 +120 headers = { +121 'Authorization': f'{real_api_key}', +122 'accept': 'application/json' +123 } +124 +125 response = requests.get(url, headers=headers) +126 +127 +128 if response.status_code == 200: +129 pass +130 elif response.status_code == 401: +131 raise ConnectionRefusedError( +132 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +133 ) +134 else: +135 raise ConnectionError( +136 f'Could not connect.\nHTTP Status code {response.status_code}' +137 ) +138 +139 json_data = response.json() +140 +141 if return_as_dict == True: +142 return json_data +143 +144 for conference in json_data: +145 conference_id = conference['id'] +146 conference_name = conference['name'] +147 conference_short_name = conference['short_name'] +148 conference_abbreviation = conference['abbreviation'] +149 ncaa_classification = conference['classification'] +150 +151 row_df = pd.DataFrame( +152 { +153 "conference_id": conference_id, +154 "conference_name": conference_name, +155 "conference_short_name": conference_short_name, +156 "conference_abbreviation": conference_abbreviation, +157 "ncaa_classification": ncaa_classification +158 }, index=[0] +159 ) +160 +161 conference_df = pd.concat([conference_df, row_df], ignore_index=True) +162 del conference_id, conference_name, \ +163 conference_short_name, conference_abbreviation, \ +164 ncaa_classification +165 +166 del row_df +167 +168 return conference_df
16def get_cfbd_conference_info( - 17 api_key: str = None, - 18 api_key_dir: str = None, - 19 return_as_dict: bool = False): - 20 """ - 21 Retrives a list of CFB conferences from the CFBD API. - 22 - 23 Parameters - 24 ---------- - 25 `api_key` (str, optional): - 26 Semi-optional argument. - 27 If `api_key` is null, this function will attempt to load a CFBD API key - 28 from the python environment, or from a file on this computer. - 29 If `api_key` is not null, this function will automatically assume that the - 30 inputted `api_key` is a valid CFBD API key. - 31 - 32 `api_key_dir` (str, optional): - 33 Optional argument. - 34 If `api_key` is set to a string non-empty string, this variable is ignored. - 35 If `api_key_dir` is null, and `api_key` is null, - 36 this function will try to find a CFBD API key file in this user's home directory. - 37 If `api_key_dir` is set to a string, and `api_key` is null, - 38 this function will assume that `api_key_dir` is a directory, - 39 and will try to find a CFBD API key file in that directory. - 40 - 41 `return_as_dict` (bool, semi-optional): - 42 Semi-optional argument. - 43 If you want this function to return the data as a dictionary (read: JSON object), - 44 instead of a pandas `DataFrame` object, - 45 set `return_as_dict` to `True`. - 46 - 47 Usage - 48 ---------- - 49 ``` - 50 import time - 51 - 52 from cfbd_json_py.conferences import get_cfbd_conference_info - 53 - 54 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 55 - 56 if cfbd_key != "tigersAreAwsome": - 57 print("Using the user's API key declared in this script for this example.") - 58 - 59 # Gets CFB confrence info from the CFBD API. - 60 print("Gets CFB confrence info from the CFBD API.") - 61 json_data = get_cfbd_conference_info(api_key=cfbd_key) - 62 print(json_data) - 63 time.sleep(5) - 64 - 65 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 66 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 67 json_data = get_cfbd_conference_info( - 68 api_key=cfbd_key, - 69 return_as_dict=True) - 70 print(json_data) - 71 - 72 else: - 73 # Alternatively, if the CFBD API key exists in this python environment, - 74 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 75 # you could just call these functions directly, without setting the API key - 76 # in the script. - 77 print("Using the user's API key suposedly loaded into this python environment for this example.") - 78 - 79 # Gets CFB confrence info from the CFBD API. - 80 print("Gets CFB confrence info from the CFBD API.") - 81 json_data = get_cfbd_conference_info() - 82 print(json_data) - 83 time.sleep(5) - 84 - 85 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 86 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 87 json_data = get_cfbd_conference_info(return_as_dict=True) - 88 print(json_data) - 89 - 90 ``` - 91 - 92 Returns - 93 ---------- - 94 A pandas `DataFrame` object with CFB conference data, - 95 or (if `return_as_dict` is set to `True`) - 96 a dictionary object with CFB conference data. - 97 """ - 98 - 99 conference_df = pd.DataFrame() -100 row_df = pd.DataFrame() -101 url = "https://api.collegefootballdata.com/conferences" -102 -103 # Input validation -104 ######################################################################################################################################################################################################## -105 -106 if api_key != None: -107 real_api_key = api_key -108 del api_key -109 else: -110 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -111 -112 if real_api_key == "tigersAreAwsome": -113 raise ValueError( -114 "You actually need to change `cfbd_key` to your CFBD API key.") -115 elif "Bearer " in real_api_key: -116 pass -117 elif "Bearer" in real_api_key: -118 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -119 else: -120 real_api_key = "Bearer " + real_api_key -121 -122 headers = { -123 'Authorization': f'{real_api_key}', -124 'accept': 'application/json' -125 } -126 -127 response = requests.get(url, headers=headers) -128 time.sleep(0.1) -129 -130 if response.status_code == 200: -131 pass -132 elif response.status_code == 401: -133 raise ConnectionRefusedError( -134 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -135 ) -136 else: -137 raise ConnectionError( -138 f'Could not connect.\nHTTP Status code {response.status_code}' -139 ) -140 -141 json_data = response.json() -142 -143 if return_as_dict == True: -144 return json_data -145 -146 for conference in json_data: -147 conference_id = conference['id'] -148 conference_name = conference['name'] -149 conference_short_name = conference['short_name'] -150 conference_abbreviation = conference['abbreviation'] -151 ncaa_classification = conference['classification'] -152 -153 row_df = pd.DataFrame( -154 { -155 "conference_id": conference_id, -156 "conference_name": conference_name, -157 "conference_short_name": conference_short_name, -158 "conference_abbreviation": conference_abbreviation, -159 "ncaa_classification": ncaa_classification -160 }, index=[0] -161 ) -162 -163 conference_df = pd.concat([conference_df, row_df], ignore_index=True) -164 del conference_id, conference_name, \ -165 conference_short_name, conference_abbreviation, \ -166 ncaa_classification -167 -168 del row_df -169 -170 return conference_df +@@ -409,7 +408,7 @@15def get_cfbd_conference_info( + 16 api_key: str = None, + 17 api_key_dir: str = None, + 18 return_as_dict: bool = False): + 19 """ + 20 Retrives a list of CFB conferences from the CFBD API. + 21 + 22 Parameters + 23 ---------- + 24 `api_key` (str, optional): + 25 Semi-optional argument. + 26 If `api_key` is null, this function will attempt to load a CFBD API key + 27 from the python environment, or from a file on this computer. + 28 If `api_key` is not null, this function will automatically assume that the + 29 inputted `api_key` is a valid CFBD API key. + 30 + 31 `api_key_dir` (str, optional): + 32 Optional argument. + 33 If `api_key` is set to am empty string, this variable is ignored. + 34 If `api_key_dir` is null, and `api_key` is null, + 35 this function will try to find a CFBD API key file in this user's home directory. + 36 If `api_key_dir` is set to a string, and `api_key` is null, + 37 this function will assume that `api_key_dir` is a directory, + 38 and will try to find a CFBD API key file in that directory. + 39 + 40 `return_as_dict` (bool, semi-optional): + 41 Semi-optional argument. + 42 If you want this function to return the data as a dictionary (read: JSON object), + 43 instead of a pandas `DataFrame` object, + 44 set `return_as_dict` to `True`. + 45 + 46 Usage + 47 ---------- + 48 ``` + 49 import time + 50 + 51 from cfbd_json_py.conferences import get_cfbd_conference_info + 52 + 53 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 54 + 55 if cfbd_key != "tigersAreAwsome": + 56 print("Using the user's API key declared in this script for this example.") + 57 + 58 # Gets CFB confrence info from the CFBD API. + 59 print("Gets CFB confrence info from the CFBD API.") + 60 json_data = get_cfbd_conference_info(api_key=cfbd_key) + 61 print(json_data) + 62 time.sleep(5) + 63 + 64 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 65 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 66 json_data = get_cfbd_conference_info( + 67 api_key=cfbd_key, + 68 return_as_dict=True) + 69 print(json_data) + 70 + 71 else: + 72 # Alternatively, if the CFBD API key exists in this python environment, + 73 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 74 # you could just call these functions directly, without setting the API key + 75 # in the script. + 76 print("Using the user's API key suposedly loaded into this python environment for this example.") + 77 + 78 # Gets CFB confrence info from the CFBD API. + 79 print("Gets CFB confrence info from the CFBD API.") + 80 json_data = get_cfbd_conference_info() + 81 print(json_data) + 82 time.sleep(5) + 83 + 84 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 85 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 86 json_data = get_cfbd_conference_info(return_as_dict=True) + 87 print(json_data) + 88 + 89 ``` + 90 + 91 Returns + 92 ---------- + 93 A pandas `DataFrame` object with CFB conference data, + 94 or (if `return_as_dict` is set to `True`) + 95 a dictionary object with CFB conference data. + 96 """ + 97 + 98 conference_df = pd.DataFrame() + 99 row_df = pd.DataFrame() +100 url = "https://api.collegefootballdata.com/conferences" +101 +102 # Input validation +103 ######################################################################################################################################################################################################## +104 +105 if api_key != None: +106 real_api_key = api_key +107 del api_key +108 else: +109 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +110 +111 if real_api_key == "tigersAreAwsome": +112 raise ValueError( +113 "You actually need to change `cfbd_key` to your CFBD API key.") +114 elif "Bearer " in real_api_key: +115 pass +116 elif "Bearer" in real_api_key: +117 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +118 else: +119 real_api_key = "Bearer " + real_api_key +120 +121 headers = { +122 'Authorization': f'{real_api_key}', +123 'accept': 'application/json' +124 } +125 +126 response = requests.get(url, headers=headers) +127 +128 +129 if response.status_code == 200: +130 pass +131 elif response.status_code == 401: +132 raise ConnectionRefusedError( +133 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +134 ) +135 else: +136 raise ConnectionError( +137 f'Could not connect.\nHTTP Status code {response.status_code}' +138 ) +139 +140 json_data = response.json() +141 +142 if return_as_dict == True: +143 return json_data +144 +145 for conference in json_data: +146 conference_id = conference['id'] +147 conference_name = conference['name'] +148 conference_short_name = conference['short_name'] +149 conference_abbreviation = conference['abbreviation'] +150 ncaa_classification = conference['classification'] +151 +152 row_df = pd.DataFrame( +153 { +154 "conference_id": conference_id, +155 "conference_name": conference_name, +156 "conference_short_name": conference_short_name, +157 "conference_abbreviation": conference_abbreviation, +158 "ncaa_classification": ncaa_classification +159 }, index=[0] +160 ) +161 +162 conference_df = pd.concat([conference_df, row_df], ignore_index=True) +163 del conference_id, conference_name, \ +164 conference_short_name, conference_abbreviation, \ +165 ncaa_classification +166 +167 del row_df +168 +169 return conference_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, diff --git a/docs/cfbd_json_py/draft.html b/docs/cfbd_json_py/draft.html index 99ddf52..4f29309 100644 --- a/docs/cfbd_json_py/draft.html +++ b/docs/cfbd_json_py/draft.html @@ -61,7 +61,7 @@
@@ -753,160 +752,160 @@1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/07/2023 10:56 AM EDT + 2# Last Updated Date: 10/23/2023 04:09 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: draft.py 5# Purpose: Houses functions pertaining to NFL Draft data within the CFBD API. @@ -69,675 +69,674 @@7 8from datetime import datetime 9import logging - 10import time - 11import pandas as pd - 12import requests - 13from tqdm import tqdm - 14 - 15from cfbd_json_py.utls import get_cfbd_api_token + 10import pandas as pd + 11import requests + 12from tqdm import tqdm + 13 + 14from cfbd_json_py.utls import get_cfbd_api_token + 15 16 - 17 - 18def get_cfbd_nfl_teams( - 19 api_key: str = None, - 20 api_key_dir: str = None, - 21 return_as_dict: bool = False): - 22 """ - 23 Retrives a list of NFL teams from the CFBD API. - 24 - 25 Parameters - 26 ---------- - 27 `api_key` (str, optional): - 28 Semi-optional argument. - 29 If `api_key` is null, this function will attempt to load a CFBD API key - 30 from the python environment, or from a file on this computer. - 31 If `api_key` is not null, this function will automatically assume that the - 32 inputted `api_key` is a valid CFBD API key. - 33 - 34 `api_key_dir` (str, optional): - 35 Optional argument. - 36 If `api_key` is set to a string non-empty string, this variable is ignored. - 37 If `api_key_dir` is null, and `api_key` is null, - 38 this function will try to find a CFBD API key file in this user's home directory. - 39 If `api_key_dir` is set to a string, and `api_key` is null, - 40 this function will assume that `api_key_dir` is a directory, - 41 and will try to find a CFBD API key file in that directory. - 42 - 43 `return_as_dict` (bool, semi-optional): - 44 Semi-optional argument. - 45 If you want this function to return the data as a dictionary (read: JSON object), - 46 instead of a pandas `DataFrame` object, - 47 set `return_as_dict` to `True`. - 48 - 49 Usage - 50 ---------- - 51 ``` - 52 import time - 53 - 54 from cfbd_json_py.draft import get_cfbd_nfl_teams - 55 - 56 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 57 - 58 if cfbd_key != "tigersAreAwsome": - 59 print("Using the user's API key declared in this script for this example.") - 60 - 61 # Gets NFL team info from the CFBD API. - 62 print("Gets NFL team info from the CFBD API.") - 63 json_data = get_cfbd_nfl_teams(api_key=cfbd_key) - 64 print(json_data) - 65 time.sleep(5) - 66 - 67 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 68 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 69 json_data = get_cfbd_nfl_teams( - 70 api_key=cfbd_key, - 71 return_as_dict=True) - 72 print(json_data) - 73 - 74 else: - 75 # Alternatively, if the CFBD API key exists in this python environment, - 76 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 77 # you could just call these functions directly, without setting the API key - 78 # in the script. - 79 print("Using the user's API key suposedly loaded into this python environment for this example.") - 80 - 81 # Gets NFL team info from the CFBD API. - 82 print("Gets NFL team info from the CFBD API.") - 83 json_data = get_cfbd_nfl_teams() - 84 print(json_data) - 85 time.sleep(5) - 86 - 87 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 88 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 89 json_data = get_cfbd_nfl_teams(return_as_dict=True) - 90 print(json_data) - 91 - 92 ``` - 93 - 94 Returns - 95 ---------- - 96 A pandas `DataFrame` object with NFL team data, - 97 or (if `return_as_dict` is set to `True`) - 98 a dictionary object with NFL team data. - 99 -100 """ -101 -102 nfl_teams_df = pd.DataFrame() -103 row_df = pd.DataFrame() -104 url = "https://api.collegefootballdata.com/draft/teams" -105 -106 # Input validation -107 ######################################################################################################################################################################################################## -108 -109 if api_key != None: -110 real_api_key = api_key -111 del api_key -112 else: -113 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -114 -115 if real_api_key == "tigersAreAwsome": -116 raise ValueError( -117 "You actually need to change `cfbd_key` to your CFBD API key.") -118 elif "Bearer " in real_api_key: -119 pass -120 elif "Bearer" in real_api_key: -121 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -122 else: -123 real_api_key = "Bearer " + real_api_key -124 -125 headers = { -126 'Authorization': f'{real_api_key}', -127 'accept': 'application/json' -128 } -129 -130 response = requests.get(url, headers=headers) -131 time.sleep(0.1) -132 -133 if response.status_code == 200: -134 pass -135 elif response.status_code == 401: -136 raise ConnectionRefusedError( -137 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -138 ) -139 else: -140 raise ConnectionError( -141 f'Could not connect.\nHTTP Status code {response.status_code}' -142 ) -143 -144 json_data = response.json() -145 -146 if return_as_dict == True: -147 return json_data -148 -149 for nfl_team in json_data: -150 nfl_team_location = nfl_team['location'] -151 nfl_team_nickname = nfl_team['nickname'] -152 nfl_team_display_name = nfl_team['displayName'] -153 nfl_team_logo = nfl_team['logo'] -154 -155 row_df = pd.DataFrame( -156 { -157 "nfl_team_location": nfl_team_location, -158 "nfl_team_nickname": nfl_team_nickname, -159 "nfl_team_display_name": nfl_team_display_name, -160 "nfl_team_logo": nfl_team_logo -161 }, index=[0] -162 ) -163 -164 nfl_teams_df = pd.concat([nfl_teams_df, row_df], ignore_index=True) -165 -166 del nfl_team_location, nfl_team_nickname, \ -167 nfl_team_display_name, nfl_team_logo -168 -169 del row_df -170 -171 return nfl_teams_df + 17def get_cfbd_nfl_teams( + 18 api_key: str = None, + 19 api_key_dir: str = None, + 20 return_as_dict: bool = False): + 21 """ + 22 Retrives a list of NFL teams from the CFBD API. + 23 + 24 Parameters + 25 ---------- + 26 `api_key` (str, optional): + 27 Semi-optional argument. + 28 If `api_key` is null, this function will attempt to load a CFBD API key + 29 from the python environment, or from a file on this computer. + 30 If `api_key` is not null, this function will automatically assume that the + 31 inputted `api_key` is a valid CFBD API key. + 32 + 33 `api_key_dir` (str, optional): + 34 Optional argument. + 35 If `api_key` is set to am empty string, this variable is ignored. + 36 If `api_key_dir` is null, and `api_key` is null, + 37 this function will try to find a CFBD API key file in this user's home directory. + 38 If `api_key_dir` is set to a string, and `api_key` is null, + 39 this function will assume that `api_key_dir` is a directory, + 40 and will try to find a CFBD API key file in that directory. + 41 + 42 `return_as_dict` (bool, semi-optional): + 43 Semi-optional argument. + 44 If you want this function to return the data as a dictionary (read: JSON object), + 45 instead of a pandas `DataFrame` object, + 46 set `return_as_dict` to `True`. + 47 + 48 Usage + 49 ---------- + 50 ``` + 51 import time + 52 + 53 from cfbd_json_py.draft import get_cfbd_nfl_teams + 54 + 55 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 56 + 57 if cfbd_key != "tigersAreAwsome": + 58 print("Using the user's API key declared in this script for this example.") + 59 + 60 # Gets NFL team info from the CFBD API. + 61 print("Gets NFL team info from the CFBD API.") + 62 json_data = get_cfbd_nfl_teams(api_key=cfbd_key) + 63 print(json_data) + 64 time.sleep(5) + 65 + 66 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 67 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 68 json_data = get_cfbd_nfl_teams( + 69 api_key=cfbd_key, + 70 return_as_dict=True) + 71 print(json_data) + 72 + 73 else: + 74 # Alternatively, if the CFBD API key exists in this python environment, + 75 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 76 # you could just call these functions directly, without setting the API key + 77 # in the script. + 78 print("Using the user's API key suposedly loaded into this python environment for this example.") + 79 + 80 # Gets NFL team info from the CFBD API. + 81 print("Gets NFL team info from the CFBD API.") + 82 json_data = get_cfbd_nfl_teams() + 83 print(json_data) + 84 time.sleep(5) + 85 + 86 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 87 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 88 json_data = get_cfbd_nfl_teams(return_as_dict=True) + 89 print(json_data) + 90 + 91 ``` + 92 + 93 Returns + 94 ---------- + 95 A pandas `DataFrame` object with NFL team data, + 96 or (if `return_as_dict` is set to `True`) + 97 a dictionary object with NFL team data. + 98 + 99 """ +100 +101 nfl_teams_df = pd.DataFrame() +102 row_df = pd.DataFrame() +103 url = "https://api.collegefootballdata.com/draft/teams" +104 +105 # Input validation +106 ######################################################################################################################################################################################################## +107 +108 if api_key != None: +109 real_api_key = api_key +110 del api_key +111 else: +112 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +113 +114 if real_api_key == "tigersAreAwsome": +115 raise ValueError( +116 "You actually need to change `cfbd_key` to your CFBD API key.") +117 elif "Bearer " in real_api_key: +118 pass +119 elif "Bearer" in real_api_key: +120 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +121 else: +122 real_api_key = "Bearer " + real_api_key +123 +124 headers = { +125 'Authorization': f'{real_api_key}', +126 'accept': 'application/json' +127 } +128 +129 response = requests.get(url, headers=headers) +130 +131 +132 if response.status_code == 200: +133 pass +134 elif response.status_code == 401: +135 raise ConnectionRefusedError( +136 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +137 ) +138 else: +139 raise ConnectionError( +140 f'Could not connect.\nHTTP Status code {response.status_code}' +141 ) +142 +143 json_data = response.json() +144 +145 if return_as_dict == True: +146 return json_data +147 +148 for nfl_team in json_data: +149 nfl_team_location = nfl_team['location'] +150 nfl_team_nickname = nfl_team['nickname'] +151 nfl_team_display_name = nfl_team['displayName'] +152 nfl_team_logo = nfl_team['logo'] +153 +154 row_df = pd.DataFrame( +155 { +156 "nfl_team_location": nfl_team_location, +157 "nfl_team_nickname": nfl_team_nickname, +158 "nfl_team_display_name": nfl_team_display_name, +159 "nfl_team_logo": nfl_team_logo +160 }, index=[0] +161 ) +162 +163 nfl_teams_df = pd.concat([nfl_teams_df, row_df], ignore_index=True) +164 +165 del nfl_team_location, nfl_team_nickname, \ +166 nfl_team_display_name, nfl_team_logo +167 +168 del row_df +169 +170 return nfl_teams_df +171 172 -173 -174def get_cfbd_nfl_positions( -175 api_key: str = None, -176 api_key_dir: str = None, -177 return_as_dict: bool = False): -178 """ -179 Retrives a list of player positions for the NFL Draft from the CFBD API. -180 -181 Parameters -182 ---------- -183 `api_key` (str, optional): -184 Semi-optional argument. -185 If `api_key` is null, this function will attempt to load a CFBD API key -186 from the python environment, or from a file on this computer. -187 If `api_key` is not null, this function will automatically assume that the -188 inputted `api_key` is a valid CFBD API key. -189 -190 `api_key_dir` (str, optional): -191 Optional argument. -192 If `api_key` is set to a string non-empty string, this variable is ignored. -193 If `api_key_dir` is null, and `api_key` is null, -194 this function will try to find a CFBD API key file in this user's home directory. -195 If `api_key_dir` is set to a string, and `api_key` is null, -196 this function will assume that `api_key_dir` is a directory, -197 and will try to find a CFBD API key file in that directory. -198 -199 `return_as_dict` (bool, semi-optional): -200 Semi-optional argument. -201 If you want this function to return the data as a dictionary (read: JSON object), -202 instead of a pandas `DataFrame` object, -203 set `return_as_dict` to `True`. -204 -205 Usage -206 ---------- -207 ``` -208 import time -209 -210 from cfbd_json_py.draft import get_cfbd_nfl_positions -211 -212 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -213 -214 if cfbd_key != "tigersAreAwsome": -215 print("Using the user's API key declared in this script for this example.") -216 -217 # Gets a list of player positions for the NFL Draft from the CFBD API. -218 print("Gets a list of player positions for the NFL Draft from the CFBD API.") -219 json_data = get_cfbd_nfl_positions(api_key=cfbd_key) -220 print(json_data) -221 time.sleep(5) -222 -223 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -224 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -225 json_data = get_cfbd_nfl_positions( -226 api_key=cfbd_key, -227 return_as_dict=True) -228 print(json_data) -229 -230 else: -231 # Alternatively, if the CFBD API key exists in this python environment, -232 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -233 # you could just call these functions directly, without setting the API key -234 # in the script. -235 print("Using the user's API key suposedly loaded into this python environment for this example.") -236 -237 # Gets a list of player positions for the NFL Draft from the CFBD API. -238 print("Gets a list of player positions for the NFL Draft from the CFBD API.") -239 json_data = get_cfbd_nfl_positions() -240 print(json_data) -241 time.sleep(5) -242 -243 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -244 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -245 json_data = get_cfbd_nfl_positions(return_as_dict=True) -246 print(json_data) -247 -248 ``` -249 Returns -250 ---------- -251 A pandas `DataFrame` object with player position data, -252 or (if `return_as_dict` is set to `True`) -253 a dictionary object with player position data. -254 -255 """ -256 -257 positions_df = pd.DataFrame() -258 row_df = pd.DataFrame() -259 url = "https://api.collegefootballdata.com/draft/positions" -260 -261 # Input validation -262 ######################################################################################################################################################################################################## -263 -264 if api_key != None: -265 real_api_key = api_key -266 del api_key -267 else: -268 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -269 -270 if real_api_key == "tigersAreAwsome": -271 raise ValueError( -272 "You actually need to change `cfbd_key` to your CFBD API key.") -273 elif "Bearer " in real_api_key: -274 pass -275 elif "Bearer" in real_api_key: -276 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -277 else: -278 real_api_key = "Bearer " + real_api_key -279 -280 headers = { -281 'Authorization': f'{real_api_key}', -282 'accept': 'application/json' -283 } -284 -285 response = requests.get(url, headers=headers) -286 time.sleep(0.1) -287 -288 if response.status_code == 200: -289 pass -290 elif response.status_code == 401: -291 raise ConnectionRefusedError( -292 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -293 ) -294 else: -295 raise ConnectionError( -296 f'Could not connect.\nHTTP Status code {response.status_code}' -297 ) -298 -299 json_data = response.json() -300 -301 if return_as_dict == True: -302 return json_data -303 -304 for p in json_data: -305 position_name = p['name'] -306 position_abbreviation = p['abbreviation'] -307 -308 row_df = pd.DataFrame( -309 { -310 "position_name": position_name, -311 "position_abbreviation": position_abbreviation -312 }, index=[0] -313 ) -314 positions_df = pd.concat([positions_df, row_df], ignore_index=True) -315 -316 del position_name, position_abbreviation -317 del row_df -318 -319 return positions_df +173def get_cfbd_nfl_positions( +174 api_key: str = None, +175 api_key_dir: str = None, +176 return_as_dict: bool = False): +177 """ +178 Retrives a list of player positions for the NFL Draft from the CFBD API. +179 +180 Parameters +181 ---------- +182 `api_key` (str, optional): +183 Semi-optional argument. +184 If `api_key` is null, this function will attempt to load a CFBD API key +185 from the python environment, or from a file on this computer. +186 If `api_key` is not null, this function will automatically assume that the +187 inputted `api_key` is a valid CFBD API key. +188 +189 `api_key_dir` (str, optional): +190 Optional argument. +191 If `api_key` is set to am empty string, this variable is ignored. +192 If `api_key_dir` is null, and `api_key` is null, +193 this function will try to find a CFBD API key file in this user's home directory. +194 If `api_key_dir` is set to a string, and `api_key` is null, +195 this function will assume that `api_key_dir` is a directory, +196 and will try to find a CFBD API key file in that directory. +197 +198 `return_as_dict` (bool, semi-optional): +199 Semi-optional argument. +200 If you want this function to return the data as a dictionary (read: JSON object), +201 instead of a pandas `DataFrame` object, +202 set `return_as_dict` to `True`. +203 +204 Usage +205 ---------- +206 ``` +207 import time +208 +209 from cfbd_json_py.draft import get_cfbd_nfl_positions +210 +211 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +212 +213 if cfbd_key != "tigersAreAwsome": +214 print("Using the user's API key declared in this script for this example.") +215 +216 # Gets a list of player positions for the NFL Draft from the CFBD API. +217 print("Gets a list of player positions for the NFL Draft from the CFBD API.") +218 json_data = get_cfbd_nfl_positions(api_key=cfbd_key) +219 print(json_data) +220 time.sleep(5) +221 +222 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +223 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +224 json_data = get_cfbd_nfl_positions( +225 api_key=cfbd_key, +226 return_as_dict=True) +227 print(json_data) +228 +229 else: +230 # Alternatively, if the CFBD API key exists in this python environment, +231 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +232 # you could just call these functions directly, without setting the API key +233 # in the script. +234 print("Using the user's API key suposedly loaded into this python environment for this example.") +235 +236 # Gets a list of player positions for the NFL Draft from the CFBD API. +237 print("Gets a list of player positions for the NFL Draft from the CFBD API.") +238 json_data = get_cfbd_nfl_positions() +239 print(json_data) +240 time.sleep(5) +241 +242 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +243 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +244 json_data = get_cfbd_nfl_positions(return_as_dict=True) +245 print(json_data) +246 +247 ``` +248 Returns +249 ---------- +250 A pandas `DataFrame` object with player position data, +251 or (if `return_as_dict` is set to `True`) +252 a dictionary object with player position data. +253 +254 """ +255 +256 positions_df = pd.DataFrame() +257 row_df = pd.DataFrame() +258 url = "https://api.collegefootballdata.com/draft/positions" +259 +260 # Input validation +261 ######################################################################################################################################################################################################## +262 +263 if api_key != None: +264 real_api_key = api_key +265 del api_key +266 else: +267 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +268 +269 if real_api_key == "tigersAreAwsome": +270 raise ValueError( +271 "You actually need to change `cfbd_key` to your CFBD API key.") +272 elif "Bearer " in real_api_key: +273 pass +274 elif "Bearer" in real_api_key: +275 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +276 else: +277 real_api_key = "Bearer " + real_api_key +278 +279 headers = { +280 'Authorization': f'{real_api_key}', +281 'accept': 'application/json' +282 } +283 +284 response = requests.get(url, headers=headers) +285 +286 +287 if response.status_code == 200: +288 pass +289 elif response.status_code == 401: +290 raise ConnectionRefusedError( +291 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +292 ) +293 else: +294 raise ConnectionError( +295 f'Could not connect.\nHTTP Status code {response.status_code}' +296 ) +297 +298 json_data = response.json() +299 +300 if return_as_dict == True: +301 return json_data +302 +303 for p in json_data: +304 position_name = p['name'] +305 position_abbreviation = p['abbreviation'] +306 +307 row_df = pd.DataFrame( +308 { +309 "position_name": position_name, +310 "position_abbreviation": position_abbreviation +311 }, index=[0] +312 ) +313 positions_df = pd.concat([positions_df, row_df], ignore_index=True) +314 +315 del position_name, position_abbreviation +316 del row_df +317 +318 return positions_df +319 320 -321 -322def get_cfbd_nfl_draft_info( -323 api_key: str = None, -324 api_key_dir: str = None, -325 season: int = None, -326 nfl_team: str = None, -327 college: str = None, -328 conference_abv: str = None, -329 position: str = None, -330 return_as_dict: bool = False): -331 """ -332 Retrives a list of actual NFL Draft selections from the CFBD API. -333 -334 Parameters -335 ---------- -336 -337 `api_key` (str, optional): -338 Semi-optional argument. -339 If `api_key` is null, this function will attempt to load a CFBD API key -340 from the python environment, or from a file on this computer. -341 If `api_key` is not null, this function will automatically assume that the -342 inputted `api_key` is a valid CFBD API key. -343 -344 `api_key_dir` (str, optional): -345 Optional argument. -346 If `api_key` is set to a string non-empty string, this variable is ignored. -347 If `api_key_dir` is null, and `api_key` is null, -348 this function will try to find a CFBD API key file in this user's home directory. -349 If `api_key_dir` is set to a string, and `api_key` is null, -350 this function will assume that `api_key_dir` is a directory, -351 and will try to find a CFBD API key file in that directory. -352 -353 The following paramaters are optional, but it is highly reccomended to not call this function -354 withiout settting one of these five optional paramaters to a non-null value. -355 -356 `season` (int, semi-optional): -357 Semi-Optional argument. -358 This is the season you want NFL Draft information for. For example, if you only want -359 data for the 2020 NFL Draft, set `season` to `2020`. -360 -361 `nfl_team` (str, optional): -362 Semi-Optional argument. -363 If you only want NFL Draft selections from a specific NFL team, set `nfl_team` to the -364 name of that team. For example, if you want to only get NFL Draft information for -365 draft picks made by the Cincinnati Bengals, set `nfl_team` to `Cincinnati`. -366 -367 `college` (str, optional): -368 Semi-Optional argument. -369 If you only want NFL Draft selections from a specific CFB team, set `college` to the -370 name of that team. For example, if you want to only get NFL Draft information for -371 draft picks from the Clemson Tigers Football Program, set `college` to `Clemson`. -372 -373 `conference` (str, optional): -374 Semi-Optional argument. -375 If you only want NFL Draft selections from a specific CFB confrence, set `conference` to the abbreviation of that confrence. -376 A list of CFBD API confrence abbreviations can be found in the `conference_abbreviation` column from -377 the pandas DataFrame that is returned by calling `cfbd_json_py.conferences.get_cfbd_conference_info()`. -378 For example, if you want to only get NFL Draft information for -379 draft picks that played in the Big 12, set `confrence` to `B12`. -380 -381 `position` (str, optional): -382 Semi-Optional argument. -383 If you only want NFL Draft selections who played a specific position, -384 set `position` to that position's abbreviation. -385 A list of CFBD API positions can be found in the `position_abbreviation` column from -386 the pandas DataFrame that is returned by calling `cfbd_json_py.draft.get_cfbd_nfl_positions()`. -387 -388 `return_as_dict` (bool, semi-optional): -389 Semi-optional argument. -390 If you want this function to return the data as a dictionary (read: JSON object), -391 instead of a pandas `DataFrame` object, -392 set `return_as_dict` to `True`. -393 Usage -394 ---------- -395 -396 ``` -397 import time -398 -399 from cfbd_json_py.draft import get_cfbd_nfl_draft_info -400 -401 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -402 -403 if cfbd_key != "tigersAreAwsome": -404 print("Using the user's API key declared in this script for this example.") -405 -406 # Get NFL Draft selections from the 2020 NFL Draft. -407 print("Get NFL Draft selections from the 2020 NFL Draft.") -408 json_data = get_cfbd_nfl_draft_info( -409 api_key=cfbd_key, -410 season=2020 -411 ) -412 print(json_data) -413 time.sleep(5) -414 -415 # Get NFL Draft selections from the 2020 NFL Draft made by the -416 # 2020 Cincinnati Bengals. -417 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") -418 json_data = get_cfbd_nfl_draft_info( -419 api_key=cfbd_key, -420 season=2020, -421 nfl_team="Cincinnati" -422 ) -423 print(json_data) -424 time.sleep(5) -425 -426 # Get NFL Draft selections from the 2020 NFL Draft made involving -427 # Clemson Tigers football players. -428 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") -429 json_data = get_cfbd_nfl_draft_info( -430 api_key=cfbd_key, -431 season=2020, -432 college="Clemson" -433 ) -434 print(json_data) -435 time.sleep(5) -436 -437 # Get NFL Draft selections from the 2020 NFL Draft made involving -438 # players who played in the Southeastern Confrence (SEC). -439 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") -440 json_data = get_cfbd_nfl_draft_info( -441 api_key=cfbd_key, -442 season=2020, -443 conference="SEC" -444 ) -445 print(json_data) -446 time.sleep(5) -447 -448 # Get NFL Draft selections from the 2020 NFL Draft made -449 # where the selected player was a QB in college. -450 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") -451 json_data = get_cfbd_nfl_draft_info( -452 api_key=cfbd_key, -453 season=2020, -454 position="QB" -455 ) -456 print(json_data) -457 time.sleep(5) -458 -459 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -460 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -461 json_data = get_cfbd_nfl_draft_info( -462 season=2020, -463 position="QB", -464 api_key=cfbd_key, -465 return_as_dict=True -466 ) -467 print(json_data) -468 -469 else: -470 # Alternatively, if the CFBD API key exists in this python environment, -471 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -472 # you could just call these functions directly, without setting the API key -473 # in the script. -474 print("Using the user's API key suposedly loaded into this python environment for this example.") -475 -476 # Get NFL Draft selections from the 2020 NFL Draft. -477 print("Get NFL Draft selections from the 2020 NFL Draft.") -478 json_data = get_cfbd_nfl_draft_info(season=2020) -479 print(json_data) -480 time.sleep(5) -481 -482 # Get NFL Draft selections from the 2020 NFL Draft made by the -483 # 2020 Cincinnati Bengals. -484 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") -485 json_data = get_cfbd_nfl_draft_info( -486 season=2020, -487 nfl_team="Cincinnati" -488 ) -489 print(json_data) -490 time.sleep(5) -491 -492 # Get NFL Draft selections from the 2020 NFL Draft made involving -493 # Clemson Tigers football players. -494 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") -495 json_data = get_cfbd_nfl_draft_info( -496 season=2020, -497 college="Clemson" -498 ) -499 print(json_data) -500 time.sleep(5) -501 -502 # Get NFL Draft selections from the 2020 NFL Draft made involving -503 # players who played in the Southeastern Confrence (SEC). -504 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") -505 json_data = get_cfbd_nfl_draft_info( -506 season=2020, -507 conference="SEC" -508 ) -509 print(json_data) -510 time.sleep(5) -511 -512 # Get NFL Draft selections from the 2020 NFL Draft made -513 # where the selected player was a QB in college. -514 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") -515 json_data = get_cfbd_nfl_draft_info( -516 season=2020, -517 position="QB" -518 ) -519 print(json_data) -520 time.sleep(5) -521 -522 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -523 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -524 json_data = get_cfbd_nfl_draft_info( -525 season=2020, -526 position="QB", -527 return_as_dict=True -528 ) -529 print(json_data) -530 ``` -531 -532 Returns -533 ---------- -534 A pandas `DataFrame` object with NFL Draft selection data, -535 or (if `return_as_dict` is set to `True`) -536 a dictionary object with NFL Draft selection data. -537 -538 """ -539 now = datetime.now() -540 nfl_draft_df = pd.DataFrame() -541 row_df = pd.DataFrame() -542 url = "https://api.collegefootballdata.com/draft/picks" -543 -544 # Input validation -545 ######################################################################################################################################################################################################## -546 -547 if api_key != None: -548 real_api_key = api_key -549 del api_key -550 else: -551 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -552 -553 if real_api_key == "tigersAreAwsome": -554 raise ValueError( -555 "You actually need to change `cfbd_key` to your CFBD API key.") -556 elif "Bearer " in real_api_key: -557 pass -558 elif "Bearer" in real_api_key: -559 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -560 else: -561 real_api_key = "Bearer " + real_api_key -562 -563 if season == None and nfl_team == None and college == None and conference_abv == None: -564 logging.warning( -565 "Not specifying a `season`, `nfl_team`, `college`, or `confrence` will still result in a successful get request (assuming the API key is valid)" + -566 ", but this is not a recomended method of calling this function.") -567 -568 if season < 1936 or season > now.year: -569 raise ValueError( -570 f"`season` must be an integer between 1936 and {now.year}.\nYou entered:\n{season}") -571 -572 # URL builder -573 ######################################################################################################################################################################################################## -574 url_elements = 0 -575 -576 if season != None and url_elements == 0: -577 url += f"?year={season}" -578 url_elements += 1 -579 elif season != None: -580 url += f"&year={season}" -581 url_elements += 1 -582 -583 if nfl_team != None and url_elements == 0: -584 url += f"?nflTeam={nfl_team}" # nfl_team = "Cincinnati", not "CIN" -585 url_elements += 1 -586 elif nfl_team != None: -587 url += f"&nflTeam={nfl_team}" -588 url_elements += 1 -589 -590 if college != None and url_elements == 0: -591 url += f"?college={college}" -592 url_elements += 1 -593 elif college != None: -594 url += f"&college={college}" -595 url_elements += 1 -596 -597 if conference_abv != None and url_elements == 0: -598 # conference = "SEC", not "Southeastern Confrence" -599 url += f"?conference={conference_abv}" -600 url_elements += 1 -601 elif conference_abv != None: -602 url += f"&conference={conference_abv}" -603 url_elements += 1 -604 -605 if position != None and url_elements == 0: -606 url += f"?position={position}" -607 url_elements += 1 -608 elif position != None: -609 url += f"&position={position}" -610 url_elements += 1 -611 -612 headers = { -613 'Authorization': f'{real_api_key}', -614 'accept': 'application/json' -615 } -616 -617 response = requests.get(url, headers=headers) -618 time.sleep(0.1) -619 -620 if response.status_code == 200: -621 pass -622 elif response.status_code == 401: -623 raise ConnectionRefusedError( -624 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -625 ) -626 else: -627 raise ConnectionError( -628 f'Could not connect.\nHTTP Status code {response.status_code}' -629 ) -630 -631 json_data = response.json() -632 -633 if return_as_dict == True: -634 return json_data -635 -636 for p in tqdm(json_data): -637 college_athlete_id = p['collegeAthleteId'] -638 row_df = pd.DataFrame( -639 { -640 "college_athlete_id": college_athlete_id -641 }, index=[0] -642 ) -643 del college_athlete_id -644 -645 row_df['nfl_athlete_id'] = p['nflAthleteId'] -646 row_df['college_id'] = p['collegeId'] -647 row_df['college_team'] = p['collegeTeam'] -648 row_df['college_conference'] = p['collegeConference'] -649 row_df['nfl_team'] = p['nflTeam'] -650 row_df['draft_year'] = p['year'] -651 row_df['draft_pick_overall'] = p['overall'] -652 row_df['draft_round'] = p['round'] -653 row_df['draft_round_pick'] = p['pick'] -654 row_df['player_name'] = p['name'] -655 row_df['player_position'] = p['position'] -656 row_df['player_height'] = p['height'] -657 row_df['player_weight'] = p['weight'] -658 row_df['pre_draft_ranking'] = p['preDraftRanking'] -659 row_df['pre_draft_position_ranking'] = p['preDraftPositionRanking'] -660 row_df['pre_draft_grade'] = p['preDraftGrade'] -661 row_df['player_hometown_city'] = p['hometownInfo']['city'] -662 row_df['player_hometown_state'] = p['hometownInfo']['state'] -663 row_df['player_hometown_country'] = p['hometownInfo']['country'] -664 row_df['player_hometown_latitude'] = p['hometownInfo']['latitude'] -665 row_df['player_hometown_longitude'] = p['hometownInfo']['longitude'] -666 row_df['player_hometown_county_fips'] = p['hometownInfo']['countyFips'] -667 -668 nfl_draft_df = pd.concat([nfl_draft_df, row_df], ignore_index=True) -669 del row_df -670 -671 if len(nfl_draft_df) == 0: -672 logging.error( -673 "The CFBD API accepted your inputs, " + -674 "but found no data within your specified input paramaters." + -675 " Please double check your input paramaters." -676 ) -677 -678 return nfl_draft_df +321def get_cfbd_nfl_draft_info( +322 api_key: str = None, +323 api_key_dir: str = None, +324 season: int = None, +325 nfl_team: str = None, +326 college: str = None, +327 conference_abv: str = None, +328 position: str = None, +329 return_as_dict: bool = False): +330 """ +331 Retrives a list of actual NFL Draft selections from the CFBD API. +332 +333 Parameters +334 ---------- +335 +336 `api_key` (str, optional): +337 Semi-optional argument. +338 If `api_key` is null, this function will attempt to load a CFBD API key +339 from the python environment, or from a file on this computer. +340 If `api_key` is not null, this function will automatically assume that the +341 inputted `api_key` is a valid CFBD API key. +342 +343 `api_key_dir` (str, optional): +344 Optional argument. +345 If `api_key` is set to am empty string, this variable is ignored. +346 If `api_key_dir` is null, and `api_key` is null, +347 this function will try to find a CFBD API key file in this user's home directory. +348 If `api_key_dir` is set to a string, and `api_key` is null, +349 this function will assume that `api_key_dir` is a directory, +350 and will try to find a CFBD API key file in that directory. +351 +352 The following paramaters are optional, but it is highly reccomended to not call this function +353 withiout settting one of these five optional paramaters to a non-null value. +354 +355 `season` (int, semi-optional): +356 Semi-Optional argument. +357 This is the season you want NFL Draft information for. For example, if you only want +358 data for the 2020 NFL Draft, set `season` to `2020`. +359 +360 `nfl_team` (str, optional): +361 Semi-Optional argument. +362 If you only want NFL Draft selections from a specific NFL team, set `nfl_team` to the +363 name of that team. For example, if you want to only get NFL Draft information for +364 draft picks made by the Cincinnati Bengals, set `nfl_team` to `Cincinnati`. +365 +366 `college` (str, optional): +367 Semi-Optional argument. +368 If you only want NFL Draft selections from a specific CFB team, set `college` to the +369 name of that team. For example, if you want to only get NFL Draft information for +370 draft picks from the Clemson Tigers Football Program, set `college` to `Clemson`. +371 +372 `conference` (str, optional): +373 Semi-Optional argument. +374 If you only want NFL Draft selections from a specific CFB confrence, set `conference` to the abbreviation of that confrence. +375 A list of CFBD API confrence abbreviations can be found in the `conference_abbreviation` column from +376 the pandas DataFrame that is returned by calling `cfbd_json_py.conferences.get_cfbd_conference_info()`. +377 For example, if you want to only get NFL Draft information for +378 draft picks that played in the Big 12, set `confrence` to `B12`. +379 +380 `position` (str, optional): +381 Semi-Optional argument. +382 If you only want NFL Draft selections who played a specific position, +383 set `position` to that position's abbreviation. +384 A list of CFBD API positions can be found in the `position_abbreviation` column from +385 the pandas DataFrame that is returned by calling `cfbd_json_py.draft.get_cfbd_nfl_positions()`. +386 +387 `return_as_dict` (bool, semi-optional): +388 Semi-optional argument. +389 If you want this function to return the data as a dictionary (read: JSON object), +390 instead of a pandas `DataFrame` object, +391 set `return_as_dict` to `True`. +392 Usage +393 ---------- +394 +395 ``` +396 import time +397 +398 from cfbd_json_py.draft import get_cfbd_nfl_draft_info +399 +400 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +401 +402 if cfbd_key != "tigersAreAwsome": +403 print("Using the user's API key declared in this script for this example.") +404 +405 # Get NFL Draft selections from the 2020 NFL Draft. +406 print("Get NFL Draft selections from the 2020 NFL Draft.") +407 json_data = get_cfbd_nfl_draft_info( +408 api_key=cfbd_key, +409 season=2020 +410 ) +411 print(json_data) +412 time.sleep(5) +413 +414 # Get NFL Draft selections from the 2020 NFL Draft made by the +415 # 2020 Cincinnati Bengals. +416 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") +417 json_data = get_cfbd_nfl_draft_info( +418 api_key=cfbd_key, +419 season=2020, +420 nfl_team="Cincinnati" +421 ) +422 print(json_data) +423 time.sleep(5) +424 +425 # Get NFL Draft selections from the 2020 NFL Draft made involving +426 # Clemson Tigers football players. +427 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") +428 json_data = get_cfbd_nfl_draft_info( +429 api_key=cfbd_key, +430 season=2020, +431 college="Clemson" +432 ) +433 print(json_data) +434 time.sleep(5) +435 +436 # Get NFL Draft selections from the 2020 NFL Draft made involving +437 # players who played in the Southeastern Confrence (SEC). +438 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") +439 json_data = get_cfbd_nfl_draft_info( +440 api_key=cfbd_key, +441 season=2020, +442 conference="SEC" +443 ) +444 print(json_data) +445 time.sleep(5) +446 +447 # Get NFL Draft selections from the 2020 NFL Draft made +448 # where the selected player was a QB in college. +449 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") +450 json_data = get_cfbd_nfl_draft_info( +451 api_key=cfbd_key, +452 season=2020, +453 position="QB" +454 ) +455 print(json_data) +456 time.sleep(5) +457 +458 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +459 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +460 json_data = get_cfbd_nfl_draft_info( +461 season=2020, +462 position="QB", +463 api_key=cfbd_key, +464 return_as_dict=True +465 ) +466 print(json_data) +467 +468 else: +469 # Alternatively, if the CFBD API key exists in this python environment, +470 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +471 # you could just call these functions directly, without setting the API key +472 # in the script. +473 print("Using the user's API key suposedly loaded into this python environment for this example.") +474 +475 # Get NFL Draft selections from the 2020 NFL Draft. +476 print("Get NFL Draft selections from the 2020 NFL Draft.") +477 json_data = get_cfbd_nfl_draft_info(season=2020) +478 print(json_data) +479 time.sleep(5) +480 +481 # Get NFL Draft selections from the 2020 NFL Draft made by the +482 # 2020 Cincinnati Bengals. +483 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") +484 json_data = get_cfbd_nfl_draft_info( +485 season=2020, +486 nfl_team="Cincinnati" +487 ) +488 print(json_data) +489 time.sleep(5) +490 +491 # Get NFL Draft selections from the 2020 NFL Draft made involving +492 # Clemson Tigers football players. +493 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") +494 json_data = get_cfbd_nfl_draft_info( +495 season=2020, +496 college="Clemson" +497 ) +498 print(json_data) +499 time.sleep(5) +500 +501 # Get NFL Draft selections from the 2020 NFL Draft made involving +502 # players who played in the Southeastern Confrence (SEC). +503 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") +504 json_data = get_cfbd_nfl_draft_info( +505 season=2020, +506 conference="SEC" +507 ) +508 print(json_data) +509 time.sleep(5) +510 +511 # Get NFL Draft selections from the 2020 NFL Draft made +512 # where the selected player was a QB in college. +513 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") +514 json_data = get_cfbd_nfl_draft_info( +515 season=2020, +516 position="QB" +517 ) +518 print(json_data) +519 time.sleep(5) +520 +521 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +522 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +523 json_data = get_cfbd_nfl_draft_info( +524 season=2020, +525 position="QB", +526 return_as_dict=True +527 ) +528 print(json_data) +529 ``` +530 +531 Returns +532 ---------- +533 A pandas `DataFrame` object with NFL Draft selection data, +534 or (if `return_as_dict` is set to `True`) +535 a dictionary object with NFL Draft selection data. +536 +537 """ +538 now = datetime.now() +539 nfl_draft_df = pd.DataFrame() +540 row_df = pd.DataFrame() +541 url = "https://api.collegefootballdata.com/draft/picks" +542 +543 # Input validation +544 ######################################################################################################################################################################################################## +545 +546 if api_key != None: +547 real_api_key = api_key +548 del api_key +549 else: +550 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +551 +552 if real_api_key == "tigersAreAwsome": +553 raise ValueError( +554 "You actually need to change `cfbd_key` to your CFBD API key.") +555 elif "Bearer " in real_api_key: +556 pass +557 elif "Bearer" in real_api_key: +558 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +559 else: +560 real_api_key = "Bearer " + real_api_key +561 +562 if season == None and nfl_team == None and college == None and conference_abv == None: +563 logging.warning( +564 "Not specifying a `season`, `nfl_team`, `college`, or `confrence` will still result in a successful get request (assuming the API key is valid)" + +565 ", but this is not a recomended method of calling this function.") +566 +567 if season < 1936 or season > now.year: +568 raise ValueError( +569 f"`season` must be an integer between 1936 and {now.year}.\nYou entered:\n{season}") +570 +571 # URL builder +572 ######################################################################################################################################################################################################## +573 url_elements = 0 +574 +575 if season != None and url_elements == 0: +576 url += f"?year={season}" +577 url_elements += 1 +578 elif season != None: +579 url += f"&year={season}" +580 url_elements += 1 +581 +582 if nfl_team != None and url_elements == 0: +583 url += f"?nflTeam={nfl_team}" # nfl_team = "Cincinnati", not "CIN" +584 url_elements += 1 +585 elif nfl_team != None: +586 url += f"&nflTeam={nfl_team}" +587 url_elements += 1 +588 +589 if college != None and url_elements == 0: +590 url += f"?college={college}" +591 url_elements += 1 +592 elif college != None: +593 url += f"&college={college}" +594 url_elements += 1 +595 +596 if conference_abv != None and url_elements == 0: +597 # conference = "SEC", not "Southeastern Confrence" +598 url += f"?conference={conference_abv}" +599 url_elements += 1 +600 elif conference_abv != None: +601 url += f"&conference={conference_abv}" +602 url_elements += 1 +603 +604 if position != None and url_elements == 0: +605 url += f"?position={position}" +606 url_elements += 1 +607 elif position != None: +608 url += f"&position={position}" +609 url_elements += 1 +610 +611 headers = { +612 'Authorization': f'{real_api_key}', +613 'accept': 'application/json' +614 } +615 +616 response = requests.get(url, headers=headers) +617 +618 +619 if response.status_code == 200: +620 pass +621 elif response.status_code == 401: +622 raise ConnectionRefusedError( +623 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +624 ) +625 else: +626 raise ConnectionError( +627 f'Could not connect.\nHTTP Status code {response.status_code}' +628 ) +629 +630 json_data = response.json() +631 +632 if return_as_dict == True: +633 return json_data +634 +635 for p in tqdm(json_data): +636 college_athlete_id = p['collegeAthleteId'] +637 row_df = pd.DataFrame( +638 { +639 "college_athlete_id": college_athlete_id +640 }, index=[0] +641 ) +642 del college_athlete_id +643 +644 row_df['nfl_athlete_id'] = p['nflAthleteId'] +645 row_df['college_id'] = p['collegeId'] +646 row_df['college_team'] = p['collegeTeam'] +647 row_df['college_conference'] = p['collegeConference'] +648 row_df['nfl_team'] = p['nflTeam'] +649 row_df['draft_year'] = p['year'] +650 row_df['draft_pick_overall'] = p['overall'] +651 row_df['draft_round'] = p['round'] +652 row_df['draft_round_pick'] = p['pick'] +653 row_df['player_name'] = p['name'] +654 row_df['player_position'] = p['position'] +655 row_df['player_height'] = p['height'] +656 row_df['player_weight'] = p['weight'] +657 row_df['pre_draft_ranking'] = p['preDraftRanking'] +658 row_df['pre_draft_position_ranking'] = p['preDraftPositionRanking'] +659 row_df['pre_draft_grade'] = p['preDraftGrade'] +660 row_df['player_hometown_city'] = p['hometownInfo']['city'] +661 row_df['player_hometown_state'] = p['hometownInfo']['state'] +662 row_df['player_hometown_country'] = p['hometownInfo']['country'] +663 row_df['player_hometown_latitude'] = p['hometownInfo']['latitude'] +664 row_df['player_hometown_longitude'] = p['hometownInfo']['longitude'] +665 row_df['player_hometown_county_fips'] = p['hometownInfo']['countyFips'] +666 +667 nfl_draft_df = pd.concat([nfl_draft_df, row_df], ignore_index=True) +668 del row_df +669 +670 if len(nfl_draft_df) == 0: +671 logging.error( +672 "The CFBD API accepted your inputs, " + +673 "but found no data within your specified input paramaters." + +674 " Please double check your input paramaters." +675 ) +676 +677 return nfl_draft_df
19def get_cfbd_nfl_teams( - 20 api_key: str = None, - 21 api_key_dir: str = None, - 22 return_as_dict: bool = False): - 23 """ - 24 Retrives a list of NFL teams from the CFBD API. - 25 - 26 Parameters - 27 ---------- - 28 `api_key` (str, optional): - 29 Semi-optional argument. - 30 If `api_key` is null, this function will attempt to load a CFBD API key - 31 from the python environment, or from a file on this computer. - 32 If `api_key` is not null, this function will automatically assume that the - 33 inputted `api_key` is a valid CFBD API key. - 34 - 35 `api_key_dir` (str, optional): - 36 Optional argument. - 37 If `api_key` is set to a string non-empty string, this variable is ignored. - 38 If `api_key_dir` is null, and `api_key` is null, - 39 this function will try to find a CFBD API key file in this user's home directory. - 40 If `api_key_dir` is set to a string, and `api_key` is null, - 41 this function will assume that `api_key_dir` is a directory, - 42 and will try to find a CFBD API key file in that directory. - 43 - 44 `return_as_dict` (bool, semi-optional): - 45 Semi-optional argument. - 46 If you want this function to return the data as a dictionary (read: JSON object), - 47 instead of a pandas `DataFrame` object, - 48 set `return_as_dict` to `True`. - 49 - 50 Usage - 51 ---------- - 52 ``` - 53 import time - 54 - 55 from cfbd_json_py.draft import get_cfbd_nfl_teams - 56 - 57 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 58 - 59 if cfbd_key != "tigersAreAwsome": - 60 print("Using the user's API key declared in this script for this example.") - 61 - 62 # Gets NFL team info from the CFBD API. - 63 print("Gets NFL team info from the CFBD API.") - 64 json_data = get_cfbd_nfl_teams(api_key=cfbd_key) - 65 print(json_data) - 66 time.sleep(5) - 67 - 68 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 69 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 70 json_data = get_cfbd_nfl_teams( - 71 api_key=cfbd_key, - 72 return_as_dict=True) - 73 print(json_data) - 74 - 75 else: - 76 # Alternatively, if the CFBD API key exists in this python environment, - 77 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 78 # you could just call these functions directly, without setting the API key - 79 # in the script. - 80 print("Using the user's API key suposedly loaded into this python environment for this example.") - 81 - 82 # Gets NFL team info from the CFBD API. - 83 print("Gets NFL team info from the CFBD API.") - 84 json_data = get_cfbd_nfl_teams() - 85 print(json_data) - 86 time.sleep(5) - 87 - 88 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. - 89 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 90 json_data = get_cfbd_nfl_teams(return_as_dict=True) - 91 print(json_data) - 92 - 93 ``` - 94 - 95 Returns - 96 ---------- - 97 A pandas `DataFrame` object with NFL team data, - 98 or (if `return_as_dict` is set to `True`) - 99 a dictionary object with NFL team data. -100 -101 """ -102 -103 nfl_teams_df = pd.DataFrame() -104 row_df = pd.DataFrame() -105 url = "https://api.collegefootballdata.com/draft/teams" -106 -107 # Input validation -108 ######################################################################################################################################################################################################## -109 -110 if api_key != None: -111 real_api_key = api_key -112 del api_key -113 else: -114 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -115 -116 if real_api_key == "tigersAreAwsome": -117 raise ValueError( -118 "You actually need to change `cfbd_key` to your CFBD API key.") -119 elif "Bearer " in real_api_key: -120 pass -121 elif "Bearer" in real_api_key: -122 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -123 else: -124 real_api_key = "Bearer " + real_api_key -125 -126 headers = { -127 'Authorization': f'{real_api_key}', -128 'accept': 'application/json' -129 } -130 -131 response = requests.get(url, headers=headers) -132 time.sleep(0.1) -133 -134 if response.status_code == 200: -135 pass -136 elif response.status_code == 401: -137 raise ConnectionRefusedError( -138 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -139 ) -140 else: -141 raise ConnectionError( -142 f'Could not connect.\nHTTP Status code {response.status_code}' -143 ) -144 -145 json_data = response.json() -146 -147 if return_as_dict == True: -148 return json_data -149 -150 for nfl_team in json_data: -151 nfl_team_location = nfl_team['location'] -152 nfl_team_nickname = nfl_team['nickname'] -153 nfl_team_display_name = nfl_team['displayName'] -154 nfl_team_logo = nfl_team['logo'] -155 -156 row_df = pd.DataFrame( -157 { -158 "nfl_team_location": nfl_team_location, -159 "nfl_team_nickname": nfl_team_nickname, -160 "nfl_team_display_name": nfl_team_display_name, -161 "nfl_team_logo": nfl_team_logo -162 }, index=[0] -163 ) -164 -165 nfl_teams_df = pd.concat([nfl_teams_df, row_df], ignore_index=True) -166 -167 del nfl_team_location, nfl_team_nickname, \ -168 nfl_team_display_name, nfl_team_logo -169 -170 del row_df -171 -172 return nfl_teams_df +@@ -923,7 +922,7 @@18def get_cfbd_nfl_teams( + 19 api_key: str = None, + 20 api_key_dir: str = None, + 21 return_as_dict: bool = False): + 22 """ + 23 Retrives a list of NFL teams from the CFBD API. + 24 + 25 Parameters + 26 ---------- + 27 `api_key` (str, optional): + 28 Semi-optional argument. + 29 If `api_key` is null, this function will attempt to load a CFBD API key + 30 from the python environment, or from a file on this computer. + 31 If `api_key` is not null, this function will automatically assume that the + 32 inputted `api_key` is a valid CFBD API key. + 33 + 34 `api_key_dir` (str, optional): + 35 Optional argument. + 36 If `api_key` is set to am empty string, this variable is ignored. + 37 If `api_key_dir` is null, and `api_key` is null, + 38 this function will try to find a CFBD API key file in this user's home directory. + 39 If `api_key_dir` is set to a string, and `api_key` is null, + 40 this function will assume that `api_key_dir` is a directory, + 41 and will try to find a CFBD API key file in that directory. + 42 + 43 `return_as_dict` (bool, semi-optional): + 44 Semi-optional argument. + 45 If you want this function to return the data as a dictionary (read: JSON object), + 46 instead of a pandas `DataFrame` object, + 47 set `return_as_dict` to `True`. + 48 + 49 Usage + 50 ---------- + 51 ``` + 52 import time + 53 + 54 from cfbd_json_py.draft import get_cfbd_nfl_teams + 55 + 56 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 57 + 58 if cfbd_key != "tigersAreAwsome": + 59 print("Using the user's API key declared in this script for this example.") + 60 + 61 # Gets NFL team info from the CFBD API. + 62 print("Gets NFL team info from the CFBD API.") + 63 json_data = get_cfbd_nfl_teams(api_key=cfbd_key) + 64 print(json_data) + 65 time.sleep(5) + 66 + 67 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 68 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 69 json_data = get_cfbd_nfl_teams( + 70 api_key=cfbd_key, + 71 return_as_dict=True) + 72 print(json_data) + 73 + 74 else: + 75 # Alternatively, if the CFBD API key exists in this python environment, + 76 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 77 # you could just call these functions directly, without setting the API key + 78 # in the script. + 79 print("Using the user's API key suposedly loaded into this python environment for this example.") + 80 + 81 # Gets NFL team info from the CFBD API. + 82 print("Gets NFL team info from the CFBD API.") + 83 json_data = get_cfbd_nfl_teams() + 84 print(json_data) + 85 time.sleep(5) + 86 + 87 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. + 88 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 89 json_data = get_cfbd_nfl_teams(return_as_dict=True) + 90 print(json_data) + 91 + 92 ``` + 93 + 94 Returns + 95 ---------- + 96 A pandas `DataFrame` object with NFL team data, + 97 or (if `return_as_dict` is set to `True`) + 98 a dictionary object with NFL team data. + 99 +100 """ +101 +102 nfl_teams_df = pd.DataFrame() +103 row_df = pd.DataFrame() +104 url = "https://api.collegefootballdata.com/draft/teams" +105 +106 # Input validation +107 ######################################################################################################################################################################################################## +108 +109 if api_key != None: +110 real_api_key = api_key +111 del api_key +112 else: +113 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +114 +115 if real_api_key == "tigersAreAwsome": +116 raise ValueError( +117 "You actually need to change `cfbd_key` to your CFBD API key.") +118 elif "Bearer " in real_api_key: +119 pass +120 elif "Bearer" in real_api_key: +121 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +122 else: +123 real_api_key = "Bearer " + real_api_key +124 +125 headers = { +126 'Authorization': f'{real_api_key}', +127 'accept': 'application/json' +128 } +129 +130 response = requests.get(url, headers=headers) +131 +132 +133 if response.status_code == 200: +134 pass +135 elif response.status_code == 401: +136 raise ConnectionRefusedError( +137 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +138 ) +139 else: +140 raise ConnectionError( +141 f'Could not connect.\nHTTP Status code {response.status_code}' +142 ) +143 +144 json_data = response.json() +145 +146 if return_as_dict == True: +147 return json_data +148 +149 for nfl_team in json_data: +150 nfl_team_location = nfl_team['location'] +151 nfl_team_nickname = nfl_team['nickname'] +152 nfl_team_display_name = nfl_team['displayName'] +153 nfl_team_logo = nfl_team['logo'] +154 +155 row_df = pd.DataFrame( +156 { +157 "nfl_team_location": nfl_team_location, +158 "nfl_team_nickname": nfl_team_nickname, +159 "nfl_team_display_name": nfl_team_display_name, +160 "nfl_team_logo": nfl_team_logo +161 }, index=[0] +162 ) +163 +164 nfl_teams_df = pd.concat([nfl_teams_df, row_df], ignore_index=True) +165 +166 del nfl_team_location, nfl_team_nickname, \ +167 nfl_team_display_name, nfl_team_logo +168 +169 del row_df +170 +171 return nfl_teams_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -1000,152 +999,152 @@Returns
175def get_cfbd_nfl_positions( -176 api_key: str = None, -177 api_key_dir: str = None, -178 return_as_dict: bool = False): -179 """ -180 Retrives a list of player positions for the NFL Draft from the CFBD API. -181 -182 Parameters -183 ---------- -184 `api_key` (str, optional): -185 Semi-optional argument. -186 If `api_key` is null, this function will attempt to load a CFBD API key -187 from the python environment, or from a file on this computer. -188 If `api_key` is not null, this function will automatically assume that the -189 inputted `api_key` is a valid CFBD API key. -190 -191 `api_key_dir` (str, optional): -192 Optional argument. -193 If `api_key` is set to a string non-empty string, this variable is ignored. -194 If `api_key_dir` is null, and `api_key` is null, -195 this function will try to find a CFBD API key file in this user's home directory. -196 If `api_key_dir` is set to a string, and `api_key` is null, -197 this function will assume that `api_key_dir` is a directory, -198 and will try to find a CFBD API key file in that directory. -199 -200 `return_as_dict` (bool, semi-optional): -201 Semi-optional argument. -202 If you want this function to return the data as a dictionary (read: JSON object), -203 instead of a pandas `DataFrame` object, -204 set `return_as_dict` to `True`. -205 -206 Usage -207 ---------- -208 ``` -209 import time -210 -211 from cfbd_json_py.draft import get_cfbd_nfl_positions -212 -213 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -214 -215 if cfbd_key != "tigersAreAwsome": -216 print("Using the user's API key declared in this script for this example.") -217 -218 # Gets a list of player positions for the NFL Draft from the CFBD API. -219 print("Gets a list of player positions for the NFL Draft from the CFBD API.") -220 json_data = get_cfbd_nfl_positions(api_key=cfbd_key) -221 print(json_data) -222 time.sleep(5) -223 -224 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -225 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -226 json_data = get_cfbd_nfl_positions( -227 api_key=cfbd_key, -228 return_as_dict=True) -229 print(json_data) -230 -231 else: -232 # Alternatively, if the CFBD API key exists in this python environment, -233 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -234 # you could just call these functions directly, without setting the API key -235 # in the script. -236 print("Using the user's API key suposedly loaded into this python environment for this example.") -237 -238 # Gets a list of player positions for the NFL Draft from the CFBD API. -239 print("Gets a list of player positions for the NFL Draft from the CFBD API.") -240 json_data = get_cfbd_nfl_positions() -241 print(json_data) -242 time.sleep(5) -243 -244 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -245 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -246 json_data = get_cfbd_nfl_positions(return_as_dict=True) -247 print(json_data) -248 -249 ``` -250 Returns -251 ---------- -252 A pandas `DataFrame` object with player position data, -253 or (if `return_as_dict` is set to `True`) -254 a dictionary object with player position data. -255 -256 """ -257 -258 positions_df = pd.DataFrame() -259 row_df = pd.DataFrame() -260 url = "https://api.collegefootballdata.com/draft/positions" -261 -262 # Input validation -263 ######################################################################################################################################################################################################## -264 -265 if api_key != None: -266 real_api_key = api_key -267 del api_key -268 else: -269 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -270 -271 if real_api_key == "tigersAreAwsome": -272 raise ValueError( -273 "You actually need to change `cfbd_key` to your CFBD API key.") -274 elif "Bearer " in real_api_key: -275 pass -276 elif "Bearer" in real_api_key: -277 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -278 else: -279 real_api_key = "Bearer " + real_api_key -280 -281 headers = { -282 'Authorization': f'{real_api_key}', -283 'accept': 'application/json' -284 } -285 -286 response = requests.get(url, headers=headers) -287 time.sleep(0.1) -288 -289 if response.status_code == 200: -290 pass -291 elif response.status_code == 401: -292 raise ConnectionRefusedError( -293 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -294 ) -295 else: -296 raise ConnectionError( -297 f'Could not connect.\nHTTP Status code {response.status_code}' -298 ) -299 -300 json_data = response.json() -301 -302 if return_as_dict == True: -303 return json_data -304 -305 for p in json_data: -306 position_name = p['name'] -307 position_abbreviation = p['abbreviation'] -308 -309 row_df = pd.DataFrame( -310 { -311 "position_name": position_name, -312 "position_abbreviation": position_abbreviation -313 }, index=[0] -314 ) -315 positions_df = pd.concat([positions_df, row_df], ignore_index=True) -316 -317 del position_name, position_abbreviation -318 del row_df -319 -320 return positions_df +@@ -1162,7 +1161,7 @@174def get_cfbd_nfl_positions( +175 api_key: str = None, +176 api_key_dir: str = None, +177 return_as_dict: bool = False): +178 """ +179 Retrives a list of player positions for the NFL Draft from the CFBD API. +180 +181 Parameters +182 ---------- +183 `api_key` (str, optional): +184 Semi-optional argument. +185 If `api_key` is null, this function will attempt to load a CFBD API key +186 from the python environment, or from a file on this computer. +187 If `api_key` is not null, this function will automatically assume that the +188 inputted `api_key` is a valid CFBD API key. +189 +190 `api_key_dir` (str, optional): +191 Optional argument. +192 If `api_key` is set to am empty string, this variable is ignored. +193 If `api_key_dir` is null, and `api_key` is null, +194 this function will try to find a CFBD API key file in this user's home directory. +195 If `api_key_dir` is set to a string, and `api_key` is null, +196 this function will assume that `api_key_dir` is a directory, +197 and will try to find a CFBD API key file in that directory. +198 +199 `return_as_dict` (bool, semi-optional): +200 Semi-optional argument. +201 If you want this function to return the data as a dictionary (read: JSON object), +202 instead of a pandas `DataFrame` object, +203 set `return_as_dict` to `True`. +204 +205 Usage +206 ---------- +207 ``` +208 import time +209 +210 from cfbd_json_py.draft import get_cfbd_nfl_positions +211 +212 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +213 +214 if cfbd_key != "tigersAreAwsome": +215 print("Using the user's API key declared in this script for this example.") +216 +217 # Gets a list of player positions for the NFL Draft from the CFBD API. +218 print("Gets a list of player positions for the NFL Draft from the CFBD API.") +219 json_data = get_cfbd_nfl_positions(api_key=cfbd_key) +220 print(json_data) +221 time.sleep(5) +222 +223 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +224 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +225 json_data = get_cfbd_nfl_positions( +226 api_key=cfbd_key, +227 return_as_dict=True) +228 print(json_data) +229 +230 else: +231 # Alternatively, if the CFBD API key exists in this python environment, +232 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +233 # you could just call these functions directly, without setting the API key +234 # in the script. +235 print("Using the user's API key suposedly loaded into this python environment for this example.") +236 +237 # Gets a list of player positions for the NFL Draft from the CFBD API. +238 print("Gets a list of player positions for the NFL Draft from the CFBD API.") +239 json_data = get_cfbd_nfl_positions() +240 print(json_data) +241 time.sleep(5) +242 +243 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +244 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +245 json_data = get_cfbd_nfl_positions(return_as_dict=True) +246 print(json_data) +247 +248 ``` +249 Returns +250 ---------- +251 A pandas `DataFrame` object with player position data, +252 or (if `return_as_dict` is set to `True`) +253 a dictionary object with player position data. +254 +255 """ +256 +257 positions_df = pd.DataFrame() +258 row_df = pd.DataFrame() +259 url = "https://api.collegefootballdata.com/draft/positions" +260 +261 # Input validation +262 ######################################################################################################################################################################################################## +263 +264 if api_key != None: +265 real_api_key = api_key +266 del api_key +267 else: +268 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +269 +270 if real_api_key == "tigersAreAwsome": +271 raise ValueError( +272 "You actually need to change `cfbd_key` to your CFBD API key.") +273 elif "Bearer " in real_api_key: +274 pass +275 elif "Bearer" in real_api_key: +276 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +277 else: +278 real_api_key = "Bearer " + real_api_key +279 +280 headers = { +281 'Authorization': f'{real_api_key}', +282 'accept': 'application/json' +283 } +284 +285 response = requests.get(url, headers=headers) +286 +287 +288 if response.status_code == 200: +289 pass +290 elif response.status_code == 401: +291 raise ConnectionRefusedError( +292 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +293 ) +294 else: +295 raise ConnectionError( +296 f'Could not connect.\nHTTP Status code {response.status_code}' +297 ) +298 +299 json_data = response.json() +300 +301 if return_as_dict == True: +302 return json_data +303 +304 for p in json_data: +305 position_name = p['name'] +306 position_abbreviation = p['abbreviation'] +307 +308 row_df = pd.DataFrame( +309 { +310 "position_name": position_name, +311 "position_abbreviation": position_abbreviation +312 }, index=[0] +313 ) +314 positions_df = pd.concat([positions_df, row_df], ignore_index=True) +315 +316 del position_name, position_abbreviation +317 del row_df +318 +319 return positions_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -1239,363 +1238,363 @@Returns
323def get_cfbd_nfl_draft_info( -324 api_key: str = None, -325 api_key_dir: str = None, -326 season: int = None, -327 nfl_team: str = None, -328 college: str = None, -329 conference_abv: str = None, -330 position: str = None, -331 return_as_dict: bool = False): -332 """ -333 Retrives a list of actual NFL Draft selections from the CFBD API. -334 -335 Parameters -336 ---------- -337 -338 `api_key` (str, optional): -339 Semi-optional argument. -340 If `api_key` is null, this function will attempt to load a CFBD API key -341 from the python environment, or from a file on this computer. -342 If `api_key` is not null, this function will automatically assume that the -343 inputted `api_key` is a valid CFBD API key. -344 -345 `api_key_dir` (str, optional): -346 Optional argument. -347 If `api_key` is set to a string non-empty string, this variable is ignored. -348 If `api_key_dir` is null, and `api_key` is null, -349 this function will try to find a CFBD API key file in this user's home directory. -350 If `api_key_dir` is set to a string, and `api_key` is null, -351 this function will assume that `api_key_dir` is a directory, -352 and will try to find a CFBD API key file in that directory. -353 -354 The following paramaters are optional, but it is highly reccomended to not call this function -355 withiout settting one of these five optional paramaters to a non-null value. -356 -357 `season` (int, semi-optional): -358 Semi-Optional argument. -359 This is the season you want NFL Draft information for. For example, if you only want -360 data for the 2020 NFL Draft, set `season` to `2020`. -361 -362 `nfl_team` (str, optional): -363 Semi-Optional argument. -364 If you only want NFL Draft selections from a specific NFL team, set `nfl_team` to the -365 name of that team. For example, if you want to only get NFL Draft information for -366 draft picks made by the Cincinnati Bengals, set `nfl_team` to `Cincinnati`. -367 -368 `college` (str, optional): -369 Semi-Optional argument. -370 If you only want NFL Draft selections from a specific CFB team, set `college` to the -371 name of that team. For example, if you want to only get NFL Draft information for -372 draft picks from the Clemson Tigers Football Program, set `college` to `Clemson`. -373 -374 `conference` (str, optional): -375 Semi-Optional argument. -376 If you only want NFL Draft selections from a specific CFB confrence, set `conference` to the abbreviation of that confrence. -377 A list of CFBD API confrence abbreviations can be found in the `conference_abbreviation` column from -378 the pandas DataFrame that is returned by calling `cfbd_json_py.conferences.get_cfbd_conference_info()`. -379 For example, if you want to only get NFL Draft information for -380 draft picks that played in the Big 12, set `confrence` to `B12`. -381 -382 `position` (str, optional): -383 Semi-Optional argument. -384 If you only want NFL Draft selections who played a specific position, -385 set `position` to that position's abbreviation. -386 A list of CFBD API positions can be found in the `position_abbreviation` column from -387 the pandas DataFrame that is returned by calling `cfbd_json_py.draft.get_cfbd_nfl_positions()`. -388 -389 `return_as_dict` (bool, semi-optional): -390 Semi-optional argument. -391 If you want this function to return the data as a dictionary (read: JSON object), -392 instead of a pandas `DataFrame` object, -393 set `return_as_dict` to `True`. -394 Usage -395 ---------- -396 -397 ``` -398 import time -399 -400 from cfbd_json_py.draft import get_cfbd_nfl_draft_info -401 -402 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -403 -404 if cfbd_key != "tigersAreAwsome": -405 print("Using the user's API key declared in this script for this example.") -406 -407 # Get NFL Draft selections from the 2020 NFL Draft. -408 print("Get NFL Draft selections from the 2020 NFL Draft.") -409 json_data = get_cfbd_nfl_draft_info( -410 api_key=cfbd_key, -411 season=2020 -412 ) -413 print(json_data) -414 time.sleep(5) -415 -416 # Get NFL Draft selections from the 2020 NFL Draft made by the -417 # 2020 Cincinnati Bengals. -418 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") -419 json_data = get_cfbd_nfl_draft_info( -420 api_key=cfbd_key, -421 season=2020, -422 nfl_team="Cincinnati" -423 ) -424 print(json_data) -425 time.sleep(5) -426 -427 # Get NFL Draft selections from the 2020 NFL Draft made involving -428 # Clemson Tigers football players. -429 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") -430 json_data = get_cfbd_nfl_draft_info( -431 api_key=cfbd_key, -432 season=2020, -433 college="Clemson" -434 ) -435 print(json_data) -436 time.sleep(5) -437 -438 # Get NFL Draft selections from the 2020 NFL Draft made involving -439 # players who played in the Southeastern Confrence (SEC). -440 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") -441 json_data = get_cfbd_nfl_draft_info( -442 api_key=cfbd_key, -443 season=2020, -444 conference="SEC" -445 ) -446 print(json_data) -447 time.sleep(5) -448 -449 # Get NFL Draft selections from the 2020 NFL Draft made -450 # where the selected player was a QB in college. -451 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") -452 json_data = get_cfbd_nfl_draft_info( -453 api_key=cfbd_key, -454 season=2020, -455 position="QB" -456 ) -457 print(json_data) -458 time.sleep(5) -459 -460 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -461 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -462 json_data = get_cfbd_nfl_draft_info( -463 season=2020, -464 position="QB", -465 api_key=cfbd_key, -466 return_as_dict=True -467 ) -468 print(json_data) -469 -470 else: -471 # Alternatively, if the CFBD API key exists in this python environment, -472 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -473 # you could just call these functions directly, without setting the API key -474 # in the script. -475 print("Using the user's API key suposedly loaded into this python environment for this example.") -476 -477 # Get NFL Draft selections from the 2020 NFL Draft. -478 print("Get NFL Draft selections from the 2020 NFL Draft.") -479 json_data = get_cfbd_nfl_draft_info(season=2020) -480 print(json_data) -481 time.sleep(5) -482 -483 # Get NFL Draft selections from the 2020 NFL Draft made by the -484 # 2020 Cincinnati Bengals. -485 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") -486 json_data = get_cfbd_nfl_draft_info( -487 season=2020, -488 nfl_team="Cincinnati" -489 ) -490 print(json_data) -491 time.sleep(5) -492 -493 # Get NFL Draft selections from the 2020 NFL Draft made involving -494 # Clemson Tigers football players. -495 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") -496 json_data = get_cfbd_nfl_draft_info( -497 season=2020, -498 college="Clemson" -499 ) -500 print(json_data) -501 time.sleep(5) -502 -503 # Get NFL Draft selections from the 2020 NFL Draft made involving -504 # players who played in the Southeastern Confrence (SEC). -505 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") -506 json_data = get_cfbd_nfl_draft_info( -507 season=2020, -508 conference="SEC" -509 ) -510 print(json_data) -511 time.sleep(5) -512 -513 # Get NFL Draft selections from the 2020 NFL Draft made -514 # where the selected player was a QB in college. -515 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") -516 json_data = get_cfbd_nfl_draft_info( -517 season=2020, -518 position="QB" -519 ) -520 print(json_data) -521 time.sleep(5) -522 -523 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. -524 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -525 json_data = get_cfbd_nfl_draft_info( -526 season=2020, -527 position="QB", -528 return_as_dict=True -529 ) -530 print(json_data) -531 ``` -532 -533 Returns -534 ---------- -535 A pandas `DataFrame` object with NFL Draft selection data, -536 or (if `return_as_dict` is set to `True`) -537 a dictionary object with NFL Draft selection data. -538 -539 """ -540 now = datetime.now() -541 nfl_draft_df = pd.DataFrame() -542 row_df = pd.DataFrame() -543 url = "https://api.collegefootballdata.com/draft/picks" -544 -545 # Input validation -546 ######################################################################################################################################################################################################## -547 -548 if api_key != None: -549 real_api_key = api_key -550 del api_key -551 else: -552 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -553 -554 if real_api_key == "tigersAreAwsome": -555 raise ValueError( -556 "You actually need to change `cfbd_key` to your CFBD API key.") -557 elif "Bearer " in real_api_key: -558 pass -559 elif "Bearer" in real_api_key: -560 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -561 else: -562 real_api_key = "Bearer " + real_api_key -563 -564 if season == None and nfl_team == None and college == None and conference_abv == None: -565 logging.warning( -566 "Not specifying a `season`, `nfl_team`, `college`, or `confrence` will still result in a successful get request (assuming the API key is valid)" + -567 ", but this is not a recomended method of calling this function.") -568 -569 if season < 1936 or season > now.year: -570 raise ValueError( -571 f"`season` must be an integer between 1936 and {now.year}.\nYou entered:\n{season}") -572 -573 # URL builder -574 ######################################################################################################################################################################################################## -575 url_elements = 0 -576 -577 if season != None and url_elements == 0: -578 url += f"?year={season}" -579 url_elements += 1 -580 elif season != None: -581 url += f"&year={season}" -582 url_elements += 1 -583 -584 if nfl_team != None and url_elements == 0: -585 url += f"?nflTeam={nfl_team}" # nfl_team = "Cincinnati", not "CIN" -586 url_elements += 1 -587 elif nfl_team != None: -588 url += f"&nflTeam={nfl_team}" -589 url_elements += 1 -590 -591 if college != None and url_elements == 0: -592 url += f"?college={college}" -593 url_elements += 1 -594 elif college != None: -595 url += f"&college={college}" -596 url_elements += 1 -597 -598 if conference_abv != None and url_elements == 0: -599 # conference = "SEC", not "Southeastern Confrence" -600 url += f"?conference={conference_abv}" -601 url_elements += 1 -602 elif conference_abv != None: -603 url += f"&conference={conference_abv}" -604 url_elements += 1 -605 -606 if position != None and url_elements == 0: -607 url += f"?position={position}" -608 url_elements += 1 -609 elif position != None: -610 url += f"&position={position}" -611 url_elements += 1 -612 -613 headers = { -614 'Authorization': f'{real_api_key}', -615 'accept': 'application/json' -616 } -617 -618 response = requests.get(url, headers=headers) -619 time.sleep(0.1) -620 -621 if response.status_code == 200: -622 pass -623 elif response.status_code == 401: -624 raise ConnectionRefusedError( -625 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -626 ) -627 else: -628 raise ConnectionError( -629 f'Could not connect.\nHTTP Status code {response.status_code}' -630 ) -631 -632 json_data = response.json() -633 -634 if return_as_dict == True: -635 return json_data -636 -637 for p in tqdm(json_data): -638 college_athlete_id = p['collegeAthleteId'] -639 row_df = pd.DataFrame( -640 { -641 "college_athlete_id": college_athlete_id -642 }, index=[0] -643 ) -644 del college_athlete_id -645 -646 row_df['nfl_athlete_id'] = p['nflAthleteId'] -647 row_df['college_id'] = p['collegeId'] -648 row_df['college_team'] = p['collegeTeam'] -649 row_df['college_conference'] = p['collegeConference'] -650 row_df['nfl_team'] = p['nflTeam'] -651 row_df['draft_year'] = p['year'] -652 row_df['draft_pick_overall'] = p['overall'] -653 row_df['draft_round'] = p['round'] -654 row_df['draft_round_pick'] = p['pick'] -655 row_df['player_name'] = p['name'] -656 row_df['player_position'] = p['position'] -657 row_df['player_height'] = p['height'] -658 row_df['player_weight'] = p['weight'] -659 row_df['pre_draft_ranking'] = p['preDraftRanking'] -660 row_df['pre_draft_position_ranking'] = p['preDraftPositionRanking'] -661 row_df['pre_draft_grade'] = p['preDraftGrade'] -662 row_df['player_hometown_city'] = p['hometownInfo']['city'] -663 row_df['player_hometown_state'] = p['hometownInfo']['state'] -664 row_df['player_hometown_country'] = p['hometownInfo']['country'] -665 row_df['player_hometown_latitude'] = p['hometownInfo']['latitude'] -666 row_df['player_hometown_longitude'] = p['hometownInfo']['longitude'] -667 row_df['player_hometown_county_fips'] = p['hometownInfo']['countyFips'] -668 -669 nfl_draft_df = pd.concat([nfl_draft_df, row_df], ignore_index=True) -670 del row_df -671 -672 if len(nfl_draft_df) == 0: -673 logging.error( -674 "The CFBD API accepted your inputs, " + -675 "but found no data within your specified input paramaters." + -676 " Please double check your input paramaters." -677 ) -678 -679 return nfl_draft_df +@@ -1612,7 +1611,7 @@322def get_cfbd_nfl_draft_info( +323 api_key: str = None, +324 api_key_dir: str = None, +325 season: int = None, +326 nfl_team: str = None, +327 college: str = None, +328 conference_abv: str = None, +329 position: str = None, +330 return_as_dict: bool = False): +331 """ +332 Retrives a list of actual NFL Draft selections from the CFBD API. +333 +334 Parameters +335 ---------- +336 +337 `api_key` (str, optional): +338 Semi-optional argument. +339 If `api_key` is null, this function will attempt to load a CFBD API key +340 from the python environment, or from a file on this computer. +341 If `api_key` is not null, this function will automatically assume that the +342 inputted `api_key` is a valid CFBD API key. +343 +344 `api_key_dir` (str, optional): +345 Optional argument. +346 If `api_key` is set to am empty string, this variable is ignored. +347 If `api_key_dir` is null, and `api_key` is null, +348 this function will try to find a CFBD API key file in this user's home directory. +349 If `api_key_dir` is set to a string, and `api_key` is null, +350 this function will assume that `api_key_dir` is a directory, +351 and will try to find a CFBD API key file in that directory. +352 +353 The following paramaters are optional, but it is highly reccomended to not call this function +354 withiout settting one of these five optional paramaters to a non-null value. +355 +356 `season` (int, semi-optional): +357 Semi-Optional argument. +358 This is the season you want NFL Draft information for. For example, if you only want +359 data for the 2020 NFL Draft, set `season` to `2020`. +360 +361 `nfl_team` (str, optional): +362 Semi-Optional argument. +363 If you only want NFL Draft selections from a specific NFL team, set `nfl_team` to the +364 name of that team. For example, if you want to only get NFL Draft information for +365 draft picks made by the Cincinnati Bengals, set `nfl_team` to `Cincinnati`. +366 +367 `college` (str, optional): +368 Semi-Optional argument. +369 If you only want NFL Draft selections from a specific CFB team, set `college` to the +370 name of that team. For example, if you want to only get NFL Draft information for +371 draft picks from the Clemson Tigers Football Program, set `college` to `Clemson`. +372 +373 `conference` (str, optional): +374 Semi-Optional argument. +375 If you only want NFL Draft selections from a specific CFB confrence, set `conference` to the abbreviation of that confrence. +376 A list of CFBD API confrence abbreviations can be found in the `conference_abbreviation` column from +377 the pandas DataFrame that is returned by calling `cfbd_json_py.conferences.get_cfbd_conference_info()`. +378 For example, if you want to only get NFL Draft information for +379 draft picks that played in the Big 12, set `confrence` to `B12`. +380 +381 `position` (str, optional): +382 Semi-Optional argument. +383 If you only want NFL Draft selections who played a specific position, +384 set `position` to that position's abbreviation. +385 A list of CFBD API positions can be found in the `position_abbreviation` column from +386 the pandas DataFrame that is returned by calling `cfbd_json_py.draft.get_cfbd_nfl_positions()`. +387 +388 `return_as_dict` (bool, semi-optional): +389 Semi-optional argument. +390 If you want this function to return the data as a dictionary (read: JSON object), +391 instead of a pandas `DataFrame` object, +392 set `return_as_dict` to `True`. +393 Usage +394 ---------- +395 +396 ``` +397 import time +398 +399 from cfbd_json_py.draft import get_cfbd_nfl_draft_info +400 +401 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +402 +403 if cfbd_key != "tigersAreAwsome": +404 print("Using the user's API key declared in this script for this example.") +405 +406 # Get NFL Draft selections from the 2020 NFL Draft. +407 print("Get NFL Draft selections from the 2020 NFL Draft.") +408 json_data = get_cfbd_nfl_draft_info( +409 api_key=cfbd_key, +410 season=2020 +411 ) +412 print(json_data) +413 time.sleep(5) +414 +415 # Get NFL Draft selections from the 2020 NFL Draft made by the +416 # 2020 Cincinnati Bengals. +417 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") +418 json_data = get_cfbd_nfl_draft_info( +419 api_key=cfbd_key, +420 season=2020, +421 nfl_team="Cincinnati" +422 ) +423 print(json_data) +424 time.sleep(5) +425 +426 # Get NFL Draft selections from the 2020 NFL Draft made involving +427 # Clemson Tigers football players. +428 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") +429 json_data = get_cfbd_nfl_draft_info( +430 api_key=cfbd_key, +431 season=2020, +432 college="Clemson" +433 ) +434 print(json_data) +435 time.sleep(5) +436 +437 # Get NFL Draft selections from the 2020 NFL Draft made involving +438 # players who played in the Southeastern Confrence (SEC). +439 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") +440 json_data = get_cfbd_nfl_draft_info( +441 api_key=cfbd_key, +442 season=2020, +443 conference="SEC" +444 ) +445 print(json_data) +446 time.sleep(5) +447 +448 # Get NFL Draft selections from the 2020 NFL Draft made +449 # where the selected player was a QB in college. +450 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") +451 json_data = get_cfbd_nfl_draft_info( +452 api_key=cfbd_key, +453 season=2020, +454 position="QB" +455 ) +456 print(json_data) +457 time.sleep(5) +458 +459 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +460 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +461 json_data = get_cfbd_nfl_draft_info( +462 season=2020, +463 position="QB", +464 api_key=cfbd_key, +465 return_as_dict=True +466 ) +467 print(json_data) +468 +469 else: +470 # Alternatively, if the CFBD API key exists in this python environment, +471 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +472 # you could just call these functions directly, without setting the API key +473 # in the script. +474 print("Using the user's API key suposedly loaded into this python environment for this example.") +475 +476 # Get NFL Draft selections from the 2020 NFL Draft. +477 print("Get NFL Draft selections from the 2020 NFL Draft.") +478 json_data = get_cfbd_nfl_draft_info(season=2020) +479 print(json_data) +480 time.sleep(5) +481 +482 # Get NFL Draft selections from the 2020 NFL Draft made by the +483 # 2020 Cincinnati Bengals. +484 print("Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.") +485 json_data = get_cfbd_nfl_draft_info( +486 season=2020, +487 nfl_team="Cincinnati" +488 ) +489 print(json_data) +490 time.sleep(5) +491 +492 # Get NFL Draft selections from the 2020 NFL Draft made involving +493 # Clemson Tigers football players. +494 print("Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.") +495 json_data = get_cfbd_nfl_draft_info( +496 season=2020, +497 college="Clemson" +498 ) +499 print(json_data) +500 time.sleep(5) +501 +502 # Get NFL Draft selections from the 2020 NFL Draft made involving +503 # players who played in the Southeastern Confrence (SEC). +504 print("Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).") +505 json_data = get_cfbd_nfl_draft_info( +506 season=2020, +507 conference="SEC" +508 ) +509 print(json_data) +510 time.sleep(5) +511 +512 # Get NFL Draft selections from the 2020 NFL Draft made +513 # where the selected player was a QB in college. +514 print("Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.") +515 json_data = get_cfbd_nfl_draft_info( +516 season=2020, +517 position="QB" +518 ) +519 print(json_data) +520 time.sleep(5) +521 +522 # You can also tell this function to just return the API call as a Dictionary (read: JSON) object. +523 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +524 json_data = get_cfbd_nfl_draft_info( +525 season=2020, +526 position="QB", +527 return_as_dict=True +528 ) +529 print(json_data) +530 ``` +531 +532 Returns +533 ---------- +534 A pandas `DataFrame` object with NFL Draft selection data, +535 or (if `return_as_dict` is set to `True`) +536 a dictionary object with NFL Draft selection data. +537 +538 """ +539 now = datetime.now() +540 nfl_draft_df = pd.DataFrame() +541 row_df = pd.DataFrame() +542 url = "https://api.collegefootballdata.com/draft/picks" +543 +544 # Input validation +545 ######################################################################################################################################################################################################## +546 +547 if api_key != None: +548 real_api_key = api_key +549 del api_key +550 else: +551 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +552 +553 if real_api_key == "tigersAreAwsome": +554 raise ValueError( +555 "You actually need to change `cfbd_key` to your CFBD API key.") +556 elif "Bearer " in real_api_key: +557 pass +558 elif "Bearer" in real_api_key: +559 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +560 else: +561 real_api_key = "Bearer " + real_api_key +562 +563 if season == None and nfl_team == None and college == None and conference_abv == None: +564 logging.warning( +565 "Not specifying a `season`, `nfl_team`, `college`, or `confrence` will still result in a successful get request (assuming the API key is valid)" + +566 ", but this is not a recomended method of calling this function.") +567 +568 if season < 1936 or season > now.year: +569 raise ValueError( +570 f"`season` must be an integer between 1936 and {now.year}.\nYou entered:\n{season}") +571 +572 # URL builder +573 ######################################################################################################################################################################################################## +574 url_elements = 0 +575 +576 if season != None and url_elements == 0: +577 url += f"?year={season}" +578 url_elements += 1 +579 elif season != None: +580 url += f"&year={season}" +581 url_elements += 1 +582 +583 if nfl_team != None and url_elements == 0: +584 url += f"?nflTeam={nfl_team}" # nfl_team = "Cincinnati", not "CIN" +585 url_elements += 1 +586 elif nfl_team != None: +587 url += f"&nflTeam={nfl_team}" +588 url_elements += 1 +589 +590 if college != None and url_elements == 0: +591 url += f"?college={college}" +592 url_elements += 1 +593 elif college != None: +594 url += f"&college={college}" +595 url_elements += 1 +596 +597 if conference_abv != None and url_elements == 0: +598 # conference = "SEC", not "Southeastern Confrence" +599 url += f"?conference={conference_abv}" +600 url_elements += 1 +601 elif conference_abv != None: +602 url += f"&conference={conference_abv}" +603 url_elements += 1 +604 +605 if position != None and url_elements == 0: +606 url += f"?position={position}" +607 url_elements += 1 +608 elif position != None: +609 url += f"&position={position}" +610 url_elements += 1 +611 +612 headers = { +613 'Authorization': f'{real_api_key}', +614 'accept': 'application/json' +615 } +616 +617 response = requests.get(url, headers=headers) +618 +619 +620 if response.status_code == 200: +621 pass +622 elif response.status_code == 401: +623 raise ConnectionRefusedError( +624 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +625 ) +626 else: +627 raise ConnectionError( +628 f'Could not connect.\nHTTP Status code {response.status_code}' +629 ) +630 +631 json_data = response.json() +632 +633 if return_as_dict == True: +634 return json_data +635 +636 for p in tqdm(json_data): +637 college_athlete_id = p['collegeAthleteId'] +638 row_df = pd.DataFrame( +639 { +640 "college_athlete_id": college_athlete_id +641 }, index=[0] +642 ) +643 del college_athlete_id +644 +645 row_df['nfl_athlete_id'] = p['nflAthleteId'] +646 row_df['college_id'] = p['collegeId'] +647 row_df['college_team'] = p['collegeTeam'] +648 row_df['college_conference'] = p['collegeConference'] +649 row_df['nfl_team'] = p['nflTeam'] +650 row_df['draft_year'] = p['year'] +651 row_df['draft_pick_overall'] = p['overall'] +652 row_df['draft_round'] = p['round'] +653 row_df['draft_round_pick'] = p['pick'] +654 row_df['player_name'] = p['name'] +655 row_df['player_position'] = p['position'] +656 row_df['player_height'] = p['height'] +657 row_df['player_weight'] = p['weight'] +658 row_df['pre_draft_ranking'] = p['preDraftRanking'] +659 row_df['pre_draft_position_ranking'] = p['preDraftPositionRanking'] +660 row_df['pre_draft_grade'] = p['preDraftGrade'] +661 row_df['player_hometown_city'] = p['hometownInfo']['city'] +662 row_df['player_hometown_state'] = p['hometownInfo']['state'] +663 row_df['player_hometown_country'] = p['hometownInfo']['country'] +664 row_df['player_hometown_latitude'] = p['hometownInfo']['latitude'] +665 row_df['player_hometown_longitude'] = p['hometownInfo']['longitude'] +666 row_df['player_hometown_county_fips'] = p['hometownInfo']['countyFips'] +667 +668 nfl_draft_df = pd.concat([nfl_draft_df, row_df], ignore_index=True) +669 del row_df +670 +671 if len(nfl_draft_df) == 0: +672 logging.error( +673 "The CFBD API accepted your inputs, " + +674 "but found no data within your specified input paramaters." + +675 " Please double check your input paramaters." +676 ) +677 +678 return nfl_draft_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, diff --git a/docs/cfbd_json_py/drives.html b/docs/cfbd_json_py/drives.html index a002848..2f6db74 100644 --- a/docs/cfbd_json_py/drives.html +++ b/docs/cfbd_json_py/drives.html @@ -55,7 +55,7 @@
@@ -613,533 +612,533 @@1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/07/2023 10:16 AM EDT + 2# Last Updated Date: 10/23/2023 04:09 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: drives.py 5# Purpose: Houses functions pertaining to CFB drive data within the CFBD API. @@ -63,541 +63,540 @@7 8from datetime import datetime 9import logging - 10import time - 11import pandas as pd - 12import requests - 13from tqdm import tqdm - 14 - 15from cfbd_json_py.utls import get_cfbd_api_token + 10import pandas as pd + 11import requests + 12from tqdm import tqdm + 13 + 14from cfbd_json_py.utls import get_cfbd_api_token + 15 16 - 17 - 18def get_cfbd_drives_info( - 19 season: int, - 20 api_key: str = None, - 21 api_key_dir: str = None, - 22 season_type: str = "regular", - 23 week: int = None, - 24 team: str = None, - 25 offensive_team: str = None, - 26 defensive_team: str = None, - 27 conference_abv: str = None, - 28 offensive_conference_abv: str = None, - 29 defensive_conference_abv: str = None, - 30 ncaa_division: str = "fbs", - 31 return_as_dict: bool = False): - 32 """ - 33 Retrives a list of CFB drives from the CFBD API. - 34 - 35 Parameters - 36 ---------- - 37 `season` (int, mandatory): - 38 Required argument. - 39 Specifies the season you want CFB drive information from. - 40 This must be specified, otherwise this package, and by extension - 41 the CFBD API, will not accept the request to get CFB drive information. - 42 - 43 `api_key` (str, optional): - 44 Semi-optional argument. - 45 If `api_key` is null, this function will attempt to load a CFBD API key - 46 from the python environment, or from a file on this computer. - 47 If `api_key` is not null, this function will automatically assume that the - 48 inputted `api_key` is a valid CFBD API key. - 49 - 50 `api_key_dir` (str, optional): - 51 Optional argument. - 52 If `api_key` is set to a string non-empty string, this variable is ignored. - 53 If `api_key_dir` is null, and `api_key` is null, - 54 this function will try to find a CFBD API key file in this user's home directory. - 55 If `api_key_dir` is set to a string, and `api_key` is null, - 56 this function will assume that `api_key_dir` is a directory, - 57 and will try to find a CFBD API key file in that directory. - 58 - 59 `season_type` (str, semi-optional): - 60 Semi-optional argument. - 61 By defualt, this will be set to "regular", for the CFB regular season. - 62 If you want CFB drive data for non-regular season games, - 63 set `season_type` to "postseason". - 64 If `season_type` is set to anything but "regular" or "postseason", - 65 a `ValueError()` will be raised. - 66 - 67 `week` (int, optional): - 68 Optional argument. - 69 If `week` is set to an integer, this function will attempt - 70 to load CFB drive data from games in that season, and that week. - 71 - 72 `team` (str, optional): - 73 Optional argument. - 74 If you only want CFB drive data for a team, - 75 regardless if they are the home/away team, - 76 set `team` to the name of the team you want CFB drive data from. - 77 - 78 `offensive_team` (str, optional): - 79 Optional argument. - 80 If you only want CFB drive data from a team, while they are on offense, - 81 regardless if they are the home/away team, - 82 set `team` to the name of the team you want CFB drive data from. - 83 - 84 `defensive_team` (str, optional): - 85 Optional argument. - 86 If you only want CFB drive data from a team, while they are on defense, - 87 regardless if they are the home/away team, - 88 set `team` to the name of the team you want CFB drive data from. - 89 - 90 `conference_abv` (str, optional): - 91 Optional argument. - 92 If you only want CFB drive data from games - 93 involving teams from a specific confrence, - 94 set `conference_abv` to the abbreviation - 95 of the conference you want CFB drive data from. - 96 For a list of confrences, - 97 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` - 98 function. - 99 -100 `offensive_conference_abv` (str, optional): -101 Optional argument. -102 If you only want CFB drive data from games -103 where the offensive team is from a specific confrenece, -104 set `conference_abv` to the abbreviation -105 of the conference you want CFB drive data from. -106 For a list of confrences, -107 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` -108 function. -109 -110 `defensive_conference_abv` (str, optional): -111 Optional argument. -112 If you only want CFB drive data from games -113 where the defensive team is from a specific confrenece, -114 set `conference_abv` to the abbreviation -115 of the conference you want CFB drive data from. -116 For a list of confrences, -117 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` -118 function. -119 -120 `ncaa_division` (str, semi-optional): -121 Semi-optional argument. -122 By default, `ncaa_division` will be set to "fbs", -123 short for the Football Bowl Subdivision (FBS), -124 formerly known as D1-A (read as "division one single A"), -125 the highest level in the NCAA football pyramid, -126 where teams can scolarship up to 85 players -127 on their football team soley for athletic ability, -128 and often have the largest athletics budgets -129 within the NCAA. -130 -131 Other valid inputs are: -132 - "fcs": Football Championship Subdivision (FCS), -133 formerly known as D1-AA (read as "division one double A"). -134 An FCS school is still in the 1st division of the NCAA, -135 making them elligable for the March Madness tournament, -136 but may not have the resources to compete at the FBS level -137 at this time. FCS schools are limited to 63 athletic scolarships -138 for football. -139 - "ii": NCAA Division II. Schools in this and D3 are not -140 elligable for the March Madness tournament, -141 and are limited to 36 athletic scolarships for their football team. -142 - "iii": NCAA Division III. The largest single division within the -143 NCAA football pyramid. -144 D3 schools have the distinction of being part of -145 the only NCAA division that cannot give out scolarships soley -146 for athletic ability. -147 -148 `return_as_dict` (bool, semi-optional): -149 Semi-optional argument. -150 If you want this function to return the data as a dictionary (read: JSON object), -151 instead of a pandas `DataFrame` object, -152 set `return_as_dict` to `True`. -153 -154 Usage -155 ---------- -156 ``` -157 import time -158 -159 from cfbd_json_py.drives import get_cfbd_drives_info -160 -161 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -162 -163 if cfbd_key != "tigersAreAwsome": -164 print("Using the user's API key declared in this script for this example.") -165 -166 # Get CFB Drive data from the 2020 CFB season. -167 print("Get CFB Drive data from the 2020 CFB season.") -168 json_data = get_cfbd_drives_info( -169 api_key=cfbd_key, -170 season=2020 -171 ) -172 print(json_data) -173 time.sleep(5) -174 -175 # Get CFB Drive data from week 10 of the 2020 CFB season. -176 print("Get CFB Drive data from week 10 of the 2020 CFB season.") -177 json_data = get_cfbd_drives_info( -178 api_key=cfbd_key, -179 season=2020, -180 week=10 -181 ) -182 print(json_data) -183 time.sleep(5) -184 -185 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats -186 # Football Team. -187 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") -188 json_data = get_cfbd_drives_info( -189 api_key=cfbd_key, -190 season=2020, -191 team="Cincinnati" -192 ) -193 print(json_data) -194 time.sleep(5) -195 -196 # Get CFB Drive data from games involving the 2020 Ohio Bobcats -197 # Football Team, when Ohio was on offense. -198 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") -199 json_data = get_cfbd_drives_info( -200 api_key=cfbd_key, -201 season=2020, -202 offensive_team="Ohio" -203 ) -204 print(json_data) -205 time.sleep(5) -206 -207 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes -208 # Football Team, when Ohio was on offense. -209 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -210 json_data = get_cfbd_drives_info( -211 api_key=cfbd_key, -212 season=2020, -213 defensive_team="Ohio State" -214 ) -215 print(json_data) -216 time.sleep(5) -217 -218 # Get CFB Drive data from Big 12 games in the 2020 CFB season. -219 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -220 json_data = get_cfbd_drives_info( -221 api_key=cfbd_key, -222 season=2020, -223 conference_abv="B12" -224 ) -225 print(json_data) -226 time.sleep(5) -227 -228 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, -229 # where the Big 10 team was on offense. -230 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -231 json_data = get_cfbd_drives_info( -232 api_key=cfbd_key, -233 season=2020, -234 offensive_conference_abv="B1G" -235 ) -236 print(json_data) -237 time.sleep(5) -238 -239 # Get CFB Drive data from Mid-American Conference (MAC) games -240 # in the 2020 CFB season, where the MAC team was on offense. -241 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -242 json_data = get_cfbd_drives_info( -243 api_key=cfbd_key, -244 season=2020, -245 defensive_conference_abv="MAC" -246 ) -247 print(json_data) -248 time.sleep(5) -249 -250 # Get CFB Drive data from Football Championship Subdivision (FCS) games -251 # in week 3 ofthe 2020 CFB season, -252 # where the MAC team was on offense. -253 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -254 json_data = get_cfbd_drives_info( -255 api_key=cfbd_key, -256 season=2020, -257 week=3, -258 ncaa_division="fcs" -259 ) -260 print(json_data) -261 time.sleep(5) -262 -263 # You can also tell this function to just return the API call as -264 # a Dictionary (read: JSON) object. -265 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -266 json_data = get_cfbd_drives_info( -267 season=2020, -268 week=10, -269 api_key=cfbd_key, -270 return_as_dict=True -271 ) -272 print(json_data) -273 -274 else: -275 # Alternatively, if the CFBD API key exists in this python environment, -276 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -277 # you could just call these functions directly, without setting the API key -278 # in the script. -279 print("Using the user's API key suposedly loaded into this python environment for this example.") -280 -281 # Get CFB Drive data from the 2020 CFB season. -282 print("Get CFB Drive data from the 2020 CFB season.") -283 json_data = get_cfbd_drives_info( -284 season=2020 -285 ) -286 print(json_data) -287 time.sleep(5) -288 -289 # Get CFB Drive data from week 10 of the 2020 CFB season. -290 print("Get CFB Drive data from week 10 of the 2020 CFB season.") -291 json_data = get_cfbd_drives_info( -292 season=2020, -293 week=10 -294 ) -295 print(json_data) -296 time.sleep(5) -297 -298 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats -299 # Football Team. -300 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") -301 json_data = get_cfbd_drives_info( -302 season=2020, -303 team="Cincinnati" -304 ) -305 print(json_data) -306 time.sleep(5) -307 -308 # Get CFB Drive data from games involving the 2020 Ohio Bobcats -309 # Football Team, when Ohio was on offense. -310 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") -311 json_data = get_cfbd_drives_info( -312 season=2020, -313 offensive_team="Ohio" -314 ) -315 print(json_data) -316 time.sleep(5) -317 -318 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes -319 # Football Team, when Ohio was on offense. -320 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -321 json_data = get_cfbd_drives_info( -322 season=2020, -323 defensive_team="Ohio State" -324 ) -325 print(json_data) -326 time.sleep(5) -327 -328 # Get CFB Drive data from Big 12 games in the 2020 CFB season. -329 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -330 json_data = get_cfbd_drives_info( -331 season=2020, -332 conference_abv="B12" -333 ) -334 print(json_data) -335 time.sleep(5) -336 -337 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, -338 # where the Big 10 team was on offense. -339 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -340 json_data = get_cfbd_drives_info( -341 season=2020, -342 offensive_conference_abv="B1G" -343 ) -344 print(json_data) -345 time.sleep(5) -346 -347 # Get CFB Drive data from Mid-American Conference (MAC) games -348 # in the 2020 CFB season, where the MAC team was on offense. -349 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -350 json_data = get_cfbd_drives_info( -351 season=2020, -352 defensive_conference_abv="MAC" -353 ) -354 print(json_data) -355 time.sleep(5) -356 -357 # Get CFB Drive data from Football Championship Subdivision (FCS) games -358 # in week 3 ofthe 2020 CFB season, -359 # where the MAC team was on offense. -360 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -361 json_data = get_cfbd_drives_info( -362 season=2020, -363 week=3, -364 ncaa_division="fcs" -365 ) -366 print(json_data) -367 time.sleep(5) -368 -369 # You can also tell this function to just return the API call as -370 # a Dictionary (read: JSON) object. -371 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -372 json_data = get_cfbd_drives_info( -373 season=2020, -374 week=10, -375 return_as_dict=True -376 ) -377 print(json_data) -378 -379 ``` -380 -381 Returns -382 ---------- -383 A pandas `DataFrame` object with CFB drive data, -384 or (if `return_as_dict` is set to `True`) -385 a dictionary object with CFB drive data. -386 -387 """ -388 now = datetime.now() -389 cfb_drives_df = pd.DataFrame() -390 row_df = pd.DataFrame() -391 url = "https://api.collegefootballdata.com/drives" -392 -393 # Input validation -394 ######################################################################################################################################################################################################## -395 -396 if api_key != None: -397 real_api_key = api_key -398 del api_key -399 else: -400 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -401 -402 if real_api_key == "tigersAreAwsome": -403 raise ValueError( -404 "You actually need to change `cfbd_key` to your CFBD API key.") -405 elif "Bearer " in real_api_key: -406 pass -407 elif "Bearer" in real_api_key: -408 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -409 else: -410 real_api_key = "Bearer " + real_api_key -411 -412 if season == None: -413 # This should never happen without user tampering, but if it does, -414 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -415 raise SystemError( -416 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + -417 " and the function got to this point in the code." + -418 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + -419 "https://github.com/armstjc/cfbd-json-py/issues" -420 ) -421 elif season > now.year: -422 raise ValueError(f"`season` cannot be greater than {season}.") -423 elif season < 1869: -424 raise ValueError(f"`season` cannot be less than 1869.") -425 -426 if season_type != "regular" and season_type != "postseason": -427 raise ValueError( -428 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") -429 -430 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ -431 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": -432 pass -433 else: -434 raise ValueError( -435 "An invalid NCAA Division was inputted when calling this function." + -436 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + -437 f"\n\nYou entered:\n{ncaa_division}" -438 ) -439 -440 # URL builder -441 ######################################################################################################################################################################################################## -442 -443 # Required by API -444 url += f"?seasonType={season_type}" -445 -446 url += f"&year={season}" -447 -448 if week != None: -449 url += f"&week={week}" -450 -451 if team != None: -452 url += f"&team={team}" -453 -454 if offensive_team != None: -455 url += f"&offense={offensive_team}" -456 -457 if defensive_team != None: -458 url += f"&defense={defensive_team}" -459 -460 if conference_abv != None: -461 url += f"&conference={conference_abv}" -462 -463 if offensive_conference_abv != None: -464 url += f"&offenseConference={offensive_conference_abv}" -465 -466 if defensive_conference_abv != None: -467 url += f"&defenseConference={defensive_conference_abv}" -468 -469 if ncaa_division != None: -470 url += f"&classification={ncaa_division.lower}" -471 -472 headers = { -473 'Authorization': f'{real_api_key}', -474 'accept': 'application/json' -475 } -476 -477 response = requests.get(url, headers=headers) -478 time.sleep(0.1) -479 -480 if response.status_code == 200: -481 pass -482 elif response.status_code == 401: -483 raise ConnectionRefusedError( -484 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -485 ) -486 else: -487 raise ConnectionError( -488 f'Could not connect.\nHTTP Status code {response.status_code}' -489 ) -490 -491 json_data = response.json() -492 -493 if return_as_dict == True: -494 return json_data -495 -496 for drive in tqdm(json_data): -497 offense = drive['offense'] -498 row_df = pd.DataFrame( -499 { -500 "offense": offense -501 }, index=[0] -502 ) -503 del offense -504 -505 row_df['offense_conference'] = drive['offense_conference'] -506 row_df['defense'] = drive['defense'] -507 row_df['defense_conference'] = drive['defense_conference'] -508 row_df['game_id'] = drive['game_id'] -509 row_df['drive_id'] = drive['id'] -510 row_df['drive_number'] = drive['drive_number'] -511 row_df['is_scoring_drive'] = drive['scoring'] -512 row_df['drive_start_period'] = drive['start_period'] -513 row_df['drive_start_yardline'] = drive['start_yardline'] -514 row_df['drive_start_yards_to_goal'] = drive['start_yards_to_goal'] -515 row_df['drive_start_time_minutes'] = drive['start_time']['minutes'] -516 row_df['drive_start_time_seconds'] = drive['start_time']['seconds'] -517 row_df['drive_end_period'] = drive['end_period'] -518 row_df['drive_end_yardline'] = drive['end_yardline'] -519 row_df['drive_end_yards_to_goal'] = drive['end_yards_to_goal'] -520 row_df['drive_end_time_minutes'] = drive['end_time']['minutes'] -521 row_df['drive_end_time_seconds'] = drive['end_time']['seconds'] -522 row_df['drive_elapsed_minutes'] = drive['elapsed']['minutes'] -523 row_df['drive_elapsed_seconds'] = drive['elapsed']['seconds'] -524 row_df['drive_plays'] = drive['plays'] -525 row_df['drive_yards'] = drive['yards'] -526 row_df['drive_result'] = drive['drive_result'] -527 row_df['is_home_offense'] = drive['is_home_offense'] -528 row_df['start_offense_score'] = drive['start_offense_score'] -529 row_df['start_defense_score'] = drive['start_defense_score'] -530 row_df['end_offense_score'] = drive['end_offense_score'] -531 row_df['end_defense_score'] = drive['end_defense_score'] -532 -533 cfb_drives_df = pd.concat([cfb_drives_df, row_df], ignore_index=True) -534 -535 del row_df -536 -537 if len(cfb_drives_df) == 0: -538 logging.error( -539 "The CFBD API accepted your inputs, " + -540 "but found no data within your specified input paramaters." + -541 " Please double check your input paramaters." -542 ) -543 -544 return cfb_drives_df + 17def get_cfbd_drives_info( + 18 season: int, + 19 api_key: str = None, + 20 api_key_dir: str = None, + 21 season_type: str = "regular", + 22 week: int = None, + 23 team: str = None, + 24 offensive_team: str = None, + 25 defensive_team: str = None, + 26 conference_abv: str = None, + 27 offensive_conference_abv: str = None, + 28 defensive_conference_abv: str = None, + 29 ncaa_division: str = "fbs", + 30 return_as_dict: bool = False): + 31 """ + 32 Retrives a list of CFB drives from the CFBD API. + 33 + 34 Parameters + 35 ---------- + 36 `season` (int, mandatory): + 37 Required argument. + 38 Specifies the season you want CFB drive information from. + 39 This must be specified, otherwise this package, and by extension + 40 the CFBD API, will not accept the request to get CFB drive information. + 41 + 42 `api_key` (str, optional): + 43 Semi-optional argument. + 44 If `api_key` is null, this function will attempt to load a CFBD API key + 45 from the python environment, or from a file on this computer. + 46 If `api_key` is not null, this function will automatically assume that the + 47 inputted `api_key` is a valid CFBD API key. + 48 + 49 `api_key_dir` (str, optional): + 50 Optional argument. + 51 If `api_key` is set to am empty string, this variable is ignored. + 52 If `api_key_dir` is null, and `api_key` is null, + 53 this function will try to find a CFBD API key file in this user's home directory. + 54 If `api_key_dir` is set to a string, and `api_key` is null, + 55 this function will assume that `api_key_dir` is a directory, + 56 and will try to find a CFBD API key file in that directory. + 57 + 58 `season_type` (str, semi-optional): + 59 Semi-optional argument. + 60 By defualt, this will be set to "regular", for the CFB regular season. + 61 If you want CFB drive data for non-regular season games, + 62 set `season_type` to "postseason". + 63 If `season_type` is set to anything but "regular" or "postseason", + 64 a `ValueError()` will be raised. + 65 + 66 `week` (int, optional): + 67 Optional argument. + 68 If `week` is set to an integer, this function will attempt + 69 to load CFB drive data from games in that season, and that week. + 70 + 71 `team` (str, optional): + 72 Optional argument. + 73 If you only want CFB drive data for a team, + 74 regardless if they are the home/away team, + 75 set `team` to the name of the team you want CFB drive data from. + 76 + 77 `offensive_team` (str, optional): + 78 Optional argument. + 79 If you only want CFB drive data from a team, while they are on offense, + 80 regardless if they are the home/away team, + 81 set `team` to the name of the team you want CFB drive data from. + 82 + 83 `defensive_team` (str, optional): + 84 Optional argument. + 85 If you only want CFB drive data from a team, while they are on defense, + 86 regardless if they are the home/away team, + 87 set `team` to the name of the team you want CFB drive data from. + 88 + 89 `conference_abv` (str, optional): + 90 Optional argument. + 91 If you only want CFB drive data from games + 92 involving teams from a specific confrence, + 93 set `conference_abv` to the abbreviation + 94 of the conference you want CFB drive data from. + 95 For a list of confrences, + 96 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` + 97 function. + 98 + 99 `offensive_conference_abv` (str, optional): +100 Optional argument. +101 If you only want CFB drive data from games +102 where the offensive team is from a specific confrenece, +103 set `conference_abv` to the abbreviation +104 of the conference you want CFB drive data from. +105 For a list of confrences, +106 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +107 function. +108 +109 `defensive_conference_abv` (str, optional): +110 Optional argument. +111 If you only want CFB drive data from games +112 where the defensive team is from a specific confrenece, +113 set `conference_abv` to the abbreviation +114 of the conference you want CFB drive data from. +115 For a list of confrences, +116 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +117 function. +118 +119 `ncaa_division` (str, semi-optional): +120 Semi-optional argument. +121 By default, `ncaa_division` will be set to "fbs", +122 short for the Football Bowl Subdivision (FBS), +123 formerly known as D1-A (read as "division one single A"), +124 the highest level in the NCAA football pyramid, +125 where teams can scolarship up to 85 players +126 on their football team soley for athletic ability, +127 and often have the largest athletics budgets +128 within the NCAA. +129 +130 Other valid inputs are: +131 - "fcs": Football Championship Subdivision (FCS), +132 formerly known as D1-AA (read as "division one double A"). +133 An FCS school is still in the 1st division of the NCAA, +134 making them elligable for the March Madness tournament, +135 but may not have the resources to compete at the FBS level +136 at this time. FCS schools are limited to 63 athletic scolarships +137 for football. +138 - "ii": NCAA Division II. Schools in this and D3 are not +139 elligable for the March Madness tournament, +140 and are limited to 36 athletic scolarships for their football team. +141 - "iii": NCAA Division III. The largest single division within the +142 NCAA football pyramid. +143 D3 schools have the distinction of being part of +144 the only NCAA division that cannot give out scolarships soley +145 for athletic ability. +146 +147 `return_as_dict` (bool, semi-optional): +148 Semi-optional argument. +149 If you want this function to return the data as a dictionary (read: JSON object), +150 instead of a pandas `DataFrame` object, +151 set `return_as_dict` to `True`. +152 +153 Usage +154 ---------- +155 ``` +156 import time +157 +158 from cfbd_json_py.drives import get_cfbd_drives_info +159 +160 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +161 +162 if cfbd_key != "tigersAreAwsome": +163 print("Using the user's API key declared in this script for this example.") +164 +165 # Get CFB Drive data from the 2020 CFB season. +166 print("Get CFB Drive data from the 2020 CFB season.") +167 json_data = get_cfbd_drives_info( +168 api_key=cfbd_key, +169 season=2020 +170 ) +171 print(json_data) +172 time.sleep(5) +173 +174 # Get CFB Drive data from week 10 of the 2020 CFB season. +175 print("Get CFB Drive data from week 10 of the 2020 CFB season.") +176 json_data = get_cfbd_drives_info( +177 api_key=cfbd_key, +178 season=2020, +179 week=10 +180 ) +181 print(json_data) +182 time.sleep(5) +183 +184 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats +185 # Football Team. +186 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") +187 json_data = get_cfbd_drives_info( +188 api_key=cfbd_key, +189 season=2020, +190 team="Cincinnati" +191 ) +192 print(json_data) +193 time.sleep(5) +194 +195 # Get CFB Drive data from games involving the 2020 Ohio Bobcats +196 # Football Team, when Ohio was on offense. +197 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") +198 json_data = get_cfbd_drives_info( +199 api_key=cfbd_key, +200 season=2020, +201 offensive_team="Ohio" +202 ) +203 print(json_data) +204 time.sleep(5) +205 +206 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes +207 # Football Team, when Ohio was on offense. +208 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +209 json_data = get_cfbd_drives_info( +210 api_key=cfbd_key, +211 season=2020, +212 defensive_team="Ohio State" +213 ) +214 print(json_data) +215 time.sleep(5) +216 +217 # Get CFB Drive data from Big 12 games in the 2020 CFB season. +218 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +219 json_data = get_cfbd_drives_info( +220 api_key=cfbd_key, +221 season=2020, +222 conference_abv="B12" +223 ) +224 print(json_data) +225 time.sleep(5) +226 +227 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, +228 # where the Big 10 team was on offense. +229 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +230 json_data = get_cfbd_drives_info( +231 api_key=cfbd_key, +232 season=2020, +233 offensive_conference_abv="B1G" +234 ) +235 print(json_data) +236 time.sleep(5) +237 +238 # Get CFB Drive data from Mid-American Conference (MAC) games +239 # in the 2020 CFB season, where the MAC team was on offense. +240 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +241 json_data = get_cfbd_drives_info( +242 api_key=cfbd_key, +243 season=2020, +244 defensive_conference_abv="MAC" +245 ) +246 print(json_data) +247 time.sleep(5) +248 +249 # Get CFB Drive data from Football Championship Subdivision (FCS) games +250 # in week 3 ofthe 2020 CFB season, +251 # where the MAC team was on offense. +252 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +253 json_data = get_cfbd_drives_info( +254 api_key=cfbd_key, +255 season=2020, +256 week=3, +257 ncaa_division="fcs" +258 ) +259 print(json_data) +260 time.sleep(5) +261 +262 # You can also tell this function to just return the API call as +263 # a Dictionary (read: JSON) object. +264 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +265 json_data = get_cfbd_drives_info( +266 season=2020, +267 week=10, +268 api_key=cfbd_key, +269 return_as_dict=True +270 ) +271 print(json_data) +272 +273 else: +274 # Alternatively, if the CFBD API key exists in this python environment, +275 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +276 # you could just call these functions directly, without setting the API key +277 # in the script. +278 print("Using the user's API key suposedly loaded into this python environment for this example.") +279 +280 # Get CFB Drive data from the 2020 CFB season. +281 print("Get CFB Drive data from the 2020 CFB season.") +282 json_data = get_cfbd_drives_info( +283 season=2020 +284 ) +285 print(json_data) +286 time.sleep(5) +287 +288 # Get CFB Drive data from week 10 of the 2020 CFB season. +289 print("Get CFB Drive data from week 10 of the 2020 CFB season.") +290 json_data = get_cfbd_drives_info( +291 season=2020, +292 week=10 +293 ) +294 print(json_data) +295 time.sleep(5) +296 +297 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats +298 # Football Team. +299 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") +300 json_data = get_cfbd_drives_info( +301 season=2020, +302 team="Cincinnati" +303 ) +304 print(json_data) +305 time.sleep(5) +306 +307 # Get CFB Drive data from games involving the 2020 Ohio Bobcats +308 # Football Team, when Ohio was on offense. +309 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") +310 json_data = get_cfbd_drives_info( +311 season=2020, +312 offensive_team="Ohio" +313 ) +314 print(json_data) +315 time.sleep(5) +316 +317 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes +318 # Football Team, when Ohio was on offense. +319 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +320 json_data = get_cfbd_drives_info( +321 season=2020, +322 defensive_team="Ohio State" +323 ) +324 print(json_data) +325 time.sleep(5) +326 +327 # Get CFB Drive data from Big 12 games in the 2020 CFB season. +328 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +329 json_data = get_cfbd_drives_info( +330 season=2020, +331 conference_abv="B12" +332 ) +333 print(json_data) +334 time.sleep(5) +335 +336 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, +337 # where the Big 10 team was on offense. +338 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +339 json_data = get_cfbd_drives_info( +340 season=2020, +341 offensive_conference_abv="B1G" +342 ) +343 print(json_data) +344 time.sleep(5) +345 +346 # Get CFB Drive data from Mid-American Conference (MAC) games +347 # in the 2020 CFB season, where the MAC team was on offense. +348 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +349 json_data = get_cfbd_drives_info( +350 season=2020, +351 defensive_conference_abv="MAC" +352 ) +353 print(json_data) +354 time.sleep(5) +355 +356 # Get CFB Drive data from Football Championship Subdivision (FCS) games +357 # in week 3 ofthe 2020 CFB season, +358 # where the MAC team was on offense. +359 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +360 json_data = get_cfbd_drives_info( +361 season=2020, +362 week=3, +363 ncaa_division="fcs" +364 ) +365 print(json_data) +366 time.sleep(5) +367 +368 # You can also tell this function to just return the API call as +369 # a Dictionary (read: JSON) object. +370 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +371 json_data = get_cfbd_drives_info( +372 season=2020, +373 week=10, +374 return_as_dict=True +375 ) +376 print(json_data) +377 +378 ``` +379 +380 Returns +381 ---------- +382 A pandas `DataFrame` object with CFB drive data, +383 or (if `return_as_dict` is set to `True`) +384 a dictionary object with CFB drive data. +385 +386 """ +387 now = datetime.now() +388 cfb_drives_df = pd.DataFrame() +389 row_df = pd.DataFrame() +390 url = "https://api.collegefootballdata.com/drives" +391 +392 # Input validation +393 ######################################################################################################################################################################################################## +394 +395 if api_key != None: +396 real_api_key = api_key +397 del api_key +398 else: +399 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +400 +401 if real_api_key == "tigersAreAwsome": +402 raise ValueError( +403 "You actually need to change `cfbd_key` to your CFBD API key.") +404 elif "Bearer " in real_api_key: +405 pass +406 elif "Bearer" in real_api_key: +407 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +408 else: +409 real_api_key = "Bearer " + real_api_key +410 +411 if season == None: +412 # This should never happen without user tampering, but if it does, +413 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +414 raise SystemError( +415 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +416 " and the function got to this point in the code." + +417 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +418 "https://github.com/armstjc/cfbd-json-py/issues" +419 ) +420 elif season > now.year: +421 raise ValueError(f"`season` cannot be greater than {season}.") +422 elif season < 1869: +423 raise ValueError(f"`season` cannot be less than 1869.") +424 +425 if season_type != "regular" and season_type != "postseason": +426 raise ValueError( +427 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +428 +429 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ +430 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": +431 pass +432 else: +433 raise ValueError( +434 "An invalid NCAA Division was inputted when calling this function." + +435 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + +436 f"\n\nYou entered:\n{ncaa_division}" +437 ) +438 +439 # URL builder +440 ######################################################################################################################################################################################################## +441 +442 # Required by API +443 url += f"?seasonType={season_type}" +444 +445 url += f"&year={season}" +446 +447 if week != None: +448 url += f"&week={week}" +449 +450 if team != None: +451 url += f"&team={team}" +452 +453 if offensive_team != None: +454 url += f"&offense={offensive_team}" +455 +456 if defensive_team != None: +457 url += f"&defense={defensive_team}" +458 +459 if conference_abv != None: +460 url += f"&conference={conference_abv}" +461 +462 if offensive_conference_abv != None: +463 url += f"&offenseConference={offensive_conference_abv}" +464 +465 if defensive_conference_abv != None: +466 url += f"&defenseConference={defensive_conference_abv}" +467 +468 if ncaa_division != None: +469 url += f"&classification={ncaa_division.lower}" +470 +471 headers = { +472 'Authorization': f'{real_api_key}', +473 'accept': 'application/json' +474 } +475 +476 response = requests.get(url, headers=headers) +477 +478 +479 if response.status_code == 200: +480 pass +481 elif response.status_code == 401: +482 raise ConnectionRefusedError( +483 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +484 ) +485 else: +486 raise ConnectionError( +487 f'Could not connect.\nHTTP Status code {response.status_code}' +488 ) +489 +490 json_data = response.json() +491 +492 if return_as_dict == True: +493 return json_data +494 +495 for drive in tqdm(json_data): +496 offense = drive['offense'] +497 row_df = pd.DataFrame( +498 { +499 "offense": offense +500 }, index=[0] +501 ) +502 del offense +503 +504 row_df['offense_conference'] = drive['offense_conference'] +505 row_df['defense'] = drive['defense'] +506 row_df['defense_conference'] = drive['defense_conference'] +507 row_df['game_id'] = drive['game_id'] +508 row_df['drive_id'] = drive['id'] +509 row_df['drive_number'] = drive['drive_number'] +510 row_df['is_scoring_drive'] = drive['scoring'] +511 row_df['drive_start_period'] = drive['start_period'] +512 row_df['drive_start_yardline'] = drive['start_yardline'] +513 row_df['drive_start_yards_to_goal'] = drive['start_yards_to_goal'] +514 row_df['drive_start_time_minutes'] = drive['start_time']['minutes'] +515 row_df['drive_start_time_seconds'] = drive['start_time']['seconds'] +516 row_df['drive_end_period'] = drive['end_period'] +517 row_df['drive_end_yardline'] = drive['end_yardline'] +518 row_df['drive_end_yards_to_goal'] = drive['end_yards_to_goal'] +519 row_df['drive_end_time_minutes'] = drive['end_time']['minutes'] +520 row_df['drive_end_time_seconds'] = drive['end_time']['seconds'] +521 row_df['drive_elapsed_minutes'] = drive['elapsed']['minutes'] +522 row_df['drive_elapsed_seconds'] = drive['elapsed']['seconds'] +523 row_df['drive_plays'] = drive['plays'] +524 row_df['drive_yards'] = drive['yards'] +525 row_df['drive_result'] = drive['drive_result'] +526 row_df['is_home_offense'] = drive['is_home_offense'] +527 row_df['start_offense_score'] = drive['start_offense_score'] +528 row_df['start_defense_score'] = drive['start_defense_score'] +529 row_df['end_offense_score'] = drive['end_offense_score'] +530 row_df['end_defense_score'] = drive['end_defense_score'] +531 +532 cfb_drives_df = pd.concat([cfb_drives_df, row_df], ignore_index=True) +533 +534 del row_df +535 +536 if len(cfb_drives_df) == 0: +537 logging.error( +538 "The CFBD API accepted your inputs, " + +539 "but found no data within your specified input paramaters." + +540 " Please double check your input paramaters." +541 ) +542 +543 return cfb_drives_df
19def get_cfbd_drives_info( - 20 season: int, - 21 api_key: str = None, - 22 api_key_dir: str = None, - 23 season_type: str = "regular", - 24 week: int = None, - 25 team: str = None, - 26 offensive_team: str = None, - 27 defensive_team: str = None, - 28 conference_abv: str = None, - 29 offensive_conference_abv: str = None, - 30 defensive_conference_abv: str = None, - 31 ncaa_division: str = "fbs", - 32 return_as_dict: bool = False): - 33 """ - 34 Retrives a list of CFB drives from the CFBD API. - 35 - 36 Parameters - 37 ---------- - 38 `season` (int, mandatory): - 39 Required argument. - 40 Specifies the season you want CFB drive information from. - 41 This must be specified, otherwise this package, and by extension - 42 the CFBD API, will not accept the request to get CFB drive information. - 43 - 44 `api_key` (str, optional): - 45 Semi-optional argument. - 46 If `api_key` is null, this function will attempt to load a CFBD API key - 47 from the python environment, or from a file on this computer. - 48 If `api_key` is not null, this function will automatically assume that the - 49 inputted `api_key` is a valid CFBD API key. - 50 - 51 `api_key_dir` (str, optional): - 52 Optional argument. - 53 If `api_key` is set to a string non-empty string, this variable is ignored. - 54 If `api_key_dir` is null, and `api_key` is null, - 55 this function will try to find a CFBD API key file in this user's home directory. - 56 If `api_key_dir` is set to a string, and `api_key` is null, - 57 this function will assume that `api_key_dir` is a directory, - 58 and will try to find a CFBD API key file in that directory. - 59 - 60 `season_type` (str, semi-optional): - 61 Semi-optional argument. - 62 By defualt, this will be set to "regular", for the CFB regular season. - 63 If you want CFB drive data for non-regular season games, - 64 set `season_type` to "postseason". - 65 If `season_type` is set to anything but "regular" or "postseason", - 66 a `ValueError()` will be raised. - 67 - 68 `week` (int, optional): - 69 Optional argument. - 70 If `week` is set to an integer, this function will attempt - 71 to load CFB drive data from games in that season, and that week. - 72 - 73 `team` (str, optional): - 74 Optional argument. - 75 If you only want CFB drive data for a team, - 76 regardless if they are the home/away team, - 77 set `team` to the name of the team you want CFB drive data from. - 78 - 79 `offensive_team` (str, optional): - 80 Optional argument. - 81 If you only want CFB drive data from a team, while they are on offense, - 82 regardless if they are the home/away team, - 83 set `team` to the name of the team you want CFB drive data from. - 84 - 85 `defensive_team` (str, optional): - 86 Optional argument. - 87 If you only want CFB drive data from a team, while they are on defense, - 88 regardless if they are the home/away team, - 89 set `team` to the name of the team you want CFB drive data from. - 90 - 91 `conference_abv` (str, optional): - 92 Optional argument. - 93 If you only want CFB drive data from games - 94 involving teams from a specific confrence, - 95 set `conference_abv` to the abbreviation - 96 of the conference you want CFB drive data from. - 97 For a list of confrences, - 98 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` - 99 function. -100 -101 `offensive_conference_abv` (str, optional): -102 Optional argument. -103 If you only want CFB drive data from games -104 where the offensive team is from a specific confrenece, -105 set `conference_abv` to the abbreviation -106 of the conference you want CFB drive data from. -107 For a list of confrences, -108 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` -109 function. -110 -111 `defensive_conference_abv` (str, optional): -112 Optional argument. -113 If you only want CFB drive data from games -114 where the defensive team is from a specific confrenece, -115 set `conference_abv` to the abbreviation -116 of the conference you want CFB drive data from. -117 For a list of confrences, -118 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` -119 function. -120 -121 `ncaa_division` (str, semi-optional): -122 Semi-optional argument. -123 By default, `ncaa_division` will be set to "fbs", -124 short for the Football Bowl Subdivision (FBS), -125 formerly known as D1-A (read as "division one single A"), -126 the highest level in the NCAA football pyramid, -127 where teams can scolarship up to 85 players -128 on their football team soley for athletic ability, -129 and often have the largest athletics budgets -130 within the NCAA. -131 -132 Other valid inputs are: -133 - "fcs": Football Championship Subdivision (FCS), -134 formerly known as D1-AA (read as "division one double A"). -135 An FCS school is still in the 1st division of the NCAA, -136 making them elligable for the March Madness tournament, -137 but may not have the resources to compete at the FBS level -138 at this time. FCS schools are limited to 63 athletic scolarships -139 for football. -140 - "ii": NCAA Division II. Schools in this and D3 are not -141 elligable for the March Madness tournament, -142 and are limited to 36 athletic scolarships for their football team. -143 - "iii": NCAA Division III. The largest single division within the -144 NCAA football pyramid. -145 D3 schools have the distinction of being part of -146 the only NCAA division that cannot give out scolarships soley -147 for athletic ability. -148 -149 `return_as_dict` (bool, semi-optional): -150 Semi-optional argument. -151 If you want this function to return the data as a dictionary (read: JSON object), -152 instead of a pandas `DataFrame` object, -153 set `return_as_dict` to `True`. -154 -155 Usage -156 ---------- -157 ``` -158 import time -159 -160 from cfbd_json_py.drives import get_cfbd_drives_info -161 -162 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -163 -164 if cfbd_key != "tigersAreAwsome": -165 print("Using the user's API key declared in this script for this example.") -166 -167 # Get CFB Drive data from the 2020 CFB season. -168 print("Get CFB Drive data from the 2020 CFB season.") -169 json_data = get_cfbd_drives_info( -170 api_key=cfbd_key, -171 season=2020 -172 ) -173 print(json_data) -174 time.sleep(5) -175 -176 # Get CFB Drive data from week 10 of the 2020 CFB season. -177 print("Get CFB Drive data from week 10 of the 2020 CFB season.") -178 json_data = get_cfbd_drives_info( -179 api_key=cfbd_key, -180 season=2020, -181 week=10 -182 ) -183 print(json_data) -184 time.sleep(5) -185 -186 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats -187 # Football Team. -188 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") -189 json_data = get_cfbd_drives_info( -190 api_key=cfbd_key, -191 season=2020, -192 team="Cincinnati" -193 ) -194 print(json_data) -195 time.sleep(5) -196 -197 # Get CFB Drive data from games involving the 2020 Ohio Bobcats -198 # Football Team, when Ohio was on offense. -199 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") -200 json_data = get_cfbd_drives_info( -201 api_key=cfbd_key, -202 season=2020, -203 offensive_team="Ohio" -204 ) -205 print(json_data) -206 time.sleep(5) -207 -208 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes -209 # Football Team, when Ohio was on offense. -210 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -211 json_data = get_cfbd_drives_info( -212 api_key=cfbd_key, -213 season=2020, -214 defensive_team="Ohio State" -215 ) -216 print(json_data) -217 time.sleep(5) -218 -219 # Get CFB Drive data from Big 12 games in the 2020 CFB season. -220 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -221 json_data = get_cfbd_drives_info( -222 api_key=cfbd_key, -223 season=2020, -224 conference_abv="B12" -225 ) -226 print(json_data) -227 time.sleep(5) -228 -229 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, -230 # where the Big 10 team was on offense. -231 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -232 json_data = get_cfbd_drives_info( -233 api_key=cfbd_key, -234 season=2020, -235 offensive_conference_abv="B1G" -236 ) -237 print(json_data) -238 time.sleep(5) -239 -240 # Get CFB Drive data from Mid-American Conference (MAC) games -241 # in the 2020 CFB season, where the MAC team was on offense. -242 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -243 json_data = get_cfbd_drives_info( -244 api_key=cfbd_key, -245 season=2020, -246 defensive_conference_abv="MAC" -247 ) -248 print(json_data) -249 time.sleep(5) -250 -251 # Get CFB Drive data from Football Championship Subdivision (FCS) games -252 # in week 3 ofthe 2020 CFB season, -253 # where the MAC team was on offense. -254 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -255 json_data = get_cfbd_drives_info( -256 api_key=cfbd_key, -257 season=2020, -258 week=3, -259 ncaa_division="fcs" -260 ) -261 print(json_data) -262 time.sleep(5) -263 -264 # You can also tell this function to just return the API call as -265 # a Dictionary (read: JSON) object. -266 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -267 json_data = get_cfbd_drives_info( -268 season=2020, -269 week=10, -270 api_key=cfbd_key, -271 return_as_dict=True -272 ) -273 print(json_data) -274 -275 else: -276 # Alternatively, if the CFBD API key exists in this python environment, -277 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -278 # you could just call these functions directly, without setting the API key -279 # in the script. -280 print("Using the user's API key suposedly loaded into this python environment for this example.") -281 -282 # Get CFB Drive data from the 2020 CFB season. -283 print("Get CFB Drive data from the 2020 CFB season.") -284 json_data = get_cfbd_drives_info( -285 season=2020 -286 ) -287 print(json_data) -288 time.sleep(5) -289 -290 # Get CFB Drive data from week 10 of the 2020 CFB season. -291 print("Get CFB Drive data from week 10 of the 2020 CFB season.") -292 json_data = get_cfbd_drives_info( -293 season=2020, -294 week=10 -295 ) -296 print(json_data) -297 time.sleep(5) -298 -299 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats -300 # Football Team. -301 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") -302 json_data = get_cfbd_drives_info( -303 season=2020, -304 team="Cincinnati" -305 ) -306 print(json_data) -307 time.sleep(5) -308 -309 # Get CFB Drive data from games involving the 2020 Ohio Bobcats -310 # Football Team, when Ohio was on offense. -311 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") -312 json_data = get_cfbd_drives_info( -313 season=2020, -314 offensive_team="Ohio" -315 ) -316 print(json_data) -317 time.sleep(5) -318 -319 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes -320 # Football Team, when Ohio was on offense. -321 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -322 json_data = get_cfbd_drives_info( -323 season=2020, -324 defensive_team="Ohio State" -325 ) -326 print(json_data) -327 time.sleep(5) -328 -329 # Get CFB Drive data from Big 12 games in the 2020 CFB season. -330 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -331 json_data = get_cfbd_drives_info( -332 season=2020, -333 conference_abv="B12" -334 ) -335 print(json_data) -336 time.sleep(5) -337 -338 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, -339 # where the Big 10 team was on offense. -340 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -341 json_data = get_cfbd_drives_info( -342 season=2020, -343 offensive_conference_abv="B1G" -344 ) -345 print(json_data) -346 time.sleep(5) -347 -348 # Get CFB Drive data from Mid-American Conference (MAC) games -349 # in the 2020 CFB season, where the MAC team was on offense. -350 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -351 json_data = get_cfbd_drives_info( -352 season=2020, -353 defensive_conference_abv="MAC" -354 ) -355 print(json_data) -356 time.sleep(5) -357 -358 # Get CFB Drive data from Football Championship Subdivision (FCS) games -359 # in week 3 ofthe 2020 CFB season, -360 # where the MAC team was on offense. -361 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") -362 json_data = get_cfbd_drives_info( -363 season=2020, -364 week=3, -365 ncaa_division="fcs" -366 ) -367 print(json_data) -368 time.sleep(5) -369 -370 # You can also tell this function to just return the API call as -371 # a Dictionary (read: JSON) object. -372 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -373 json_data = get_cfbd_drives_info( -374 season=2020, -375 week=10, -376 return_as_dict=True -377 ) -378 print(json_data) -379 -380 ``` -381 -382 Returns -383 ---------- -384 A pandas `DataFrame` object with CFB drive data, -385 or (if `return_as_dict` is set to `True`) -386 a dictionary object with CFB drive data. -387 -388 """ -389 now = datetime.now() -390 cfb_drives_df = pd.DataFrame() -391 row_df = pd.DataFrame() -392 url = "https://api.collegefootballdata.com/drives" -393 -394 # Input validation -395 ######################################################################################################################################################################################################## -396 -397 if api_key != None: -398 real_api_key = api_key -399 del api_key -400 else: -401 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -402 -403 if real_api_key == "tigersAreAwsome": -404 raise ValueError( -405 "You actually need to change `cfbd_key` to your CFBD API key.") -406 elif "Bearer " in real_api_key: -407 pass -408 elif "Bearer" in real_api_key: -409 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -410 else: -411 real_api_key = "Bearer " + real_api_key -412 -413 if season == None: -414 # This should never happen without user tampering, but if it does, -415 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -416 raise SystemError( -417 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + -418 " and the function got to this point in the code." + -419 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + -420 "https://github.com/armstjc/cfbd-json-py/issues" -421 ) -422 elif season > now.year: -423 raise ValueError(f"`season` cannot be greater than {season}.") -424 elif season < 1869: -425 raise ValueError(f"`season` cannot be less than 1869.") -426 -427 if season_type != "regular" and season_type != "postseason": -428 raise ValueError( -429 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") -430 -431 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ -432 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": -433 pass -434 else: -435 raise ValueError( -436 "An invalid NCAA Division was inputted when calling this function." + -437 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + -438 f"\n\nYou entered:\n{ncaa_division}" -439 ) -440 -441 # URL builder -442 ######################################################################################################################################################################################################## -443 -444 # Required by API -445 url += f"?seasonType={season_type}" -446 -447 url += f"&year={season}" -448 -449 if week != None: -450 url += f"&week={week}" -451 -452 if team != None: -453 url += f"&team={team}" -454 -455 if offensive_team != None: -456 url += f"&offense={offensive_team}" -457 -458 if defensive_team != None: -459 url += f"&defense={defensive_team}" -460 -461 if conference_abv != None: -462 url += f"&conference={conference_abv}" -463 -464 if offensive_conference_abv != None: -465 url += f"&offenseConference={offensive_conference_abv}" -466 -467 if defensive_conference_abv != None: -468 url += f"&defenseConference={defensive_conference_abv}" -469 -470 if ncaa_division != None: -471 url += f"&classification={ncaa_division.lower}" -472 -473 headers = { -474 'Authorization': f'{real_api_key}', -475 'accept': 'application/json' -476 } -477 -478 response = requests.get(url, headers=headers) -479 time.sleep(0.1) -480 -481 if response.status_code == 200: -482 pass -483 elif response.status_code == 401: -484 raise ConnectionRefusedError( -485 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -486 ) -487 else: -488 raise ConnectionError( -489 f'Could not connect.\nHTTP Status code {response.status_code}' -490 ) -491 -492 json_data = response.json() -493 -494 if return_as_dict == True: -495 return json_data -496 -497 for drive in tqdm(json_data): -498 offense = drive['offense'] -499 row_df = pd.DataFrame( -500 { -501 "offense": offense -502 }, index=[0] -503 ) -504 del offense -505 -506 row_df['offense_conference'] = drive['offense_conference'] -507 row_df['defense'] = drive['defense'] -508 row_df['defense_conference'] = drive['defense_conference'] -509 row_df['game_id'] = drive['game_id'] -510 row_df['drive_id'] = drive['id'] -511 row_df['drive_number'] = drive['drive_number'] -512 row_df['is_scoring_drive'] = drive['scoring'] -513 row_df['drive_start_period'] = drive['start_period'] -514 row_df['drive_start_yardline'] = drive['start_yardline'] -515 row_df['drive_start_yards_to_goal'] = drive['start_yards_to_goal'] -516 row_df['drive_start_time_minutes'] = drive['start_time']['minutes'] -517 row_df['drive_start_time_seconds'] = drive['start_time']['seconds'] -518 row_df['drive_end_period'] = drive['end_period'] -519 row_df['drive_end_yardline'] = drive['end_yardline'] -520 row_df['drive_end_yards_to_goal'] = drive['end_yards_to_goal'] -521 row_df['drive_end_time_minutes'] = drive['end_time']['minutes'] -522 row_df['drive_end_time_seconds'] = drive['end_time']['seconds'] -523 row_df['drive_elapsed_minutes'] = drive['elapsed']['minutes'] -524 row_df['drive_elapsed_seconds'] = drive['elapsed']['seconds'] -525 row_df['drive_plays'] = drive['plays'] -526 row_df['drive_yards'] = drive['yards'] -527 row_df['drive_result'] = drive['drive_result'] -528 row_df['is_home_offense'] = drive['is_home_offense'] -529 row_df['start_offense_score'] = drive['start_offense_score'] -530 row_df['start_defense_score'] = drive['start_defense_score'] -531 row_df['end_offense_score'] = drive['end_offense_score'] -532 row_df['end_defense_score'] = drive['end_defense_score'] -533 -534 cfb_drives_df = pd.concat([cfb_drives_df, row_df], ignore_index=True) -535 -536 del row_df -537 -538 if len(cfb_drives_df) == 0: -539 logging.error( -540 "The CFBD API accepted your inputs, " + -541 "but found no data within your specified input paramaters." + -542 " Please double check your input paramaters." -543 ) -544 -545 return cfb_drives_df +@@ -1162,7 +1161,7 @@18def get_cfbd_drives_info( + 19 season: int, + 20 api_key: str = None, + 21 api_key_dir: str = None, + 22 season_type: str = "regular", + 23 week: int = None, + 24 team: str = None, + 25 offensive_team: str = None, + 26 defensive_team: str = None, + 27 conference_abv: str = None, + 28 offensive_conference_abv: str = None, + 29 defensive_conference_abv: str = None, + 30 ncaa_division: str = "fbs", + 31 return_as_dict: bool = False): + 32 """ + 33 Retrives a list of CFB drives from the CFBD API. + 34 + 35 Parameters + 36 ---------- + 37 `season` (int, mandatory): + 38 Required argument. + 39 Specifies the season you want CFB drive information from. + 40 This must be specified, otherwise this package, and by extension + 41 the CFBD API, will not accept the request to get CFB drive information. + 42 + 43 `api_key` (str, optional): + 44 Semi-optional argument. + 45 If `api_key` is null, this function will attempt to load a CFBD API key + 46 from the python environment, or from a file on this computer. + 47 If `api_key` is not null, this function will automatically assume that the + 48 inputted `api_key` is a valid CFBD API key. + 49 + 50 `api_key_dir` (str, optional): + 51 Optional argument. + 52 If `api_key` is set to am empty string, this variable is ignored. + 53 If `api_key_dir` is null, and `api_key` is null, + 54 this function will try to find a CFBD API key file in this user's home directory. + 55 If `api_key_dir` is set to a string, and `api_key` is null, + 56 this function will assume that `api_key_dir` is a directory, + 57 and will try to find a CFBD API key file in that directory. + 58 + 59 `season_type` (str, semi-optional): + 60 Semi-optional argument. + 61 By defualt, this will be set to "regular", for the CFB regular season. + 62 If you want CFB drive data for non-regular season games, + 63 set `season_type` to "postseason". + 64 If `season_type` is set to anything but "regular" or "postseason", + 65 a `ValueError()` will be raised. + 66 + 67 `week` (int, optional): + 68 Optional argument. + 69 If `week` is set to an integer, this function will attempt + 70 to load CFB drive data from games in that season, and that week. + 71 + 72 `team` (str, optional): + 73 Optional argument. + 74 If you only want CFB drive data for a team, + 75 regardless if they are the home/away team, + 76 set `team` to the name of the team you want CFB drive data from. + 77 + 78 `offensive_team` (str, optional): + 79 Optional argument. + 80 If you only want CFB drive data from a team, while they are on offense, + 81 regardless if they are the home/away team, + 82 set `team` to the name of the team you want CFB drive data from. + 83 + 84 `defensive_team` (str, optional): + 85 Optional argument. + 86 If you only want CFB drive data from a team, while they are on defense, + 87 regardless if they are the home/away team, + 88 set `team` to the name of the team you want CFB drive data from. + 89 + 90 `conference_abv` (str, optional): + 91 Optional argument. + 92 If you only want CFB drive data from games + 93 involving teams from a specific confrence, + 94 set `conference_abv` to the abbreviation + 95 of the conference you want CFB drive data from. + 96 For a list of confrences, + 97 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` + 98 function. + 99 +100 `offensive_conference_abv` (str, optional): +101 Optional argument. +102 If you only want CFB drive data from games +103 where the offensive team is from a specific confrenece, +104 set `conference_abv` to the abbreviation +105 of the conference you want CFB drive data from. +106 For a list of confrences, +107 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +108 function. +109 +110 `defensive_conference_abv` (str, optional): +111 Optional argument. +112 If you only want CFB drive data from games +113 where the defensive team is from a specific confrenece, +114 set `conference_abv` to the abbreviation +115 of the conference you want CFB drive data from. +116 For a list of confrences, +117 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +118 function. +119 +120 `ncaa_division` (str, semi-optional): +121 Semi-optional argument. +122 By default, `ncaa_division` will be set to "fbs", +123 short for the Football Bowl Subdivision (FBS), +124 formerly known as D1-A (read as "division one single A"), +125 the highest level in the NCAA football pyramid, +126 where teams can scolarship up to 85 players +127 on their football team soley for athletic ability, +128 and often have the largest athletics budgets +129 within the NCAA. +130 +131 Other valid inputs are: +132 - "fcs": Football Championship Subdivision (FCS), +133 formerly known as D1-AA (read as "division one double A"). +134 An FCS school is still in the 1st division of the NCAA, +135 making them elligable for the March Madness tournament, +136 but may not have the resources to compete at the FBS level +137 at this time. FCS schools are limited to 63 athletic scolarships +138 for football. +139 - "ii": NCAA Division II. Schools in this and D3 are not +140 elligable for the March Madness tournament, +141 and are limited to 36 athletic scolarships for their football team. +142 - "iii": NCAA Division III. The largest single division within the +143 NCAA football pyramid. +144 D3 schools have the distinction of being part of +145 the only NCAA division that cannot give out scolarships soley +146 for athletic ability. +147 +148 `return_as_dict` (bool, semi-optional): +149 Semi-optional argument. +150 If you want this function to return the data as a dictionary (read: JSON object), +151 instead of a pandas `DataFrame` object, +152 set `return_as_dict` to `True`. +153 +154 Usage +155 ---------- +156 ``` +157 import time +158 +159 from cfbd_json_py.drives import get_cfbd_drives_info +160 +161 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +162 +163 if cfbd_key != "tigersAreAwsome": +164 print("Using the user's API key declared in this script for this example.") +165 +166 # Get CFB Drive data from the 2020 CFB season. +167 print("Get CFB Drive data from the 2020 CFB season.") +168 json_data = get_cfbd_drives_info( +169 api_key=cfbd_key, +170 season=2020 +171 ) +172 print(json_data) +173 time.sleep(5) +174 +175 # Get CFB Drive data from week 10 of the 2020 CFB season. +176 print("Get CFB Drive data from week 10 of the 2020 CFB season.") +177 json_data = get_cfbd_drives_info( +178 api_key=cfbd_key, +179 season=2020, +180 week=10 +181 ) +182 print(json_data) +183 time.sleep(5) +184 +185 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats +186 # Football Team. +187 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") +188 json_data = get_cfbd_drives_info( +189 api_key=cfbd_key, +190 season=2020, +191 team="Cincinnati" +192 ) +193 print(json_data) +194 time.sleep(5) +195 +196 # Get CFB Drive data from games involving the 2020 Ohio Bobcats +197 # Football Team, when Ohio was on offense. +198 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") +199 json_data = get_cfbd_drives_info( +200 api_key=cfbd_key, +201 season=2020, +202 offensive_team="Ohio" +203 ) +204 print(json_data) +205 time.sleep(5) +206 +207 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes +208 # Football Team, when Ohio was on offense. +209 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +210 json_data = get_cfbd_drives_info( +211 api_key=cfbd_key, +212 season=2020, +213 defensive_team="Ohio State" +214 ) +215 print(json_data) +216 time.sleep(5) +217 +218 # Get CFB Drive data from Big 12 games in the 2020 CFB season. +219 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +220 json_data = get_cfbd_drives_info( +221 api_key=cfbd_key, +222 season=2020, +223 conference_abv="B12" +224 ) +225 print(json_data) +226 time.sleep(5) +227 +228 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, +229 # where the Big 10 team was on offense. +230 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +231 json_data = get_cfbd_drives_info( +232 api_key=cfbd_key, +233 season=2020, +234 offensive_conference_abv="B1G" +235 ) +236 print(json_data) +237 time.sleep(5) +238 +239 # Get CFB Drive data from Mid-American Conference (MAC) games +240 # in the 2020 CFB season, where the MAC team was on offense. +241 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +242 json_data = get_cfbd_drives_info( +243 api_key=cfbd_key, +244 season=2020, +245 defensive_conference_abv="MAC" +246 ) +247 print(json_data) +248 time.sleep(5) +249 +250 # Get CFB Drive data from Football Championship Subdivision (FCS) games +251 # in week 3 ofthe 2020 CFB season, +252 # where the MAC team was on offense. +253 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +254 json_data = get_cfbd_drives_info( +255 api_key=cfbd_key, +256 season=2020, +257 week=3, +258 ncaa_division="fcs" +259 ) +260 print(json_data) +261 time.sleep(5) +262 +263 # You can also tell this function to just return the API call as +264 # a Dictionary (read: JSON) object. +265 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +266 json_data = get_cfbd_drives_info( +267 season=2020, +268 week=10, +269 api_key=cfbd_key, +270 return_as_dict=True +271 ) +272 print(json_data) +273 +274 else: +275 # Alternatively, if the CFBD API key exists in this python environment, +276 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +277 # you could just call these functions directly, without setting the API key +278 # in the script. +279 print("Using the user's API key suposedly loaded into this python environment for this example.") +280 +281 # Get CFB Drive data from the 2020 CFB season. +282 print("Get CFB Drive data from the 2020 CFB season.") +283 json_data = get_cfbd_drives_info( +284 season=2020 +285 ) +286 print(json_data) +287 time.sleep(5) +288 +289 # Get CFB Drive data from week 10 of the 2020 CFB season. +290 print("Get CFB Drive data from week 10 of the 2020 CFB season.") +291 json_data = get_cfbd_drives_info( +292 season=2020, +293 week=10 +294 ) +295 print(json_data) +296 time.sleep(5) +297 +298 # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats +299 # Football Team. +300 print("Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.") +301 json_data = get_cfbd_drives_info( +302 season=2020, +303 team="Cincinnati" +304 ) +305 print(json_data) +306 time.sleep(5) +307 +308 # Get CFB Drive data from games involving the 2020 Ohio Bobcats +309 # Football Team, when Ohio was on offense. +310 print("Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.") +311 json_data = get_cfbd_drives_info( +312 season=2020, +313 offensive_team="Ohio" +314 ) +315 print(json_data) +316 time.sleep(5) +317 +318 # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes +319 # Football Team, when Ohio was on offense. +320 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +321 json_data = get_cfbd_drives_info( +322 season=2020, +323 defensive_team="Ohio State" +324 ) +325 print(json_data) +326 time.sleep(5) +327 +328 # Get CFB Drive data from Big 12 games in the 2020 CFB season. +329 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +330 json_data = get_cfbd_drives_info( +331 season=2020, +332 conference_abv="B12" +333 ) +334 print(json_data) +335 time.sleep(5) +336 +337 # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season, +338 # where the Big 10 team was on offense. +339 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +340 json_data = get_cfbd_drives_info( +341 season=2020, +342 offensive_conference_abv="B1G" +343 ) +344 print(json_data) +345 time.sleep(5) +346 +347 # Get CFB Drive data from Mid-American Conference (MAC) games +348 # in the 2020 CFB season, where the MAC team was on offense. +349 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +350 json_data = get_cfbd_drives_info( +351 season=2020, +352 defensive_conference_abv="MAC" +353 ) +354 print(json_data) +355 time.sleep(5) +356 +357 # Get CFB Drive data from Football Championship Subdivision (FCS) games +358 # in week 3 ofthe 2020 CFB season, +359 # where the MAC team was on offense. +360 print("Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.") +361 json_data = get_cfbd_drives_info( +362 season=2020, +363 week=3, +364 ncaa_division="fcs" +365 ) +366 print(json_data) +367 time.sleep(5) +368 +369 # You can also tell this function to just return the API call as +370 # a Dictionary (read: JSON) object. +371 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +372 json_data = get_cfbd_drives_info( +373 season=2020, +374 week=10, +375 return_as_dict=True +376 ) +377 print(json_data) +378 +379 ``` +380 +381 Returns +382 ---------- +383 A pandas `DataFrame` object with CFB drive data, +384 or (if `return_as_dict` is set to `True`) +385 a dictionary object with CFB drive data. +386 +387 """ +388 now = datetime.now() +389 cfb_drives_df = pd.DataFrame() +390 row_df = pd.DataFrame() +391 url = "https://api.collegefootballdata.com/drives" +392 +393 # Input validation +394 ######################################################################################################################################################################################################## +395 +396 if api_key != None: +397 real_api_key = api_key +398 del api_key +399 else: +400 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +401 +402 if real_api_key == "tigersAreAwsome": +403 raise ValueError( +404 "You actually need to change `cfbd_key` to your CFBD API key.") +405 elif "Bearer " in real_api_key: +406 pass +407 elif "Bearer" in real_api_key: +408 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +409 else: +410 real_api_key = "Bearer " + real_api_key +411 +412 if season == None: +413 # This should never happen without user tampering, but if it does, +414 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +415 raise SystemError( +416 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +417 " and the function got to this point in the code." + +418 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +419 "https://github.com/armstjc/cfbd-json-py/issues" +420 ) +421 elif season > now.year: +422 raise ValueError(f"`season` cannot be greater than {season}.") +423 elif season < 1869: +424 raise ValueError(f"`season` cannot be less than 1869.") +425 +426 if season_type != "regular" and season_type != "postseason": +427 raise ValueError( +428 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +429 +430 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ +431 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": +432 pass +433 else: +434 raise ValueError( +435 "An invalid NCAA Division was inputted when calling this function." + +436 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + +437 f"\n\nYou entered:\n{ncaa_division}" +438 ) +439 +440 # URL builder +441 ######################################################################################################################################################################################################## +442 +443 # Required by API +444 url += f"?seasonType={season_type}" +445 +446 url += f"&year={season}" +447 +448 if week != None: +449 url += f"&week={week}" +450 +451 if team != None: +452 url += f"&team={team}" +453 +454 if offensive_team != None: +455 url += f"&offense={offensive_team}" +456 +457 if defensive_team != None: +458 url += f"&defense={defensive_team}" +459 +460 if conference_abv != None: +461 url += f"&conference={conference_abv}" +462 +463 if offensive_conference_abv != None: +464 url += f"&offenseConference={offensive_conference_abv}" +465 +466 if defensive_conference_abv != None: +467 url += f"&defenseConference={defensive_conference_abv}" +468 +469 if ncaa_division != None: +470 url += f"&classification={ncaa_division.lower}" +471 +472 headers = { +473 'Authorization': f'{real_api_key}', +474 'accept': 'application/json' +475 } +476 +477 response = requests.get(url, headers=headers) +478 +479 +480 if response.status_code == 200: +481 pass +482 elif response.status_code == 401: +483 raise ConnectionRefusedError( +484 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +485 ) +486 else: +487 raise ConnectionError( +488 f'Could not connect.\nHTTP Status code {response.status_code}' +489 ) +490 +491 json_data = response.json() +492 +493 if return_as_dict == True: +494 return json_data +495 +496 for drive in tqdm(json_data): +497 offense = drive['offense'] +498 row_df = pd.DataFrame( +499 { +500 "offense": offense +501 }, index=[0] +502 ) +503 del offense +504 +505 row_df['offense_conference'] = drive['offense_conference'] +506 row_df['defense'] = drive['defense'] +507 row_df['defense_conference'] = drive['defense_conference'] +508 row_df['game_id'] = drive['game_id'] +509 row_df['drive_id'] = drive['id'] +510 row_df['drive_number'] = drive['drive_number'] +511 row_df['is_scoring_drive'] = drive['scoring'] +512 row_df['drive_start_period'] = drive['start_period'] +513 row_df['drive_start_yardline'] = drive['start_yardline'] +514 row_df['drive_start_yards_to_goal'] = drive['start_yards_to_goal'] +515 row_df['drive_start_time_minutes'] = drive['start_time']['minutes'] +516 row_df['drive_start_time_seconds'] = drive['start_time']['seconds'] +517 row_df['drive_end_period'] = drive['end_period'] +518 row_df['drive_end_yardline'] = drive['end_yardline'] +519 row_df['drive_end_yards_to_goal'] = drive['end_yards_to_goal'] +520 row_df['drive_end_time_minutes'] = drive['end_time']['minutes'] +521 row_df['drive_end_time_seconds'] = drive['end_time']['seconds'] +522 row_df['drive_elapsed_minutes'] = drive['elapsed']['minutes'] +523 row_df['drive_elapsed_seconds'] = drive['elapsed']['seconds'] +524 row_df['drive_plays'] = drive['plays'] +525 row_df['drive_yards'] = drive['yards'] +526 row_df['drive_result'] = drive['drive_result'] +527 row_df['is_home_offense'] = drive['is_home_offense'] +528 row_df['start_offense_score'] = drive['start_offense_score'] +529 row_df['start_defense_score'] = drive['start_defense_score'] +530 row_df['end_offense_score'] = drive['end_offense_score'] +531 row_df['end_defense_score'] = drive['end_defense_score'] +532 +533 cfb_drives_df = pd.concat([cfb_drives_df, row_df], ignore_index=True) +534 +535 del row_df +536 +537 if len(cfb_drives_df) == 0: +538 logging.error( +539 "The CFBD API accepted your inputs, " + +540 "but found no data within your specified input paramaters." + +541 " Please double check your input paramaters." +542 ) +543 +544 return cfb_drives_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, diff --git a/docs/cfbd_json_py/games.html b/docs/cfbd_json_py/games.html index 2a53f3e..87f91b5 100644 --- a/docs/cfbd_json_py/games.html +++ b/docs/cfbd_json_py/games.html @@ -76,7 +76,7 @@
-1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/06/2023 07:53 PM EDT + 2# Last Updated Date: 10/23/2023 04:09 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: games.py 5# Purpose: Houses functions pertaining to CFB game data within the CFBD API. @@ -84,2863 +84,2863 @@7 8from datetime import datetime 9import logging - 10import time - 11 - 12import pandas as pd - 13import requests - 14from tqdm import tqdm - 15 - 16from cfbd_json_py.utls import get_cfbd_api_token + 10 + 11import pandas as pd + 12import requests + 13from tqdm import tqdm + 14 + 15from cfbd_json_py.utls import get_cfbd_api_token + 16 17 - 18 - 19def get_cfbd_games( - 20 season: int, - 21 api_key: str = None, - 22 api_key_dir: str = None, - 23 season_type: str = "regular", - 24 week: int = None, - 25 team: str = None, - 26 home_team: str = None, - 27 away_team: str = None, - 28 conference_abv: str = None, - 29 ncaa_division: str = "fbs", - 30 game_id: int = None, - 31 return_as_dict: bool = False): - 32 """ - 33 Retrives game schedule data from the CFBD API. - 34 - 35 Parameters - 36 ---------- - 37 `season` (int, mandatory): - 38 Required argument. - 39 Specifies the season you want CFB game information from. - 40 This must be specified, otherwise this package, and by extension - 41 the CFBD API, will not accept the request to get CFB game information. - 42 - 43 `api_key` (str, optional): - 44 Semi-optional argument. - 45 If `api_key` is null, this function will attempt to load a CFBD API key - 46 from the python environment, or from a file on this computer. - 47 If `api_key` is not null, this function will automatically assume that the - 48 inputted `api_key` is a valid CFBD API key. - 49 - 50 `api_key_dir` (str, optional): - 51 Optional argument. - 52 If `api_key` is set to a string non-empty string, this variable is ignored. - 53 If `api_key_dir` is null, and `api_key` is null, - 54 this function will try to find a CFBD API key file in this user's home directory. - 55 If `api_key_dir` is set to a string, and `api_key` is null, - 56 this function will assume that `api_key_dir` is a directory, - 57 and will try to find a CFBD API key file in that directory. - 58 - 59 `season_type` (str, semi-optional): - 60 Semi-optional argument. - 61 By defualt, this will be set to "regular", for the CFB regular season. - 62 If you want CFB game information for non-regular season games, - 63 set `season_type` to "postseason". - 64 If `season_type` is set to anything but "regular" or "postseason", - 65 a `ValueError()` will be raised. - 66 - 67 `week` (int, optional): - 68 Optional argument. - 69 If `week` is set to an integer, this function will attempt - 70 to load CFB game data from games in that season, and in that week. - 71 - 72 `team` (str, optional): - 73 Optional argument. - 74 If you only want CFB game information for a team, - 75 regardless if they are the home/away team, - 76 set `team` to the name of the team you want CFB game information from. - 77 - 78 `home_team` (str, optional): - 79 Optional argument. - 80 If you only want game information for a team, - 81 where that team was the home team in this season, - 82 set `home_team` to the name of the team you want game information for. - 83 - 84 `away_team` (str, optional): - 85 Optional argument. - 86 If you only want game information for a team, - 87 where that team was the away team in this season, - 88 set `away_team` to the name of the team you want game information for. - 89 - 90 `conference_abv` (str, optional): - 91 Optional argument. - 92 If you only want game information from games - 93 involving teams a specific confrence, - 94 set `conference_abv` to the abbreviation - 95 of the conference you want game information from. - 96 - 97 `ncaa_division` (str, semi-optional): - 98 Semi-optional argument. - 99 By default, `ncaa_division` will be set to "fbs", - 100 short for the Football Bowl Subdivision (FBS), - 101 formerly known as D1-A (read as "division one single A"), - 102 the highest level in the NCAA football pyramid, - 103 where teams can scolarship up to 85 players - 104 on their football team soley for athletic ability, - 105 and often have the largest athletics budgets - 106 within the NCAA. - 107 - 108 Other valid inputs are: - 109 - "fcs": Football Championship Subdivision (FCS), - 110 formerly known as D1-AA (read as "division one double A"). - 111 An FCS school is still in the 1st division of the NCAA, - 112 making them elligable for the March Madness tournament, - 113 but may not have the resources to compete at the FBS level - 114 at this time. FCS schools are limited to 63 athletic scolarships - 115 for football. - 116 - "ii": NCAA Division II. Schools in this and D3 are not - 117 elligable for the March Madness tournament, - 118 and are limited to 36 athletic scolarships for their football team. - 119 - "iii": NCAA Division III. The largest single division within the - 120 NCAA football pyramid. - 121 D3 schools have the distinction of being part of - 122 the only NCAA division that cannot give out scolarships soley - 123 for athletic ability. - 124 - 125 `game_id` (int, optional): - 126 Optional argument. - 127 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get - 128 game information just for that game ID. - 129 - 130 `return_as_dict` (bool, semi-optional): - 131 Semi-optional argument. - 132 If you want this function to return the data as a dictionary (read: JSON object), - 133 instead of a pandas `DataFrame` object, - 134 set `return_as_dict` to `True`. - 135 - 136 Usage - 137 ---------- - 138 ``` - 139 import time - 140 - 141 from cfbd_json_py.games import get_cfbd_games + 18def get_cfbd_games( + 19 season: int, + 20 api_key: str = None, + 21 api_key_dir: str = None, + 22 season_type: str = "regular", + 23 week: int = None, + 24 team: str = None, + 25 home_team: str = None, + 26 away_team: str = None, + 27 conference_abv: str = None, + 28 ncaa_division: str = "fbs", + 29 game_id: int = None, + 30 return_as_dict: bool = False): + 31 """ + 32 Retrives game schedule data from the CFBD API. + 33 + 34 Parameters + 35 ---------- + 36 `season` (int, mandatory): + 37 Required argument. + 38 Specifies the season you want CFB game information from. + 39 This must be specified, otherwise this package, and by extension + 40 the CFBD API, will not accept the request to get CFB game information. + 41 + 42 `api_key` (str, optional): + 43 Semi-optional argument. + 44 If `api_key` is null, this function will attempt to load a CFBD API key + 45 from the python environment, or from a file on this computer. + 46 If `api_key` is not null, this function will automatically assume that the + 47 inputted `api_key` is a valid CFBD API key. + 48 + 49 `api_key_dir` (str, optional): + 50 Optional argument. + 51 If `api_key` is set to am empty string, this variable is ignored. + 52 If `api_key_dir` is null, and `api_key` is null, + 53 this function will try to find a CFBD API key file in this user's home directory. + 54 If `api_key_dir` is set to a string, and `api_key` is null, + 55 this function will assume that `api_key_dir` is a directory, + 56 and will try to find a CFBD API key file in that directory. + 57 + 58 `season_type` (str, semi-optional): + 59 Semi-optional argument. + 60 By defualt, this will be set to "regular", for the CFB regular season. + 61 If you want CFB game information for non-regular season games, + 62 set `season_type` to "postseason". + 63 If `season_type` is set to anything but "regular" or "postseason", + 64 a `ValueError()` will be raised. + 65 + 66 `week` (int, optional): + 67 Optional argument. + 68 If `week` is set to an integer, this function will attempt + 69 to load CFB game data from games in that season, and in that week. + 70 + 71 `team` (str, optional): + 72 Optional argument. + 73 If you only want CFB game information for a team, + 74 regardless if they are the home/away team, + 75 set `team` to the name of the team you want CFB game information from. + 76 + 77 `home_team` (str, optional): + 78 Optional argument. + 79 If you only want game information for a team, + 80 where that team was the home team in this season, + 81 set `home_team` to the name of the team you want game information for. + 82 + 83 `away_team` (str, optional): + 84 Optional argument. + 85 If you only want game information for a team, + 86 where that team was the away team in this season, + 87 set `away_team` to the name of the team you want game information for. + 88 + 89 `conference_abv` (str, optional): + 90 Optional argument. + 91 If you only want game information from games + 92 involving teams a specific confrence, + 93 set `conference_abv` to the abbreviation + 94 of the conference you want game information from. + 95 + 96 `ncaa_division` (str, semi-optional): + 97 Semi-optional argument. + 98 By default, `ncaa_division` will be set to "fbs", + 99 short for the Football Bowl Subdivision (FBS), + 100 formerly known as D1-A (read as "division one single A"), + 101 the highest level in the NCAA football pyramid, + 102 where teams can scolarship up to 85 players + 103 on their football team soley for athletic ability, + 104 and often have the largest athletics budgets + 105 within the NCAA. + 106 + 107 Other valid inputs are: + 108 - "fcs": Football Championship Subdivision (FCS), + 109 formerly known as D1-AA (read as "division one double A"). + 110 An FCS school is still in the 1st division of the NCAA, + 111 making them elligable for the March Madness tournament, + 112 but may not have the resources to compete at the FBS level + 113 at this time. FCS schools are limited to 63 athletic scolarships + 114 for football. + 115 - "ii": NCAA Division II. Schools in this and D3 are not + 116 elligable for the March Madness tournament, + 117 and are limited to 36 athletic scolarships for their football team. + 118 - "iii": NCAA Division III. The largest single division within the + 119 NCAA football pyramid. + 120 D3 schools have the distinction of being part of + 121 the only NCAA division that cannot give out scolarships soley + 122 for athletic ability. + 123 + 124 `game_id` (int, optional): + 125 Optional argument. + 126 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get + 127 game information just for that game ID. + 128 + 129 `return_as_dict` (bool, semi-optional): + 130 Semi-optional argument. + 131 If you want this function to return the data as a dictionary (read: JSON object), + 132 instead of a pandas `DataFrame` object, + 133 set `return_as_dict` to `True`. + 134 + 135 Usage + 136 ---------- + 137 ``` + 138 import time + 139 + 140 from cfbd_json_py.games import get_cfbd_games + 141 142 - 143 - 144 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 145 - 146 if cfbd_key != "tigersAreAwsome": - 147 print("Using the user's API key declared in this script for this example.") - 148 - 149 # Get CFB games from the 2020 CFB season. - 150 print("Get CFB games from the 2020 CFB season.") - 151 json_data = get_cfbd_games( - 152 api_key=cfbd_key, - 153 season=2020 - 154 ) - 155 print(json_data) - 156 time.sleep(5) - 157 - 158 # Get CFB games from week 10 of the 2020 CFB season. - 159 print("Get CFB games from week 10 of the 2020 CFB season.") - 160 json_data = get_cfbd_games( - 161 api_key=cfbd_key, - 162 season=2020, - 163 week=10 - 164 ) - 165 print(json_data) - 166 time.sleep(5) - 167 - 168 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. - 169 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") - 170 json_data = get_cfbd_games( - 171 api_key=cfbd_key, - 172 season=2019, - 173 team="LSU" - 174 ) - 175 print(json_data) - 176 time.sleep(5) - 177 - 178 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. - 179 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") - 180 json_data = get_cfbd_games( - 181 api_key=cfbd_key, - 182 season=2021, - 183 home_team="Cincinnati" - 184 ) - 185 print(json_data) - 186 time.sleep(5) - 187 - 188 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. - 189 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") - 190 json_data = get_cfbd_games( - 191 api_key=cfbd_key, - 192 season=2019, - 193 away_team="Ohio" - 194 ) - 195 print(json_data) - 196 time.sleep(5) - 197 - 198 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. - 199 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") - 200 json_data = get_cfbd_games( - 201 api_key=cfbd_key, - 202 season=2018, - 203 away_team="Ohio" - 204 ) - 205 print(json_data) - 206 time.sleep(5) - 207 - 208 # Get 2022 college football games where one or more teams competing - 209 # was a Football Championship Subdivision team. - 210 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") - 211 json_data = get_cfbd_games( - 212 api_key=cfbd_key, - 213 season=2018, - 214 away_team="Ohio" - 215 ) - 216 print(json_data) - 217 time.sleep(5) - 218 - 219 # Get game information for the - 220 # 2021 American Athletic Confrence (AAC) Championship Game. - 221 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") - 222 json_data = get_cfbd_games( - 223 api_key=cfbd_key, - 224 season=2018, - 225 game_id=401331162 - 226 ) - 227 print(json_data) - 228 time.sleep(5) - 229 - 230 # You can also tell this function to just return the API call as - 231 # a Dictionary (read: JSON) object. - 232 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 233 json_data = get_cfbd_games( - 234 season=2020, - 235 week=10, - 236 api_key=cfbd_key, - 237 return_as_dict=True - 238 ) - 239 print(json_data) - 240 - 241 else: - 242 # Alternatively, if the CFBD API key exists in this python environment, - 243 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 244 # you could just call these functions directly, without setting the API key - 245 # in the script. - 246 print("Using the user's API key suposedly loaded into this python environment for this example.") - 247 - 248 # Get CFB games from the 2020 CFB season. - 249 print("Get CFB games from the 2020 CFB season.") - 250 json_data = get_cfbd_games( - 251 season=2020 - 252 ) - 253 print(json_data) - 254 time.sleep(5) - 255 - 256 # Get CFB games from week 10 of the 2020 CFB season. - 257 print("Get CFB games from week 10 of the 2020 CFB season.") - 258 json_data = get_cfbd_games( - 259 season=2020, - 260 week=10 - 261 ) - 262 print(json_data) - 263 time.sleep(5) - 264 - 265 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. - 266 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") - 267 json_data = get_cfbd_games( - 268 season=2019, - 269 team="LSU" - 270 ) - 271 print(json_data) - 272 time.sleep(5) - 273 - 274 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. - 275 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") - 276 json_data = get_cfbd_games( - 277 season=2021, - 278 home_team="Cincinnati" - 279 ) - 280 print(json_data) - 281 time.sleep(5) - 282 - 283 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. - 284 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") - 285 json_data = get_cfbd_games( - 286 season=2019, - 287 away_team="Ohio" - 288 ) - 289 print(json_data) - 290 time.sleep(5) - 291 - 292 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. - 293 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") - 294 json_data = get_cfbd_games( - 295 season=2018, - 296 away_team="Ohio" - 297 ) - 298 print(json_data) - 299 time.sleep(5) - 300 - 301 # Get 2022 college football games where one or more teams competing - 302 # was a Football Championship Subdivision team. - 303 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") - 304 json_data = get_cfbd_games( - 305 season=2018, - 306 away_team="Ohio" - 307 ) - 308 print(json_data) - 309 time.sleep(5) - 310 - 311 # Get game information for the - 312 # 2021 American Athletic Confrence (AAC) Championship Game. - 313 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") - 314 json_data = get_cfbd_games( - 315 season=2018, - 316 game_id=401331162 - 317 ) - 318 print(json_data) - 319 time.sleep(5) - 320 - 321 # You can also tell this function to just return the API call as - 322 # a Dictionary (read: JSON) object. - 323 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 324 json_data = get_cfbd_games( - 325 season=2020, - 326 week=10, - 327 return_as_dict=True - 328 ) - 329 print(json_data) - 330 - 331 ``` - 332 Returns - 333 ---------- - 334 A pandas `DataFrame` object with college football game information, - 335 or (if `return_as_dict` is set to `True`) - 336 a dictionary object with college football game information. - 337 """ - 338 - 339 now = datetime.now() - 340 cfb_games_df = pd.DataFrame() - 341 row_df = pd.DataFrame() - 342 url = "https://api.collegefootballdata.com/games" - 343 - 344 ######################################################################################################################################################################################################## - 345 - 346 if api_key != None: - 347 real_api_key = api_key - 348 del api_key - 349 else: - 350 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) - 351 - 352 if real_api_key == "tigersAreAwsome": - 353 raise ValueError( - 354 "You actually need to change `cfbd_key` to your CFBD API key.") - 355 elif "Bearer " in real_api_key: - 356 pass - 357 elif "Bearer" in real_api_key: - 358 real_api_key = real_api_key.replace('Bearer', 'Bearer ') - 359 else: - 360 real_api_key = "Bearer " + real_api_key - 361 - 362 if season == None: - 363 # This should never happen without user tampering, but if it does, - 364 # we need to raise an error, because the CFBD API will refuse this call without a valid season. - 365 raise SystemError( - 366 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + - 367 " and the function got to this point in the code." + - 368 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + - 369 "https://github.com/armstjc/cfbd-json-py/issues" - 370 ) - 371 elif season > now.year: - 372 raise ValueError(f"`season` cannot be greater than {season}.") - 373 elif season < 1869: - 374 raise ValueError(f"`season` cannot be less than 1869.") - 375 - 376 if season_type != "regular" and season_type != "postseason": - 377 raise ValueError( - 378 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") - 379 - 380 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ - 381 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": - 382 pass - 383 else: - 384 raise ValueError( - 385 "An invalid NCAA Division was inputted when calling this function." + - 386 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + - 387 f"\n\nYou entered: \n{ncaa_division}" - 388 ) - 389 - 390 # URL builder - 391 ######################################################################################################################################################################################################## - 392 - 393 # Required by API - 394 url += f"?seasonType={season_type}" - 395 - 396 if game_id != None: - 397 url += f"&year={season}" - 398 url += f"&id={game_id}" - 399 - 400 if team != None or home_team != None \ - 401 or away_team != None or conference_abv != None \ - 402 or week != None: - 403 logging.warning( - 404 "When calling `cfbd_json_py.games.get_cfbd_games()`, " + - 405 "and setting `game_id` to a non-null value, " + - 406 "only `season` and `game_id` are considered " + - 407 "when calling the CFBD API." - 408 ) - 409 - 410 else: - 411 url += f"&year={season}" - 412 - 413 # Optional for the API - 414 if week != None: - 415 url += f"&week={week}" - 416 - 417 if team != None: - 418 url += f"&team={team}" - 419 - 420 if home_team != None: - 421 url += f"&home={home_team}" - 422 - 423 if away_team != None: - 424 url += f"&away={away_team}" - 425 - 426 if conference_abv != None: - 427 url += f"&conference={conference_abv}" - 428 - 429 if ncaa_division != None: - 430 url += f"&division={ncaa_division}" - 431 - 432 headers = { - 433 'Authorization': f'{real_api_key}', - 434 'accept': 'application/json' - 435 } - 436 - 437 response = requests.get(url, headers=headers) - 438 time.sleep(0.1) - 439 - 440 if response.status_code == 200: - 441 pass - 442 elif response.status_code == 401: - 443 raise ConnectionRefusedError( - 444 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' - 445 ) - 446 else: - 447 raise ConnectionError( - 448 f'Could not connect.\nHTTP Status code {response.status_code}' - 449 ) - 450 - 451 json_data = response.json() - 452 - 453 if return_as_dict == True: - 454 return json_data - 455 - 456 for game in tqdm(json_data): - 457 g_id = game['id'] - 458 row_df = pd.DataFrame( - 459 { - 460 "game_id": g_id - 461 }, index=[0] - 462 ) - 463 del g_id - 464 - 465 row_df['season'] = game['season'] - 466 row_df['week'] = game['week'] - 467 row_df['season_type'] = game['season_type'] - 468 row_df['start_date'] = game['start_date'] - 469 row_df['start_time_tbd'] = game['start_time_tbd'] - 470 row_df['is_game_completed'] = game['completed'] - 471 row_df['is_neutral_site'] = game['neutral_site'] - 472 row_df['is_conference_game'] = game['conference_game'] - 473 row_df['game_attendance'] = game['attendance'] - 474 row_df['venue_id'] = game['venue_id'] - 475 row_df['venue_name'] = game['venue'] - 476 row_df['home_id'] = game['home_id'] - 477 row_df['home_team'] = game['home_team'] - 478 row_df['home_conference'] = game['home_conference'] - 479 row_df['home_division'] = game['home_division'] - 480 row_df['home_points'] = game['home_points'] - 481 row_df['home_line_scores'] = str(game['home_line_scores']) - 482 row_df['home_post_win_prob'] = game['home_post_win_prob'] - 483 row_df['home_pregame_elo'] = game['home_pregame_elo'] - 484 row_df['home_postgame_elo'] = game['home_postgame_elo'] - 485 row_df['away_id'] = game['away_id'] - 486 row_df['away_team'] = game['away_team'] - 487 row_df['away_conference'] = game['away_conference'] - 488 row_df['away_division'] = game['away_division'] - 489 row_df['away_points'] = game['away_points'] - 490 row_df['away_line_scores'] = str(game['away_line_scores']) - 491 row_df['away_post_win_prob'] = game['away_post_win_prob'] - 492 row_df['away_pregame_elo'] = game['away_pregame_elo'] - 493 row_df['away_postgame_elo'] = game['away_postgame_elo'] - 494 row_df['excitement_index'] = game['excitement_index'] - 495 row_df['highlights'] = game['highlights'] - 496 row_df['notes'] = game['notes'] - 497 - 498 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) - 499 del row_df - 500 - 501 if len(cfb_games_df) == 0: - 502 logging.error( - 503 "The CFBD API accepted your inputs, " + - 504 "but found no data within your specified input paramaters." + - 505 " Please double check your input paramaters." - 506 ) - 507 - 508 return cfb_games_df + 143 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 144 + 145 if cfbd_key != "tigersAreAwsome": + 146 print("Using the user's API key declared in this script for this example.") + 147 + 148 # Get CFB games from the 2020 CFB season. + 149 print("Get CFB games from the 2020 CFB season.") + 150 json_data = get_cfbd_games( + 151 api_key=cfbd_key, + 152 season=2020 + 153 ) + 154 print(json_data) + 155 time.sleep(5) + 156 + 157 # Get CFB games from week 10 of the 2020 CFB season. + 158 print("Get CFB games from week 10 of the 2020 CFB season.") + 159 json_data = get_cfbd_games( + 160 api_key=cfbd_key, + 161 season=2020, + 162 week=10 + 163 ) + 164 print(json_data) + 165 time.sleep(5) + 166 + 167 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. + 168 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") + 169 json_data = get_cfbd_games( + 170 api_key=cfbd_key, + 171 season=2019, + 172 team="LSU" + 173 ) + 174 print(json_data) + 175 time.sleep(5) + 176 + 177 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. + 178 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") + 179 json_data = get_cfbd_games( + 180 api_key=cfbd_key, + 181 season=2021, + 182 home_team="Cincinnati" + 183 ) + 184 print(json_data) + 185 time.sleep(5) + 186 + 187 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. + 188 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") + 189 json_data = get_cfbd_games( + 190 api_key=cfbd_key, + 191 season=2019, + 192 away_team="Ohio" + 193 ) + 194 print(json_data) + 195 time.sleep(5) + 196 + 197 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. + 198 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") + 199 json_data = get_cfbd_games( + 200 api_key=cfbd_key, + 201 season=2018, + 202 away_team="Ohio" + 203 ) + 204 print(json_data) + 205 time.sleep(5) + 206 + 207 # Get 2022 college football games where one or more teams competing + 208 # was a Football Championship Subdivision team. + 209 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") + 210 json_data = get_cfbd_games( + 211 api_key=cfbd_key, + 212 season=2018, + 213 away_team="Ohio" + 214 ) + 215 print(json_data) + 216 time.sleep(5) + 217 + 218 # Get game information for the + 219 # 2021 American Athletic Confrence (AAC) Championship Game. + 220 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") + 221 json_data = get_cfbd_games( + 222 api_key=cfbd_key, + 223 season=2018, + 224 game_id=401331162 + 225 ) + 226 print(json_data) + 227 time.sleep(5) + 228 + 229 # You can also tell this function to just return the API call as + 230 # a Dictionary (read: JSON) object. + 231 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 232 json_data = get_cfbd_games( + 233 season=2020, + 234 week=10, + 235 api_key=cfbd_key, + 236 return_as_dict=True + 237 ) + 238 print(json_data) + 239 + 240 else: + 241 # Alternatively, if the CFBD API key exists in this python environment, + 242 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 243 # you could just call these functions directly, without setting the API key + 244 # in the script. + 245 print("Using the user's API key suposedly loaded into this python environment for this example.") + 246 + 247 # Get CFB games from the 2020 CFB season. + 248 print("Get CFB games from the 2020 CFB season.") + 249 json_data = get_cfbd_games( + 250 season=2020 + 251 ) + 252 print(json_data) + 253 time.sleep(5) + 254 + 255 # Get CFB games from week 10 of the 2020 CFB season. + 256 print("Get CFB games from week 10 of the 2020 CFB season.") + 257 json_data = get_cfbd_games( + 258 season=2020, + 259 week=10 + 260 ) + 261 print(json_data) + 262 time.sleep(5) + 263 + 264 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. + 265 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") + 266 json_data = get_cfbd_games( + 267 season=2019, + 268 team="LSU" + 269 ) + 270 print(json_data) + 271 time.sleep(5) + 272 + 273 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. + 274 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") + 275 json_data = get_cfbd_games( + 276 season=2021, + 277 home_team="Cincinnati" + 278 ) + 279 print(json_data) + 280 time.sleep(5) + 281 + 282 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. + 283 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") + 284 json_data = get_cfbd_games( + 285 season=2019, + 286 away_team="Ohio" + 287 ) + 288 print(json_data) + 289 time.sleep(5) + 290 + 291 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. + 292 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") + 293 json_data = get_cfbd_games( + 294 season=2018, + 295 away_team="Ohio" + 296 ) + 297 print(json_data) + 298 time.sleep(5) + 299 + 300 # Get 2022 college football games where one or more teams competing + 301 # was a Football Championship Subdivision team. + 302 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") + 303 json_data = get_cfbd_games( + 304 season=2018, + 305 away_team="Ohio" + 306 ) + 307 print(json_data) + 308 time.sleep(5) + 309 + 310 # Get game information for the + 311 # 2021 American Athletic Confrence (AAC) Championship Game. + 312 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") + 313 json_data = get_cfbd_games( + 314 season=2018, + 315 game_id=401331162 + 316 ) + 317 print(json_data) + 318 time.sleep(5) + 319 + 320 # You can also tell this function to just return the API call as + 321 # a Dictionary (read: JSON) object. + 322 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 323 json_data = get_cfbd_games( + 324 season=2020, + 325 week=10, + 326 return_as_dict=True + 327 ) + 328 print(json_data) + 329 + 330 ``` + 331 Returns + 332 ---------- + 333 A pandas `DataFrame` object with college football game information, + 334 or (if `return_as_dict` is set to `True`) + 335 a dictionary object with college football game information. + 336 """ + 337 + 338 now = datetime.now() + 339 cfb_games_df = pd.DataFrame() + 340 row_df = pd.DataFrame() + 341 url = "https://api.collegefootballdata.com/games" + 342 + 343 ######################################################################################################################################################################################################## + 344 + 345 if api_key != None: + 346 real_api_key = api_key + 347 del api_key + 348 else: + 349 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + 350 + 351 if real_api_key == "tigersAreAwsome": + 352 raise ValueError( + 353 "You actually need to change `cfbd_key` to your CFBD API key.") + 354 elif "Bearer " in real_api_key: + 355 pass + 356 elif "Bearer" in real_api_key: + 357 real_api_key = real_api_key.replace('Bearer', 'Bearer ') + 358 else: + 359 real_api_key = "Bearer " + real_api_key + 360 + 361 if season == None: + 362 # This should never happen without user tampering, but if it does, + 363 # we need to raise an error, because the CFBD API will refuse this call without a valid season. + 364 raise SystemError( + 365 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + + 366 " and the function got to this point in the code." + + 367 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + + 368 "https://github.com/armstjc/cfbd-json-py/issues" + 369 ) + 370 elif season > now.year: + 371 raise ValueError(f"`season` cannot be greater than {season}.") + 372 elif season < 1869: + 373 raise ValueError(f"`season` cannot be less than 1869.") + 374 + 375 if season_type != "regular" and season_type != "postseason": + 376 raise ValueError( + 377 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + 378 + 379 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ + 380 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": + 381 pass + 382 else: + 383 raise ValueError( + 384 "An invalid NCAA Division was inputted when calling this function." + + 385 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + + 386 f"\n\nYou entered: \n{ncaa_division}" + 387 ) + 388 + 389 # URL builder + 390 ######################################################################################################################################################################################################## + 391 + 392 # Required by API + 393 url += f"?seasonType={season_type}" + 394 + 395 if game_id != None: + 396 url += f"&year={season}" + 397 url += f"&id={game_id}" + 398 + 399 if team != None or home_team != None \ + 400 or away_team != None or conference_abv != None \ + 401 or week != None: + 402 logging.warning( + 403 "When calling `cfbd_json_py.games.get_cfbd_games()`, " + + 404 "and setting `game_id` to a non-null value, " + + 405 "only `season` and `game_id` are considered " + + 406 "when calling the CFBD API." + 407 ) + 408 + 409 else: + 410 url += f"&year={season}" + 411 + 412 # Optional for the API + 413 if week != None: + 414 url += f"&week={week}" + 415 + 416 if team != None: + 417 url += f"&team={team}" + 418 + 419 if home_team != None: + 420 url += f"&home={home_team}" + 421 + 422 if away_team != None: + 423 url += f"&away={away_team}" + 424 + 425 if conference_abv != None: + 426 url += f"&conference={conference_abv}" + 427 + 428 if ncaa_division != None: + 429 url += f"&division={ncaa_division}" + 430 + 431 headers = { + 432 'Authorization': f'{real_api_key}', + 433 'accept': 'application/json' + 434 } + 435 + 436 response = requests.get(url, headers=headers) + 437 + 438 + 439 if response.status_code == 200: + 440 pass + 441 elif response.status_code == 401: + 442 raise ConnectionRefusedError( + 443 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + 444 ) + 445 else: + 446 raise ConnectionError( + 447 f'Could not connect.\nHTTP Status code {response.status_code}' + 448 ) + 449 + 450 json_data = response.json() + 451 + 452 if return_as_dict == True: + 453 return json_data + 454 + 455 for game in tqdm(json_data): + 456 g_id = game['id'] + 457 row_df = pd.DataFrame( + 458 { + 459 "game_id": g_id + 460 }, index=[0] + 461 ) + 462 del g_id + 463 + 464 row_df['season'] = game['season'] + 465 row_df['week'] = game['week'] + 466 row_df['season_type'] = game['season_type'] + 467 row_df['start_date'] = game['start_date'] + 468 row_df['start_time_tbd'] = game['start_time_tbd'] + 469 row_df['is_game_completed'] = game['completed'] + 470 row_df['is_neutral_site'] = game['neutral_site'] + 471 row_df['is_conference_game'] = game['conference_game'] + 472 row_df['game_attendance'] = game['attendance'] + 473 row_df['venue_id'] = game['venue_id'] + 474 row_df['venue_name'] = game['venue'] + 475 row_df['home_id'] = game['home_id'] + 476 row_df['home_team'] = game['home_team'] + 477 row_df['home_conference'] = game['home_conference'] + 478 row_df['home_division'] = game['home_division'] + 479 row_df['home_points'] = game['home_points'] + 480 row_df['home_line_scores'] = str(game['home_line_scores']) + 481 row_df['home_post_win_prob'] = game['home_post_win_prob'] + 482 row_df['home_pregame_elo'] = game['home_pregame_elo'] + 483 row_df['home_postgame_elo'] = game['home_postgame_elo'] + 484 row_df['away_id'] = game['away_id'] + 485 row_df['away_team'] = game['away_team'] + 486 row_df['away_conference'] = game['away_conference'] + 487 row_df['away_division'] = game['away_division'] + 488 row_df['away_points'] = game['away_points'] + 489 row_df['away_line_scores'] = str(game['away_line_scores']) + 490 row_df['away_post_win_prob'] = game['away_post_win_prob'] + 491 row_df['away_pregame_elo'] = game['away_pregame_elo'] + 492 row_df['away_postgame_elo'] = game['away_postgame_elo'] + 493 row_df['excitement_index'] = game['excitement_index'] + 494 row_df['highlights'] = game['highlights'] + 495 row_df['notes'] = game['notes'] + 496 + 497 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) + 498 del row_df + 499 + 500 if len(cfb_games_df) == 0: + 501 logging.error( + 502 "The CFBD API accepted your inputs, " + + 503 "but found no data within your specified input paramaters." + + 504 " Please double check your input paramaters." + 505 ) + 506 + 507 return cfb_games_df + 508 509 - 510 - 511def get_cfbd_team_records( - 512 api_key: str = None, - 513 api_key_dir: str = None, - 514 season: int = None, - 515 team: str = None, # Must specify either a year or team - 516 conference_abv: str = None, - 517 return_as_dict: bool = False): - 518 """ - 519 Get a team, or multiple team's record (wins, losses, ties) for home games, away games, - 520 confrence games, and the team's record for that season. - 521 - 522 Parameters - 523 ---------- - 524 - 525 `api_key` (str, optional): - 526 Semi-optional argument. - 527 If `api_key` is null, this function will attempt to load a CFBD API key - 528 from the python environment, or from a file on this computer. - 529 If `api_key` is not null, this function will automatically assume that the - 530 inputted `api_key` is a valid CFBD API key. - 531 - 532 `api_key_dir` (str, optional): - 533 Optional argument. - 534 If `api_key` is set to a string non-empty string, this variable is ignored. - 535 If `api_key_dir` is null, and `api_key` is null, - 536 this function will try to find a CFBD API key file in this user's home directory. - 537 If `api_key_dir` is set to a string, and `api_key` is null, - 538 this function will assume that `api_key_dir` is a directory, - 539 and will try to find a CFBD API key file in that directory. - 540 - 541 `season` (int, optional): - 542 Semi-optional argument. - 543 Specifies the season you want CFB team records data from. - 544 You MUST set `season` or `team` to a non-null value for - 545 this function to work. If you don't, a `ValueError()` - 546 will be raised. - 547 - 548 `team` (str, optional): - 549 Semi-ptional argument. - 550 If you only want CFB team records data for a specific team, - 551 set `team` to the name of the team you want CFB drive data from. - 552 You MUST set `season` or `team` to a non-null value for - 553 this function to work. If you don't, a `ValueError()` - 554 will be raised. - 555 - 556 `conference_abv` (str, optional): - 557 Optional argument. - 558 If you only want CFB team records data from games - 559 involving teams from a specific confrence, - 560 set `conference_abv` to the abbreviation - 561 of the conference you want CFB team records data from. - 562 For a list of confrences, - 563 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` - 564 function. - 565 - 566 `return_as_dict` (bool, semi-optional): - 567 Semi-optional argument. - 568 If you want this function to return the data as a dictionary (read: JSON object), - 569 instead of a pandas `DataFrame` object, - 570 set `return_as_dict` to `True`. - 571 - 572 Usage - 573 ---------- - 574 ``` - 575 import time - 576 - 577 from cfbd_json_py.games import get_cfbd_team_records + 510def get_cfbd_team_records( + 511 api_key: str = None, + 512 api_key_dir: str = None, + 513 season: int = None, + 514 team: str = None, # Must specify either a year or team + 515 conference_abv: str = None, + 516 return_as_dict: bool = False): + 517 """ + 518 Get a team, or multiple team's record (wins, losses, ties) for home games, away games, + 519 confrence games, and the team's record for that season. + 520 + 521 Parameters + 522 ---------- + 523 + 524 `api_key` (str, optional): + 525 Semi-optional argument. + 526 If `api_key` is null, this function will attempt to load a CFBD API key + 527 from the python environment, or from a file on this computer. + 528 If `api_key` is not null, this function will automatically assume that the + 529 inputted `api_key` is a valid CFBD API key. + 530 + 531 `api_key_dir` (str, optional): + 532 Optional argument. + 533 If `api_key` is set to am empty string, this variable is ignored. + 534 If `api_key_dir` is null, and `api_key` is null, + 535 this function will try to find a CFBD API key file in this user's home directory. + 536 If `api_key_dir` is set to a string, and `api_key` is null, + 537 this function will assume that `api_key_dir` is a directory, + 538 and will try to find a CFBD API key file in that directory. + 539 + 540 `season` (int, optional): + 541 Semi-optional argument. + 542 Specifies the season you want CFB team records data from. + 543 You MUST set `season` or `team` to a non-null value for + 544 this function to work. If you don't, a `ValueError()` + 545 will be raised. + 546 + 547 `team` (str, optional): + 548 Semi-ptional argument. + 549 If you only want CFB team records data for a specific team, + 550 set `team` to the name of the team you want CFB drive data from. + 551 You MUST set `season` or `team` to a non-null value for + 552 this function to work. If you don't, a `ValueError()` + 553 will be raised. + 554 + 555 `conference_abv` (str, optional): + 556 Optional argument. + 557 If you only want CFB team records data from games + 558 involving teams from a specific confrence, + 559 set `conference_abv` to the abbreviation + 560 of the conference you want CFB team records data from. + 561 For a list of confrences, + 562 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` + 563 function. + 564 + 565 `return_as_dict` (bool, semi-optional): + 566 Semi-optional argument. + 567 If you want this function to return the data as a dictionary (read: JSON object), + 568 instead of a pandas `DataFrame` object, + 569 set `return_as_dict` to `True`. + 570 + 571 Usage + 572 ---------- + 573 ``` + 574 import time + 575 + 576 from cfbd_json_py.games import get_cfbd_team_records + 577 578 - 579 - 580 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 581 - 582 if cfbd_key != "tigersAreAwsome": - 583 print("Using the user's API key declared in this script for this example.") - 584 - 585 # Get CFB team records from the 2020 CFB season. - 586 print("Get CFB team records from the 2020 CFB season.") - 587 json_data = get_cfbd_team_records( - 588 api_key=cfbd_key, - 589 season=2020 - 590 ) - 591 print(json_data) - 592 time.sleep(5) - 593 - 594 # Get team records from football teams fielded by the University of Cincinnati. - 595 print("Get team records from football teams fielded by the University of Cincinnati.") - 596 json_data = get_cfbd_team_records( - 597 api_key=cfbd_key, - 598 team="Cincinnati" - 599 ) - 600 print(json_data) - 601 time.sleep(5) - 602 - 603 # Get team records from football teams that played in the Big 10 (B1G) Confrence - 604 # in the 2017 CFB season - 605 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") - 606 json_data = get_cfbd_team_records( - 607 api_key=cfbd_key, - 608 season=2017, - 609 conference_abv="B1G" - 610 ) - 611 print(json_data) - 612 time.sleep(5) + 579 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 580 + 581 if cfbd_key != "tigersAreAwsome": + 582 print("Using the user's API key declared in this script for this example.") + 583 + 584 # Get CFB team records from the 2020 CFB season. + 585 print("Get CFB team records from the 2020 CFB season.") + 586 json_data = get_cfbd_team_records( + 587 api_key=cfbd_key, + 588 season=2020 + 589 ) + 590 print(json_data) + 591 time.sleep(5) + 592 + 593 # Get team records from football teams fielded by the University of Cincinnati. + 594 print("Get team records from football teams fielded by the University of Cincinnati.") + 595 json_data = get_cfbd_team_records( + 596 api_key=cfbd_key, + 597 team="Cincinnati" + 598 ) + 599 print(json_data) + 600 time.sleep(5) + 601 + 602 # Get team records from football teams that played in the Big 10 (B1G) Confrence + 603 # in the 2017 CFB season + 604 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") + 605 json_data = get_cfbd_team_records( + 606 api_key=cfbd_key, + 607 season=2017, + 608 conference_abv="B1G" + 609 ) + 610 print(json_data) + 611 time.sleep(5) + 612 613 - 614 - 615 # You can also tell this function to just return the API call as - 616 # a Dictionary (read: JSON) object. - 617 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 618 json_data = get_cfbd_team_records( - 619 season=2020, - 620 api_key=cfbd_key, - 621 return_as_dict=True - 622 ) - 623 print(json_data) - 624 - 625 else: - 626 # Alternatively, if the CFBD API key exists in this python environment, - 627 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 628 # you could just call these functions directly, without setting the API key - 629 # in the script. - 630 print("Using the user's API key suposedly loaded into this python environment for this example.") - 631 - 632 # Get CFB team records from the 2020 CFB season. - 633 print("Get CFB team records from the 2020 CFB season.") - 634 json_data = get_cfbd_team_records( - 635 season=2020 - 636 ) - 637 print(json_data) - 638 time.sleep(5) - 639 - 640 # Get team records from football teams fielded by the University of Cincinnati. - 641 print("Get team records from football teams fielded by the University of Cincinnati.") - 642 json_data = get_cfbd_team_records( - 643 team="Cincinnati" - 644 ) - 645 print(json_data) - 646 time.sleep(5) - 647 - 648 # Get team records from football teams that played in the Big 10 (B1G) Confrence - 649 # in the 2017 CFB season - 650 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") - 651 json_data = get_cfbd_team_records( - 652 season=2017, - 653 conference_abv="B1G" - 654 ) - 655 print(json_data) - 656 time.sleep(5) - 657 - 658 # You can also tell this function to just return the API call as - 659 # a Dictionary (read: JSON) object. - 660 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 661 json_data = get_cfbd_team_records( - 662 season=2020, - 663 return_as_dict=True - 664 ) - 665 print(json_data) - 666 - 667 ``` - 668 - 669 Returns - 670 ---------- - 671 A pandas `DataFrame` object with CFB team records data, - 672 or (if `return_as_dict` is set to `True`) - 673 a dictionary object with CFB team records data. - 674 - 675 """ - 676 - 677 now = datetime.now() - 678 cfb_records_df = pd.DataFrame() - 679 row_df = pd.DataFrame() - 680 url = "https://api.collegefootballdata.com/records" - 681 - 682 ######################################################################################################################################################################################################## - 683 - 684 if api_key != None: - 685 real_api_key = api_key - 686 del api_key - 687 else: - 688 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) - 689 - 690 if real_api_key == "tigersAreAwsome": - 691 raise ValueError( - 692 "You actually need to change `cfbd_key` to your CFBD API key.") - 693 elif "Bearer " in real_api_key: - 694 pass - 695 elif "Bearer" in real_api_key: - 696 real_api_key = real_api_key.replace('Bearer', 'Bearer ') - 697 else: - 698 real_api_key = "Bearer " + real_api_key - 699 - 700 if season != None and season > now.year: - 701 raise ValueError(f"`season` cannot be greater than {season}.") - 702 elif season != None and season < 1869: - 703 raise ValueError(f"`season` cannot be less than 1869.") - 704 - 705 if season == None and team == None: - 706 raise ValueError( - 707 f"If you call `cfbd_json_py.games.get_cfbd_team_records()`, you must specifiy at least a team or CFB season.") - 708 - 709 # URL builder - 710 ######################################################################################################################################################################################################## - 711 url_elements = 0 - 712 - 713 if season != None and url_elements == 0: - 714 url += f"?year={season}" - 715 url_elements += 1 - 716 elif season != None: - 717 url += f"&year={season}" - 718 url_elements += 1 - 719 - 720 if team != None and url_elements == 0: - 721 url += f"?team={team}" - 722 url_elements += 1 - 723 elif team != None: - 724 url += f"&team={team}" - 725 url_elements += 1 - 726 - 727 if conference_abv != None and url_elements == 0: - 728 url += f"?conference={conference_abv}" - 729 url_elements += 1 - 730 elif conference_abv != None: - 731 url += f"&conference={conference_abv}" - 732 url_elements += 1 - 733 - 734 headers = { - 735 'Authorization': f'{real_api_key}', - 736 'accept': 'application/json' - 737 } - 738 - 739 response = requests.get(url, headers=headers) - 740 time.sleep(0.1) - 741 - 742 if response.status_code == 200: - 743 pass - 744 elif response.status_code == 401: - 745 raise ConnectionRefusedError( - 746 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' - 747 ) - 748 else: - 749 raise ConnectionError( - 750 f'Could not connect.\nHTTP Status code {response.status_code}' - 751 ) - 752 - 753 json_data = response.json() - 754 - 755 if return_as_dict == True: - 756 return json_data - 757 - 758 for team in json_data: - 759 team_year = team['year'] - 760 row_df = pd.DataFrame( - 761 {"season": team_year}, - 762 index=[0] - 763 ) - 764 row_df['team_id'] = team['teamId'] - 765 row_df['team_name'] = team['team'] - 766 row_df['conference_name'] = team['conference'] - 767 if team['division'] == "" or team['division'] == None: - 768 row_df['conference_division'] = None - 769 else: - 770 row_df['conference_division'] = team['division'] - 771 - 772 row_df['expected_wins'] = team['expectedWins'] - 773 row_df['total_games'] = team['total']['games'] - 774 row_df['total_wins'] = team['total']['wins'] - 775 row_df['total_losses'] = team['total']['losses'] - 776 row_df['total_ties'] = team['total']['ties'] - 777 row_df['conference_games'] = team['conferenceGames']['games'] - 778 row_df['conference_wins'] = team['conferenceGames']['wins'] - 779 row_df['conference_losses'] = team['conferenceGames']['losses'] - 780 row_df['conference_ties'] = team['conferenceGames']['ties'] - 781 row_df['home_games'] = team['homeGames']['games'] - 782 row_df['home_wins'] = team['homeGames']['wins'] - 783 row_df['home_losses'] = team['homeGames']['losses'] - 784 row_df['home_ties'] = team['homeGames']['ties'] - 785 row_df['away_games'] = team['awayGames']['games'] - 786 row_df['away_wins'] = team['awayGames']['wins'] - 787 row_df['away_losses'] = team['awayGames']['losses'] - 788 row_df['away_ties'] = team['awayGames']['ties'] - 789 - 790 cfb_records_df = pd.concat([cfb_records_df, row_df], ignore_index=True) - 791 del row_df - 792 - 793 return cfb_records_df + 614 # You can also tell this function to just return the API call as + 615 # a Dictionary (read: JSON) object. + 616 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 617 json_data = get_cfbd_team_records( + 618 season=2020, + 619 api_key=cfbd_key, + 620 return_as_dict=True + 621 ) + 622 print(json_data) + 623 + 624 else: + 625 # Alternatively, if the CFBD API key exists in this python environment, + 626 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 627 # you could just call these functions directly, without setting the API key + 628 # in the script. + 629 print("Using the user's API key suposedly loaded into this python environment for this example.") + 630 + 631 # Get CFB team records from the 2020 CFB season. + 632 print("Get CFB team records from the 2020 CFB season.") + 633 json_data = get_cfbd_team_records( + 634 season=2020 + 635 ) + 636 print(json_data) + 637 time.sleep(5) + 638 + 639 # Get team records from football teams fielded by the University of Cincinnati. + 640 print("Get team records from football teams fielded by the University of Cincinnati.") + 641 json_data = get_cfbd_team_records( + 642 team="Cincinnati" + 643 ) + 644 print(json_data) + 645 time.sleep(5) + 646 + 647 # Get team records from football teams that played in the Big 10 (B1G) Confrence + 648 # in the 2017 CFB season + 649 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") + 650 json_data = get_cfbd_team_records( + 651 season=2017, + 652 conference_abv="B1G" + 653 ) + 654 print(json_data) + 655 time.sleep(5) + 656 + 657 # You can also tell this function to just return the API call as + 658 # a Dictionary (read: JSON) object. + 659 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 660 json_data = get_cfbd_team_records( + 661 season=2020, + 662 return_as_dict=True + 663 ) + 664 print(json_data) + 665 + 666 ``` + 667 + 668 Returns + 669 ---------- + 670 A pandas `DataFrame` object with CFB team records data, + 671 or (if `return_as_dict` is set to `True`) + 672 a dictionary object with CFB team records data. + 673 + 674 """ + 675 + 676 now = datetime.now() + 677 cfb_records_df = pd.DataFrame() + 678 row_df = pd.DataFrame() + 679 url = "https://api.collegefootballdata.com/records" + 680 + 681 ######################################################################################################################################################################################################## + 682 + 683 if api_key != None: + 684 real_api_key = api_key + 685 del api_key + 686 else: + 687 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + 688 + 689 if real_api_key == "tigersAreAwsome": + 690 raise ValueError( + 691 "You actually need to change `cfbd_key` to your CFBD API key.") + 692 elif "Bearer " in real_api_key: + 693 pass + 694 elif "Bearer" in real_api_key: + 695 real_api_key = real_api_key.replace('Bearer', 'Bearer ') + 696 else: + 697 real_api_key = "Bearer " + real_api_key + 698 + 699 if season != None and season > now.year: + 700 raise ValueError(f"`season` cannot be greater than {season}.") + 701 elif season != None and season < 1869: + 702 raise ValueError(f"`season` cannot be less than 1869.") + 703 + 704 if season == None and team == None: + 705 raise ValueError( + 706 f"If you call `cfbd_json_py.games.get_cfbd_team_records()`, you must specifiy at least a team or CFB season.") + 707 + 708 # URL builder + 709 ######################################################################################################################################################################################################## + 710 url_elements = 0 + 711 + 712 if season != None and url_elements == 0: + 713 url += f"?year={season}" + 714 url_elements += 1 + 715 elif season != None: + 716 url += f"&year={season}" + 717 url_elements += 1 + 718 + 719 if team != None and url_elements == 0: + 720 url += f"?team={team}" + 721 url_elements += 1 + 722 elif team != None: + 723 url += f"&team={team}" + 724 url_elements += 1 + 725 + 726 if conference_abv != None and url_elements == 0: + 727 url += f"?conference={conference_abv}" + 728 url_elements += 1 + 729 elif conference_abv != None: + 730 url += f"&conference={conference_abv}" + 731 url_elements += 1 + 732 + 733 headers = { + 734 'Authorization': f'{real_api_key}', + 735 'accept': 'application/json' + 736 } + 737 + 738 response = requests.get(url, headers=headers) + 739 + 740 + 741 if response.status_code == 200: + 742 pass + 743 elif response.status_code == 401: + 744 raise ConnectionRefusedError( + 745 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + 746 ) + 747 else: + 748 raise ConnectionError( + 749 f'Could not connect.\nHTTP Status code {response.status_code}' + 750 ) + 751 + 752 json_data = response.json() + 753 + 754 if return_as_dict == True: + 755 return json_data + 756 + 757 for team in json_data: + 758 team_year = team['year'] + 759 row_df = pd.DataFrame( + 760 {"season": team_year}, + 761 index=[0] + 762 ) + 763 row_df['team_id'] = team['teamId'] + 764 row_df['team_name'] = team['team'] + 765 row_df['conference_name'] = team['conference'] + 766 if team['division'] == "" or team['division'] == None: + 767 row_df['conference_division'] = None + 768 else: + 769 row_df['conference_division'] = team['division'] + 770 + 771 row_df['expected_wins'] = team['expectedWins'] + 772 row_df['total_games'] = team['total']['games'] + 773 row_df['total_wins'] = team['total']['wins'] + 774 row_df['total_losses'] = team['total']['losses'] + 775 row_df['total_ties'] = team['total']['ties'] + 776 row_df['conference_games'] = team['conferenceGames']['games'] + 777 row_df['conference_wins'] = team['conferenceGames']['wins'] + 778 row_df['conference_losses'] = team['conferenceGames']['losses'] + 779 row_df['conference_ties'] = team['conferenceGames']['ties'] + 780 row_df['home_games'] = team['homeGames']['games'] + 781 row_df['home_wins'] = team['homeGames']['wins'] + 782 row_df['home_losses'] = team['homeGames']['losses'] + 783 row_df['home_ties'] = team['homeGames']['ties'] + 784 row_df['away_games'] = team['awayGames']['games'] + 785 row_df['away_wins'] = team['awayGames']['wins'] + 786 row_df['away_losses'] = team['awayGames']['losses'] + 787 row_df['away_ties'] = team['awayGames']['ties'] + 788 + 789 cfb_records_df = pd.concat([cfb_records_df, row_df], ignore_index=True) + 790 del row_df + 791 + 792 return cfb_records_df + 793 794 - 795 - 796def get_cfbd_season_weeks( - 797 season: int, - 798 api_key: str = None, - 799 api_key_dir: str = None, - 800 return_as_dict: bool = False): - 801 """ - 802 Retrives a list of weeks that occured in a given CFB season. - 803 - 804 Parameters - 805 ---------- - 806 `season` (int, mandatory): - 807 Required argument. - 808 Specifies the season you want a list of weeks that occured in a given CFB season information from. - 809 This must be specified, otherwise this package, and by extension - 810 the CFBD API, will not accept the request to get a list of weeks that occured in a given CFB season information. - 811 - 812 `api_key` (str, optional): - 813 Semi-optional argument. - 814 If `api_key` is null, this function will attempt to load a CFBD API key - 815 from the python environment, or from a file on this computer. - 816 If `api_key` is not null, this function will automatically assume that the - 817 inputted `api_key` is a valid CFBD API key. - 818 - 819 `api_key_dir` (str, optional): - 820 Optional argument. - 821 If `api_key` is set to a string non-empty string, this variable is ignored. - 822 If `api_key_dir` is null, and `api_key` is null, - 823 this function will try to find a CFBD API key file in this user's home directory. - 824 If `api_key_dir` is set to a string, and `api_key` is null, - 825 this function will assume that `api_key_dir` is a directory, - 826 and will try to find a CFBD API key file in that directory. - 827 - 828 `return_as_dict` (bool, semi-optional): - 829 Semi-optional argument. - 830 If you want this function to return the data as a dictionary (read: JSON object), - 831 instead of a pandas `DataFrame` object, - 832 set `return_as_dict` to `True`. + 795def get_cfbd_season_weeks( + 796 season: int, + 797 api_key: str = None, + 798 api_key_dir: str = None, + 799 return_as_dict: bool = False): + 800 """ + 801 Retrives a list of weeks that occured in a given CFB season. + 802 + 803 Parameters + 804 ---------- + 805 `season` (int, mandatory): + 806 Required argument. + 807 Specifies the season you want a list of weeks that occured in a given CFB season information from. + 808 This must be specified, otherwise this package, and by extension + 809 the CFBD API, will not accept the request to get a list of weeks that occured in a given CFB season information. + 810 + 811 `api_key` (str, optional): + 812 Semi-optional argument. + 813 If `api_key` is null, this function will attempt to load a CFBD API key + 814 from the python environment, or from a file on this computer. + 815 If `api_key` is not null, this function will automatically assume that the + 816 inputted `api_key` is a valid CFBD API key. + 817 + 818 `api_key_dir` (str, optional): + 819 Optional argument. + 820 If `api_key` is set to am empty string, this variable is ignored. + 821 If `api_key_dir` is null, and `api_key` is null, + 822 this function will try to find a CFBD API key file in this user's home directory. + 823 If `api_key_dir` is set to a string, and `api_key` is null, + 824 this function will assume that `api_key_dir` is a directory, + 825 and will try to find a CFBD API key file in that directory. + 826 + 827 `return_as_dict` (bool, semi-optional): + 828 Semi-optional argument. + 829 If you want this function to return the data as a dictionary (read: JSON object), + 830 instead of a pandas `DataFrame` object, + 831 set `return_as_dict` to `True`. + 832 833 - 834 - 835 Usage - 836 ---------- - 837 ``` - 838 import time - 839 - 840 from cfbd_json_py.games import get_cfbd_season_weeks + 834 Usage + 835 ---------- + 836 ``` + 837 import time + 838 + 839 from cfbd_json_py.games import get_cfbd_season_weeks + 840 841 - 842 - 843 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. - 844 - 845 if cfbd_key != "tigersAreAwsome": - 846 print("Using the user's API key declared in this script for this example.") - 847 - 848 # Get a list of weeks in the 2020 CFB season. - 849 print("Get a list of weeks in the 2020 CFB season.") - 850 json_data = get_cfbd_season_weeks( - 851 api_key=cfbd_key, - 852 season=2020 - 853 ) - 854 print(json_data) - 855 time.sleep(5) + 842 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 843 + 844 if cfbd_key != "tigersAreAwsome": + 845 print("Using the user's API key declared in this script for this example.") + 846 + 847 # Get a list of weeks in the 2020 CFB season. + 848 print("Get a list of weeks in the 2020 CFB season.") + 849 json_data = get_cfbd_season_weeks( + 850 api_key=cfbd_key, + 851 season=2020 + 852 ) + 853 print(json_data) + 854 time.sleep(5) + 855 856 - 857 - 858 # You can also tell this function to just return the API call as - 859 # a Dictionary (read: JSON) object. - 860 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 861 json_data = get_cfbd_season_weeks( - 862 season=2020, - 863 api_key=cfbd_key, - 864 return_as_dict=True - 865 ) - 866 print(json_data) - 867 - 868 else: - 869 # Alternatively, if the CFBD API key exists in this python environment, - 870 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), - 871 # you could just call these functions directly, without setting the API key - 872 # in the script. - 873 print("Using the user's API key suposedly loaded into this python environment for this example.") - 874 - 875 # Get a list of weeks in the 2020 CFB season. - 876 print("Get a list of weeks in the 2020 CFB season.") - 877 json_data = get_cfbd_season_weeks( - 878 season=2020 - 879 ) - 880 print(json_data) - 881 time.sleep(5) + 857 # You can also tell this function to just return the API call as + 858 # a Dictionary (read: JSON) object. + 859 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 860 json_data = get_cfbd_season_weeks( + 861 season=2020, + 862 api_key=cfbd_key, + 863 return_as_dict=True + 864 ) + 865 print(json_data) + 866 + 867 else: + 868 # Alternatively, if the CFBD API key exists in this python environment, + 869 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 870 # you could just call these functions directly, without setting the API key + 871 # in the script. + 872 print("Using the user's API key suposedly loaded into this python environment for this example.") + 873 + 874 # Get a list of weeks in the 2020 CFB season. + 875 print("Get a list of weeks in the 2020 CFB season.") + 876 json_data = get_cfbd_season_weeks( + 877 season=2020 + 878 ) + 879 print(json_data) + 880 time.sleep(5) + 881 882 - 883 - 884 # You can also tell this function to just return the API call as - 885 # a Dictionary (read: JSON) object. - 886 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") - 887 json_data = get_cfbd_season_weeks( - 888 season=2020, - 889 return_as_dict=True - 890 ) - 891 print(json_data) - 892 - 893 ``` - 894 - 895 Returns - 896 ---------- - 897 A pandas `DataFrame` object with a list of valid weeks in a given CFB season, - 898 or (if `return_as_dict` is set to `True`) - 899 a dictionary object with a list of valid weeks in a given CFB season. + 883 # You can also tell this function to just return the API call as + 884 # a Dictionary (read: JSON) object. + 885 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 886 json_data = get_cfbd_season_weeks( + 887 season=2020, + 888 return_as_dict=True + 889 ) + 890 print(json_data) + 891 + 892 ``` + 893 + 894 Returns + 895 ---------- + 896 A pandas `DataFrame` object with a list of valid weeks in a given CFB season, + 897 or (if `return_as_dict` is set to `True`) + 898 a dictionary object with a list of valid weeks in a given CFB season. + 899 900 - 901 - 902 """ - 903 - 904 now = datetime.now() - 905 cfb_weeks_df = pd.DataFrame() - 906 row_df = pd.DataFrame() - 907 url = "https://api.collegefootballdata.com/calendar" - 908 - 909 ######################################################################################################################################################################################################## - 910 - 911 if api_key != None: - 912 real_api_key = api_key - 913 del api_key - 914 else: - 915 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) - 916 - 917 if real_api_key == "tigersAreAwsome": - 918 raise ValueError( - 919 "You actually need to change `cfbd_key` to your CFBD API key.") - 920 elif "Bearer " in real_api_key: - 921 pass - 922 elif "Bearer" in real_api_key: - 923 real_api_key = real_api_key.replace('Bearer', 'Bearer ') - 924 else: - 925 real_api_key = "Bearer " + real_api_key - 926 - 927 if season == None: - 928 # This should never happen without user tampering, but if it does, - 929 # we need to raise an error, because the CFBD API will refuse this call without a valid season. - 930 raise SystemError( - 931 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + - 932 " and the function got to this point in the code." + - 933 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + - 934 "https://github.com/armstjc/cfbd-json-py/issues" - 935 ) - 936 elif season > now.year: - 937 raise ValueError(f"`season` cannot be greater than {season}.") - 938 elif season < 1869: - 939 raise ValueError(f"`season` cannot be less than 1869.") - 940 - 941 # URL builder - 942 ######################################################################################################################################################################################################## - 943 - 944 # Required by API - 945 url += f"?year={season}" - 946 - 947 headers = { - 948 'Authorization': f'{real_api_key}', - 949 'accept': 'application/json' - 950 } - 951 - 952 response = requests.get(url, headers=headers) - 953 time.sleep(0.1) - 954 - 955 if response.status_code == 200: - 956 pass - 957 elif response.status_code == 401: - 958 raise ConnectionRefusedError( - 959 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' - 960 ) - 961 else: - 962 raise ConnectionError( - 963 f'Could not connect.\nHTTP Status code {response.status_code}' - 964 ) - 965 - 966 json_data = response.json() - 967 - 968 if return_as_dict == True: - 969 return json_data - 970 - 971 for week in json_data: - 972 row_df = pd.DataFrame( - 973 {"season": season}, - 974 index=[0] - 975 ) - 976 row_df['week'] = week['week'] - 977 row_df['season_type'] = week['seasonType'] - 978 row_df['first_game_start'] = week['firstGameStart'] - 979 row_df['last_game_start'] = week['lastGameStart'] - 980 - 981 cfb_weeks_df = pd.concat([cfb_weeks_df, row_df], ignore_index=True) - 982 del row_df - 983 - 984 return cfb_weeks_df + 901 """ + 902 + 903 now = datetime.now() + 904 cfb_weeks_df = pd.DataFrame() + 905 row_df = pd.DataFrame() + 906 url = "https://api.collegefootballdata.com/calendar" + 907 + 908 ######################################################################################################################################################################################################## + 909 + 910 if api_key != None: + 911 real_api_key = api_key + 912 del api_key + 913 else: + 914 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + 915 + 916 if real_api_key == "tigersAreAwsome": + 917 raise ValueError( + 918 "You actually need to change `cfbd_key` to your CFBD API key.") + 919 elif "Bearer " in real_api_key: + 920 pass + 921 elif "Bearer" in real_api_key: + 922 real_api_key = real_api_key.replace('Bearer', 'Bearer ') + 923 else: + 924 real_api_key = "Bearer " + real_api_key + 925 + 926 if season == None: + 927 # This should never happen without user tampering, but if it does, + 928 # we need to raise an error, because the CFBD API will refuse this call without a valid season. + 929 raise SystemError( + 930 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + + 931 " and the function got to this point in the code." + + 932 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + + 933 "https://github.com/armstjc/cfbd-json-py/issues" + 934 ) + 935 elif season > now.year: + 936 raise ValueError(f"`season` cannot be greater than {season}.") + 937 elif season < 1869: + 938 raise ValueError(f"`season` cannot be less than 1869.") + 939 + 940 # URL builder + 941 ######################################################################################################################################################################################################## + 942 + 943 # Required by API + 944 url += f"?year={season}" + 945 + 946 headers = { + 947 'Authorization': f'{real_api_key}', + 948 'accept': 'application/json' + 949 } + 950 + 951 response = requests.get(url, headers=headers) + 952 + 953 + 954 if response.status_code == 200: + 955 pass + 956 elif response.status_code == 401: + 957 raise ConnectionRefusedError( + 958 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + 959 ) + 960 else: + 961 raise ConnectionError( + 962 f'Could not connect.\nHTTP Status code {response.status_code}' + 963 ) + 964 + 965 json_data = response.json() + 966 + 967 if return_as_dict == True: + 968 return json_data + 969 + 970 for week in json_data: + 971 row_df = pd.DataFrame( + 972 {"season": season}, + 973 index=[0] + 974 ) + 975 row_df['week'] = week['week'] + 976 row_df['season_type'] = week['seasonType'] + 977 row_df['first_game_start'] = week['firstGameStart'] + 978 row_df['last_game_start'] = week['lastGameStart'] + 979 + 980 cfb_weeks_df = pd.concat([cfb_weeks_df, row_df], ignore_index=True) + 981 del row_df + 982 + 983 return cfb_weeks_df + 984 985 - 986 - 987def get_cfbd_game_media_info( - 988 season: int, - 989 api_key: str = None, - 990 api_key_dir: str = None, - 991 season_type: str = "regular", # "regular", "postseason", or "both" - 992 week: int = None, - 993 team: str = None, - 994 conference_abv: str = None, - 995 media_type: str = "all", # "tv", "radio", "web", "ppv", or "mobile" - 996 ncaa_division: str = "fbs", - 997 return_as_dict: bool = False): - 998 """ - 999 Gets known media information for CFB games in a given CFB season. -1000 -1001 Parameters -1002 ---------- -1003 `season` (int, mandatory): -1004 Required argument. -1005 Specifies the season you want CFB media information from. -1006 This must be specified, otherwise this package, and by extension -1007 the CFBD API, will not accept the request to get CFB media information. -1008 -1009 `api_key` (str, optional): -1010 Semi-optional argument. -1011 If `api_key` is null, this function will attempt to load a CFBD API key -1012 from the python environment, or from a file on this computer. -1013 If `api_key` is not null, this function will automatically assume that the -1014 inputted `api_key` is a valid CFBD API key. -1015 -1016 `api_key_dir` (str, optional): -1017 Optional argument. -1018 If `api_key` is set to a string non-empty string, this variable is ignored. -1019 If `api_key_dir` is null, and `api_key` is null, -1020 this function will try to find a CFBD API key file in this user's home directory. -1021 If `api_key_dir` is set to a string, and `api_key` is null, -1022 this function will assume that `api_key_dir` is a directory, -1023 and will try to find a CFBD API key file in that directory. -1024 -1025 `season_type` (str, semi-optional): -1026 Semi-optional argument. -1027 By defualt, this will be set to "regular", for the CFB regular season. -1028 If you want CFB media information for non-regular season games, -1029 set `season_type` to "postseason". -1030 If you want both "regular" and "postseason" games retunred, -1031 set `season_type` to "both" -1032 If `season_type` is set to anything but "regular" or "postseason", -1033 a `ValueError()` will be raised. -1034 -1035 `week` (int, optional): -1036 Optional argument. -1037 If `week` is set to an integer, this function will attempt -1038 to load CFB media information from games in that season, and in that week. -1039 -1040 `team` (str, optional): -1041 Optional argument. -1042 If you only want CFB media information for a team, -1043 regardless if they are the home/away team, -1044 set `team` to the name of the team you want CFB media information from. -1045 -1046 `conference_abv` (str, optional): -1047 Optional argument. -1048 If you only want media information from games -1049 involving teams a specific confrence, -1050 set `conference_abv` to the abbreviation -1051 of the conference you want game information from. -1052 -1053 `media_type` (str, semi-optional): -1054 Semi-optional argument. -1055 If you only want game broadcast information for a specific type of broadcast, -1056 set this to the type of broadcast. -1057 -1058 Valid inputs are: -1059 - `all` (default): Returns all games, and all known broadcasters for those games. -1060 - `tv`: Returns all known TV broadcasters for CFB games in the requested timeframe. -1061 - `radio`: Returns all known radio broadcasters -1062 for CFB games in the requested timeframe. -1063 - `web`: Returns all known web broadcasts (like ESPN+) -1064 for CFB games in the requested timeframe. -1065 - `ppv`: Returns all known Pay Per View (PPV) broadcasts -1066 for CFB games in the requested timeframe. -1067 - `mobile`: Returns all known broadcasters that only broadcasted -1068 games on mobile devices (?) -1069 -1070 `ncaa_division` (str, semi-optional): -1071 Semi-optional argument. -1072 By default, `ncaa_division` will be set to "fbs", -1073 short for the Football Bowl Subdivision (FBS), -1074 formerly known as D1-A (read as "division one single A"), -1075 the highest level in the NCAA football pyramid, -1076 where teams can scolarship up to 85 players -1077 on their football team soley for athletic ability, -1078 and often have the largest athletics budgets -1079 within the NCAA. -1080 -1081 Other valid inputs are: -1082 - "fcs": Football Championship Subdivision (FCS), -1083 formerly known as D1-AA (read as "division one double A"). -1084 An FCS school is still in the 1st division of the NCAA, -1085 making them elligable for the March Madness tournament, -1086 but may not have the resources to compete at the FBS level -1087 at this time. FCS schools are limited to 63 athletic scolarships -1088 for football. -1089 - "ii": NCAA Division II. Schools in this and D3 are not -1090 elligable for the March Madness tournament, -1091 and are limited to 36 athletic scolarships for their football team. -1092 - "iii": NCAA Division III. The largest single division within the -1093 NCAA football pyramid. -1094 D3 schools have the distinction of being part of -1095 the only NCAA division that cannot give out scolarships soley -1096 for athletic ability. -1097 -1098 `return_as_dict` (bool, semi-optional): -1099 Semi-optional argument. -1100 If you want this function to return the data as a dictionary (read: JSON object), -1101 instead of a pandas `DataFrame` object, -1102 set `return_as_dict` to `True`. -1103 -1104 Usage -1105 ---------- -1106 ``` -1107 import time -1108 -1109 from cfbd_json_py.games import get_cfbd_game_media_info + 986def get_cfbd_game_media_info( + 987 season: int, + 988 api_key: str = None, + 989 api_key_dir: str = None, + 990 season_type: str = "regular", # "regular", "postseason", or "both" + 991 week: int = None, + 992 team: str = None, + 993 conference_abv: str = None, + 994 media_type: str = "all", # "tv", "radio", "web", "ppv", or "mobile" + 995 ncaa_division: str = "fbs", + 996 return_as_dict: bool = False): + 997 """ + 998 Gets known media information for CFB games in a given CFB season. + 999 +1000 Parameters +1001 ---------- +1002 `season` (int, mandatory): +1003 Required argument. +1004 Specifies the season you want CFB media information from. +1005 This must be specified, otherwise this package, and by extension +1006 the CFBD API, will not accept the request to get CFB media information. +1007 +1008 `api_key` (str, optional): +1009 Semi-optional argument. +1010 If `api_key` is null, this function will attempt to load a CFBD API key +1011 from the python environment, or from a file on this computer. +1012 If `api_key` is not null, this function will automatically assume that the +1013 inputted `api_key` is a valid CFBD API key. +1014 +1015 `api_key_dir` (str, optional): +1016 Optional argument. +1017 If `api_key` is set to am empty string, this variable is ignored. +1018 If `api_key_dir` is null, and `api_key` is null, +1019 this function will try to find a CFBD API key file in this user's home directory. +1020 If `api_key_dir` is set to a string, and `api_key` is null, +1021 this function will assume that `api_key_dir` is a directory, +1022 and will try to find a CFBD API key file in that directory. +1023 +1024 `season_type` (str, semi-optional): +1025 Semi-optional argument. +1026 By defualt, this will be set to "regular", for the CFB regular season. +1027 If you want CFB media information for non-regular season games, +1028 set `season_type` to "postseason". +1029 If you want both "regular" and "postseason" games retunred, +1030 set `season_type` to "both" +1031 If `season_type` is set to anything but "regular" or "postseason", +1032 a `ValueError()` will be raised. +1033 +1034 `week` (int, optional): +1035 Optional argument. +1036 If `week` is set to an integer, this function will attempt +1037 to load CFB media information from games in that season, and in that week. +1038 +1039 `team` (str, optional): +1040 Optional argument. +1041 If you only want CFB media information for a team, +1042 regardless if they are the home/away team, +1043 set `team` to the name of the team you want CFB media information from. +1044 +1045 `conference_abv` (str, optional): +1046 Optional argument. +1047 If you only want media information from games +1048 involving teams a specific confrence, +1049 set `conference_abv` to the abbreviation +1050 of the conference you want game information from. +1051 +1052 `media_type` (str, semi-optional): +1053 Semi-optional argument. +1054 If you only want game broadcast information for a specific type of broadcast, +1055 set this to the type of broadcast. +1056 +1057 Valid inputs are: +1058 - `all` (default): Returns all games, and all known broadcasters for those games. +1059 - `tv`: Returns all known TV broadcasters for CFB games in the requested timeframe. +1060 - `radio`: Returns all known radio broadcasters +1061 for CFB games in the requested timeframe. +1062 - `web`: Returns all known web broadcasts (like ESPN+) +1063 for CFB games in the requested timeframe. +1064 - `ppv`: Returns all known Pay Per View (PPV) broadcasts +1065 for CFB games in the requested timeframe. +1066 - `mobile`: Returns all known broadcasters that only broadcasted +1067 games on mobile devices (?) +1068 +1069 `ncaa_division` (str, semi-optional): +1070 Semi-optional argument. +1071 By default, `ncaa_division` will be set to "fbs", +1072 short for the Football Bowl Subdivision (FBS), +1073 formerly known as D1-A (read as "division one single A"), +1074 the highest level in the NCAA football pyramid, +1075 where teams can scolarship up to 85 players +1076 on their football team soley for athletic ability, +1077 and often have the largest athletics budgets +1078 within the NCAA. +1079 +1080 Other valid inputs are: +1081 - "fcs": Football Championship Subdivision (FCS), +1082 formerly known as D1-AA (read as "division one double A"). +1083 An FCS school is still in the 1st division of the NCAA, +1084 making them elligable for the March Madness tournament, +1085 but may not have the resources to compete at the FBS level +1086 at this time. FCS schools are limited to 63 athletic scolarships +1087 for football. +1088 - "ii": NCAA Division II. Schools in this and D3 are not +1089 elligable for the March Madness tournament, +1090 and are limited to 36 athletic scolarships for their football team. +1091 - "iii": NCAA Division III. The largest single division within the +1092 NCAA football pyramid. +1093 D3 schools have the distinction of being part of +1094 the only NCAA division that cannot give out scolarships soley +1095 for athletic ability. +1096 +1097 `return_as_dict` (bool, semi-optional): +1098 Semi-optional argument. +1099 If you want this function to return the data as a dictionary (read: JSON object), +1100 instead of a pandas `DataFrame` object, +1101 set `return_as_dict` to `True`. +1102 +1103 Usage +1104 ---------- +1105 ``` +1106 import time +1107 +1108 from cfbd_json_py.games import get_cfbd_game_media_info +1109 1110 -1111 -1112 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -1113 -1114 if cfbd_key != "tigersAreAwsome": -1115 print("Using the user's API key declared in this script for this example.") -1116 -1117 # Get a media information for the 2020 CFB season. -1118 print("Get a media information for the 2020 CFB season.") -1119 json_data = get_cfbd_game_media_info( -1120 api_key=cfbd_key, -1121 season=2020 -1122 ) -1123 print(json_data) -1124 time.sleep(5) -1125 -1126 # Get a media information for postseason games in the 2020 CFB season. -1127 print("Get a media information for the 2020 CFB season.") -1128 json_data = get_cfbd_game_media_info( -1129 api_key=cfbd_key, -1130 season=2020, -1131 season_type="postseason" -1132 ) -1133 print(json_data) -1134 time.sleep(5) -1135 -1136 # Get a media information for week 10 games in the 2020 CFB season. -1137 print("Get a media information for week 10 games in the 2020 CFB season.") -1138 json_data = get_cfbd_game_media_info( -1139 api_key=cfbd_key, -1140 season=2020, -1141 week=10 -1142 ) -1143 print(json_data) -1144 time.sleep(5) -1145 -1146 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. -1147 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") -1148 json_data = get_cfbd_game_media_info( -1149 api_key=cfbd_key, -1150 season=2020, -1151 team="Ohio State" -1152 ) -1153 print(json_data) -1154 time.sleep(5) -1155 -1156 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. -1157 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") -1158 json_data = get_cfbd_game_media_info( -1159 api_key=cfbd_key, -1160 season=2020, -1161 conference_abv="AAC" -1162 ) -1163 print(json_data) -1164 time.sleep(5) -1165 -1166 # Get all known radio broadcasters for games in the the 2020 CFB season. -1167 print("Get all known radio broadcasters for games in the the 2020 CFB season.") -1168 json_data = get_cfbd_game_media_info( -1169 api_key=cfbd_key, -1170 season=2020, -1171 media_type="radio" -1172 ) -1173 print(json_data) -1174 time.sleep(5) -1175 -1176 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. -1177 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") -1178 json_data = get_cfbd_game_media_info( -1179 api_key=cfbd_key, -1180 season=2020, -1181 ncaa_division="fcs" -1182 ) -1183 print(json_data) -1184 time.sleep(5) -1185 -1186 # You can also tell this function to just return the API call as -1187 # a Dictionary (read: JSON) object. -1188 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1189 json_data = get_cfbd_game_media_info( -1190 season=2020, -1191 api_key=cfbd_key, -1192 return_as_dict=True -1193 ) -1194 print(json_data) -1195 -1196 else: -1197 # Alternatively, if the CFBD API key exists in this python environment, -1198 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -1199 # you could just call these functions directly, without setting the API key -1200 # in the script. -1201 print("Using the user's API key suposedly loaded into this python environment for this example.") -1202 -1203 # Get a media information for the 2020 CFB season. -1204 print("Get a media information for the 2020 CFB season.") -1205 json_data = get_cfbd_game_media_info( -1206 season=2020 -1207 ) -1208 print(json_data) -1209 time.sleep(5) -1210 -1211 # Get a media information for postseason games in the 2020 CFB season. -1212 print("Get a media information for the 2020 CFB season.") -1213 json_data = get_cfbd_game_media_info( -1214 season=2020, -1215 season_type="postseason" -1216 ) -1217 print(json_data) -1218 time.sleep(5) -1219 -1220 # Get a media information for week 10 games in the 2020 CFB season. -1221 print("Get a media information for week 10 games in the 2020 CFB season.") -1222 json_data = get_cfbd_game_media_info( -1223 season=2020, -1224 week=10 -1225 ) -1226 print(json_data) -1227 time.sleep(5) -1228 -1229 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. -1230 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") -1231 json_data = get_cfbd_game_media_info( -1232 season=2020, -1233 team="Ohio State" -1234 ) -1235 print(json_data) -1236 time.sleep(5) -1237 -1238 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. -1239 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") -1240 json_data = get_cfbd_game_media_info( -1241 season=2020, -1242 conference_abv="AAC" -1243 ) -1244 print(json_data) -1245 time.sleep(5) -1246 -1247 # Get all known radio broadcasters for games in the the 2020 CFB season. -1248 print("Get all known radio broadcasters for games in the the 2020 CFB season.") -1249 json_data = get_cfbd_game_media_info( -1250 season=2020, -1251 media_type="radio" -1252 ) -1253 print(json_data) -1254 time.sleep(5) -1255 -1256 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. -1257 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") -1258 json_data = get_cfbd_game_media_info( -1259 season=2020, -1260 ncaa_division="fcs" -1261 ) -1262 print(json_data) -1263 time.sleep(5) +1111 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1112 +1113 if cfbd_key != "tigersAreAwsome": +1114 print("Using the user's API key declared in this script for this example.") +1115 +1116 # Get a media information for the 2020 CFB season. +1117 print("Get a media information for the 2020 CFB season.") +1118 json_data = get_cfbd_game_media_info( +1119 api_key=cfbd_key, +1120 season=2020 +1121 ) +1122 print(json_data) +1123 time.sleep(5) +1124 +1125 # Get a media information for postseason games in the 2020 CFB season. +1126 print("Get a media information for the 2020 CFB season.") +1127 json_data = get_cfbd_game_media_info( +1128 api_key=cfbd_key, +1129 season=2020, +1130 season_type="postseason" +1131 ) +1132 print(json_data) +1133 time.sleep(5) +1134 +1135 # Get a media information for week 10 games in the 2020 CFB season. +1136 print("Get a media information for week 10 games in the 2020 CFB season.") +1137 json_data = get_cfbd_game_media_info( +1138 api_key=cfbd_key, +1139 season=2020, +1140 week=10 +1141 ) +1142 print(json_data) +1143 time.sleep(5) +1144 +1145 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. +1146 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") +1147 json_data = get_cfbd_game_media_info( +1148 api_key=cfbd_key, +1149 season=2020, +1150 team="Ohio State" +1151 ) +1152 print(json_data) +1153 time.sleep(5) +1154 +1155 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. +1156 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") +1157 json_data = get_cfbd_game_media_info( +1158 api_key=cfbd_key, +1159 season=2020, +1160 conference_abv="AAC" +1161 ) +1162 print(json_data) +1163 time.sleep(5) +1164 +1165 # Get all known radio broadcasters for games in the the 2020 CFB season. +1166 print("Get all known radio broadcasters for games in the the 2020 CFB season.") +1167 json_data = get_cfbd_game_media_info( +1168 api_key=cfbd_key, +1169 season=2020, +1170 media_type="radio" +1171 ) +1172 print(json_data) +1173 time.sleep(5) +1174 +1175 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. +1176 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") +1177 json_data = get_cfbd_game_media_info( +1178 api_key=cfbd_key, +1179 season=2020, +1180 ncaa_division="fcs" +1181 ) +1182 print(json_data) +1183 time.sleep(5) +1184 +1185 # You can also tell this function to just return the API call as +1186 # a Dictionary (read: JSON) object. +1187 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1188 json_data = get_cfbd_game_media_info( +1189 season=2020, +1190 api_key=cfbd_key, +1191 return_as_dict=True +1192 ) +1193 print(json_data) +1194 +1195 else: +1196 # Alternatively, if the CFBD API key exists in this python environment, +1197 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1198 # you could just call these functions directly, without setting the API key +1199 # in the script. +1200 print("Using the user's API key suposedly loaded into this python environment for this example.") +1201 +1202 # Get a media information for the 2020 CFB season. +1203 print("Get a media information for the 2020 CFB season.") +1204 json_data = get_cfbd_game_media_info( +1205 season=2020 +1206 ) +1207 print(json_data) +1208 time.sleep(5) +1209 +1210 # Get a media information for postseason games in the 2020 CFB season. +1211 print("Get a media information for the 2020 CFB season.") +1212 json_data = get_cfbd_game_media_info( +1213 season=2020, +1214 season_type="postseason" +1215 ) +1216 print(json_data) +1217 time.sleep(5) +1218 +1219 # Get a media information for week 10 games in the 2020 CFB season. +1220 print("Get a media information for week 10 games in the 2020 CFB season.") +1221 json_data = get_cfbd_game_media_info( +1222 season=2020, +1223 week=10 +1224 ) +1225 print(json_data) +1226 time.sleep(5) +1227 +1228 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. +1229 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") +1230 json_data = get_cfbd_game_media_info( +1231 season=2020, +1232 team="Ohio State" +1233 ) +1234 print(json_data) +1235 time.sleep(5) +1236 +1237 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. +1238 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") +1239 json_data = get_cfbd_game_media_info( +1240 season=2020, +1241 conference_abv="AAC" +1242 ) +1243 print(json_data) +1244 time.sleep(5) +1245 +1246 # Get all known radio broadcasters for games in the the 2020 CFB season. +1247 print("Get all known radio broadcasters for games in the the 2020 CFB season.") +1248 json_data = get_cfbd_game_media_info( +1249 season=2020, +1250 media_type="radio" +1251 ) +1252 print(json_data) +1253 time.sleep(5) +1254 +1255 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. +1256 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") +1257 json_data = get_cfbd_game_media_info( +1258 season=2020, +1259 ncaa_division="fcs" +1260 ) +1261 print(json_data) +1262 time.sleep(5) +1263 1264 -1265 -1266 # You can also tell this function to just return the API call as -1267 # a Dictionary (read: JSON) object. -1268 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1269 json_data = get_cfbd_game_media_info( -1270 season=2020, -1271 return_as_dict=True -1272 ) -1273 print(json_data) -1274 -1275 ``` -1276 Returns -1277 ---------- -1278 A pandas `DataFrame` object with college football media information, -1279 or (if `return_as_dict` is set to `True`) -1280 a dictionary object with college football media information. -1281 -1282 """ -1283 -1284 now = datetime.now() -1285 cfb_games_df = pd.DataFrame() -1286 row_df = pd.DataFrame() -1287 url = "https://api.collegefootballdata.com/games/media" -1288 -1289 ######################################################################################################################################################################################################## -1290 -1291 if api_key != None: -1292 real_api_key = api_key -1293 del api_key -1294 else: -1295 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -1296 -1297 if real_api_key == "tigersAreAwsome": -1298 raise ValueError( -1299 "You actually need to change `cfbd_key` to your CFBD API key.") -1300 elif "Bearer " in real_api_key: -1301 pass -1302 elif "Bearer" in real_api_key: -1303 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -1304 else: -1305 real_api_key = "Bearer " + real_api_key -1306 -1307 if season == None: -1308 # This should never happen without user tampering, but if it does, -1309 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -1310 raise SystemError( -1311 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + -1312 " and the function got to this point in the code." + -1313 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + -1314 "https://github.com/armstjc/cfbd-json-py/issues" -1315 ) -1316 elif season > now.year: -1317 raise ValueError(f"`season` cannot be greater than {season}.") -1318 elif season < 1869: -1319 raise ValueError(f"`season` cannot be less than 1869.") -1320 -1321 if season_type != "both" and season_type != "regular" and season_type != "postseason": -1322 raise ValueError( -1323 "`season_type` must be set to \"both\", \"regular\", or \"postseason\" for this function to work.") -1324 -1325 if media_type != "all" and media_type != "tv" and media_type != "radio" and media_type != "web" and media_type != "ppv" and media_type != "mobile": -1326 raise ValueError( -1327 "`media_type` must be set to one of the following values for this function to work:" + -1328 "\n\t- `all`" + -1329 "\n\t- `tv`" + -1330 "\n\t- `radio`" + -1331 "\n\t- `web`" + -1332 "\n\t- `ppv`" + -1333 "\n\t- `mobile`" -1334 ) -1335 -1336 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ -1337 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": -1338 pass -1339 else: -1340 raise ValueError( -1341 "An invalid NCAA Division was inputted when calling this function." + -1342 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + -1343 f"\n\nYou entered: \n{ncaa_division}" -1344 ) -1345 -1346 # URL builder -1347 ######################################################################################################################################################################################################## -1348 -1349 # Required by API -1350 url += f"?year={season}" -1351 -1352 if week != None: -1353 url += f"&week={week}" -1354 -1355 if team != None: -1356 url += f"&team={team}" -1357 -1358 if conference_abv != None: -1359 url += f"&conference={conference_abv}" -1360 -1361 if season_type != None: -1362 url += f"&seasonType={season_type}" -1363 -1364 if media_type == "all": -1365 # If we don't care about what media type we want back, -1366 # we don't need to add anything to the URL. -1367 pass -1368 elif media_type != None: -1369 url += f"&mediaType={media_type}" -1370 -1371 if ncaa_division != None: -1372 url += f"&classification={ncaa_division}" -1373 -1374 headers = { -1375 'Authorization': f'{real_api_key}', -1376 'accept': 'application/json' -1377 } -1378 -1379 response = requests.get(url, headers=headers) -1380 time.sleep(0.1) -1381 -1382 if response.status_code == 200: -1383 pass -1384 elif response.status_code == 401: -1385 raise ConnectionRefusedError( -1386 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -1387 ) -1388 else: -1389 raise ConnectionError( -1390 f'Could not connect.\nHTTP Status code {response.status_code}' -1391 ) -1392 -1393 json_data = response.json() -1394 -1395 if return_as_dict == True: -1396 return json_data -1397 -1398 for game in tqdm(json_data): -1399 row_df = pd.DataFrame( -1400 {"season": season}, -1401 index=[0] -1402 ) -1403 row_df['week'] = game['week'] -1404 row_df['game_id'] = game['id'] -1405 row_df['season_type'] = game['seasonType'] -1406 row_df['game_start_time'] = game['startTime'] -1407 row_df['is_start_time_tbd'] = game['isStartTimeTBD'] -1408 row_df['home_team'] = game['homeTeam'] -1409 row_df['home_conference'] = game['homeConference'] -1410 row_df['away_team'] = game['awayTeam'] -1411 row_df['away_conference'] = game['awayConference'] -1412 row_df['media_type'] = game['mediaType'] -1413 row_df['outlet'] = game['outlet'] -1414 -1415 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) -1416 del row_df -1417 -1418 return cfb_games_df +1265 # You can also tell this function to just return the API call as +1266 # a Dictionary (read: JSON) object. +1267 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1268 json_data = get_cfbd_game_media_info( +1269 season=2020, +1270 return_as_dict=True +1271 ) +1272 print(json_data) +1273 +1274 ``` +1275 Returns +1276 ---------- +1277 A pandas `DataFrame` object with college football media information, +1278 or (if `return_as_dict` is set to `True`) +1279 a dictionary object with college football media information. +1280 +1281 """ +1282 +1283 now = datetime.now() +1284 cfb_games_df = pd.DataFrame() +1285 row_df = pd.DataFrame() +1286 url = "https://api.collegefootballdata.com/games/media" +1287 +1288 ######################################################################################################################################################################################################## +1289 +1290 if api_key != None: +1291 real_api_key = api_key +1292 del api_key +1293 else: +1294 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1295 +1296 if real_api_key == "tigersAreAwsome": +1297 raise ValueError( +1298 "You actually need to change `cfbd_key` to your CFBD API key.") +1299 elif "Bearer " in real_api_key: +1300 pass +1301 elif "Bearer" in real_api_key: +1302 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1303 else: +1304 real_api_key = "Bearer " + real_api_key +1305 +1306 if season == None: +1307 # This should never happen without user tampering, but if it does, +1308 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +1309 raise SystemError( +1310 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +1311 " and the function got to this point in the code." + +1312 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +1313 "https://github.com/armstjc/cfbd-json-py/issues" +1314 ) +1315 elif season > now.year: +1316 raise ValueError(f"`season` cannot be greater than {season}.") +1317 elif season < 1869: +1318 raise ValueError(f"`season` cannot be less than 1869.") +1319 +1320 if season_type != "both" and season_type != "regular" and season_type != "postseason": +1321 raise ValueError( +1322 "`season_type` must be set to \"both\", \"regular\", or \"postseason\" for this function to work.") +1323 +1324 if media_type != "all" and media_type != "tv" and media_type != "radio" and media_type != "web" and media_type != "ppv" and media_type != "mobile": +1325 raise ValueError( +1326 "`media_type` must be set to one of the following values for this function to work:" + +1327 "\n\t- `all`" + +1328 "\n\t- `tv`" + +1329 "\n\t- `radio`" + +1330 "\n\t- `web`" + +1331 "\n\t- `ppv`" + +1332 "\n\t- `mobile`" +1333 ) +1334 +1335 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ +1336 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": +1337 pass +1338 else: +1339 raise ValueError( +1340 "An invalid NCAA Division was inputted when calling this function." + +1341 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + +1342 f"\n\nYou entered: \n{ncaa_division}" +1343 ) +1344 +1345 # URL builder +1346 ######################################################################################################################################################################################################## +1347 +1348 # Required by API +1349 url += f"?year={season}" +1350 +1351 if week != None: +1352 url += f"&week={week}" +1353 +1354 if team != None: +1355 url += f"&team={team}" +1356 +1357 if conference_abv != None: +1358 url += f"&conference={conference_abv}" +1359 +1360 if season_type != None: +1361 url += f"&seasonType={season_type}" +1362 +1363 if media_type == "all": +1364 # If we don't care about what media type we want back, +1365 # we don't need to add anything to the URL. +1366 pass +1367 elif media_type != None: +1368 url += f"&mediaType={media_type}" +1369 +1370 if ncaa_division != None: +1371 url += f"&classification={ncaa_division}" +1372 +1373 headers = { +1374 'Authorization': f'{real_api_key}', +1375 'accept': 'application/json' +1376 } +1377 +1378 response = requests.get(url, headers=headers) +1379 +1380 +1381 if response.status_code == 200: +1382 pass +1383 elif response.status_code == 401: +1384 raise ConnectionRefusedError( +1385 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1386 ) +1387 else: +1388 raise ConnectionError( +1389 f'Could not connect.\nHTTP Status code {response.status_code}' +1390 ) +1391 +1392 json_data = response.json() +1393 +1394 if return_as_dict == True: +1395 return json_data +1396 +1397 for game in tqdm(json_data): +1398 row_df = pd.DataFrame( +1399 {"season": season}, +1400 index=[0] +1401 ) +1402 row_df['week'] = game['week'] +1403 row_df['game_id'] = game['id'] +1404 row_df['season_type'] = game['seasonType'] +1405 row_df['game_start_time'] = game['startTime'] +1406 row_df['is_start_time_tbd'] = game['isStartTimeTBD'] +1407 row_df['home_team'] = game['homeTeam'] +1408 row_df['home_conference'] = game['homeConference'] +1409 row_df['away_team'] = game['awayTeam'] +1410 row_df['away_conference'] = game['awayConference'] +1411 row_df['media_type'] = game['mediaType'] +1412 row_df['outlet'] = game['outlet'] +1413 +1414 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +1415 del row_df +1416 +1417 return cfb_games_df +1418 1419 -1420 -1421def get_cfbd_player_game_stats( -1422 season: int, -1423 api_key: str = None, -1424 api_key_dir: str = None, -1425 season_type: str = "regular", # "regular" or "postseason" -1426 week: int = None, -1427 team: str = None, -1428 conference_abv: str = None, -1429 # `week`, `team`, and/or `conference` -1430 # must be not null for this function to work. -1431 stat_category: str = None, -1432 game_id: int = None, -1433 return_as_dict: bool = False): -1434 """ -1435 Retrives player game stats for a given time frame. -1436 -1437 Parameters -1438 ---------- -1439 `season` (int, mandatory): -1440 Required argument. -1441 Specifies the season you want CFB media information from. -1442 This must be specified, otherwise this package, and by extension -1443 the CFBD API, will not accept the request to get CFB media information. -1444 -1445 `api_key` (str, optional): -1446 Semi-optional argument. -1447 If `api_key` is null, this function will attempt to load a CFBD API key -1448 from the python environment, or from a file on this computer. -1449 If `api_key` is not null, this function will automatically assume that the -1450 inputted `api_key` is a valid CFBD API key. -1451 -1452 `api_key_dir` (str, optional): -1453 Optional argument. -1454 If `api_key` is set to a string non-empty string, this variable is ignored. -1455 If `api_key_dir` is null, and `api_key` is null, -1456 this function will try to find a CFBD API key file in this user's home directory. -1457 If `api_key_dir` is set to a string, and `api_key` is null, -1458 this function will assume that `api_key_dir` is a directory, -1459 and will try to find a CFBD API key file in that directory. -1460 -1461 `season_type` (str, semi-optional): -1462 Semi-optional argument. -1463 By defualt, this will be set to "regular", for the CFB regular season. -1464 If you want CFB media information for non-regular season games, -1465 set `season_type` to "postseason". -1466 If `season_type` is set to anything but "regular" or "postseason", -1467 a `ValueError()` will be raised. -1468 -1469 **For the following three variables, -1470 at least one must be set to a non-null variable when calling this function.** -1471 -1472 `week` (int, optional): -1473 Optional argument. -1474 If `week` is set to an integer, this function will attempt -1475 to load CFB media information from games in that season, and in that week. -1476 -1477 `team` (str, optional): -1478 Optional argument. -1479 If you only want CFB media information for a team, -1480 regardless if they are the home/away team, -1481 set `team` to the name of the team you want CFB media information from. -1482 -1483 `conference_abv` (str, optional): -1484 Optional argument. -1485 If you only want media information from games -1486 involving teams a specific confrence, -1487 set `conference_abv` to the abbreviation -1488 of the conference you want game information from. -1489 -1490 `stat_category` (str, optional): -1491 Optional argument. -1492 If only want stats for a specific stat category, -1493 set this variable to that category. -1494 -1495 Valid inputs are: -1496 - `passing` -1497 - `rushing` -1498 - `receiving` -1499 - `fumbles` -1500 - `defensive` -1501 - `interceptions` -1502 - `punting` -1503 - `kicking` -1504 - `kickReturns` -1505 - `puntReturns` -1506 -1507 `game_id` (int, optional): -1508 Optional argument. -1509 If `game_id` is set to a game ID, `get_cfbd_player_game_stats()` will try to get -1510 player game stats just for that game ID. -1511 -1512 `return_as_dict` (bool, semi-optional): -1513 Semi-optional argument. -1514 If you want this function to return the data as a dictionary (read: JSON object), -1515 instead of a pandas `DataFrame` object, -1516 set `return_as_dict` to `True`. -1517 -1518 Usage -1519 ---------- -1520 ``` -1521 import time -1522 -1523 from cfbd_json_py.games import get_cfbd_player_game_stats +1420def get_cfbd_player_game_stats( +1421 season: int, +1422 api_key: str = None, +1423 api_key_dir: str = None, +1424 season_type: str = "regular", # "regular" or "postseason" +1425 week: int = None, +1426 team: str = None, +1427 conference_abv: str = None, +1428 # `week`, `team`, and/or `conference` +1429 # must be not null for this function to work. +1430 stat_category: str = None, +1431 game_id: int = None, +1432 return_as_dict: bool = False): +1433 """ +1434 Retrives player game stats for a given time frame. +1435 +1436 Parameters +1437 ---------- +1438 `season` (int, mandatory): +1439 Required argument. +1440 Specifies the season you want CFB media information from. +1441 This must be specified, otherwise this package, and by extension +1442 the CFBD API, will not accept the request to get CFB media information. +1443 +1444 `api_key` (str, optional): +1445 Semi-optional argument. +1446 If `api_key` is null, this function will attempt to load a CFBD API key +1447 from the python environment, or from a file on this computer. +1448 If `api_key` is not null, this function will automatically assume that the +1449 inputted `api_key` is a valid CFBD API key. +1450 +1451 `api_key_dir` (str, optional): +1452 Optional argument. +1453 If `api_key` is set to am empty string, this variable is ignored. +1454 If `api_key_dir` is null, and `api_key` is null, +1455 this function will try to find a CFBD API key file in this user's home directory. +1456 If `api_key_dir` is set to a string, and `api_key` is null, +1457 this function will assume that `api_key_dir` is a directory, +1458 and will try to find a CFBD API key file in that directory. +1459 +1460 `season_type` (str, semi-optional): +1461 Semi-optional argument. +1462 By defualt, this will be set to "regular", for the CFB regular season. +1463 If you want CFB media information for non-regular season games, +1464 set `season_type` to "postseason". +1465 If `season_type` is set to anything but "regular" or "postseason", +1466 a `ValueError()` will be raised. +1467 +1468 **For the following three variables, +1469 at least one must be set to a non-null variable when calling this function.** +1470 +1471 `week` (int, optional): +1472 Optional argument. +1473 If `week` is set to an integer, this function will attempt +1474 to load CFB media information from games in that season, and in that week. +1475 +1476 `team` (str, optional): +1477 Optional argument. +1478 If you only want CFB media information for a team, +1479 regardless if they are the home/away team, +1480 set `team` to the name of the team you want CFB media information from. +1481 +1482 `conference_abv` (str, optional): +1483 Optional argument. +1484 If you only want media information from games +1485 involving teams a specific confrence, +1486 set `conference_abv` to the abbreviation +1487 of the conference you want game information from. +1488 +1489 `stat_category` (str, optional): +1490 Optional argument. +1491 If only want stats for a specific stat category, +1492 set this variable to that category. +1493 +1494 Valid inputs are: +1495 - `passing` +1496 - `rushing` +1497 - `receiving` +1498 - `fumbles` +1499 - `defensive` +1500 - `interceptions` +1501 - `punting` +1502 - `kicking` +1503 - `kickReturns` +1504 - `puntReturns` +1505 +1506 `game_id` (int, optional): +1507 Optional argument. +1508 If `game_id` is set to a game ID, `get_cfbd_player_game_stats()` will try to get +1509 player game stats just for that game ID. +1510 +1511 `return_as_dict` (bool, semi-optional): +1512 Semi-optional argument. +1513 If you want this function to return the data as a dictionary (read: JSON object), +1514 instead of a pandas `DataFrame` object, +1515 set `return_as_dict` to `True`. +1516 +1517 Usage +1518 ---------- +1519 ``` +1520 import time +1521 +1522 from cfbd_json_py.games import get_cfbd_player_game_stats +1523 1524 -1525 -1526 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -1527 -1528 if cfbd_key != "tigersAreAwsome": -1529 print("Using the user's API key declared in this script for this example.") -1530 -1531 # Get player game stats for week 10 of the 2020 CFB season. -1532 print("Get player game stats for week 10 of the 2020 CFB season.") -1533 json_data = get_cfbd_player_game_stats( -1534 api_key=cfbd_key, -1535 season=2020, -1536 week=10 -1537 ) -1538 print(json_data) -1539 time.sleep(5) -1540 -1541 # Get postseason player game stats for the 2020 CFB season. -1542 print("Get postseason player game stats for the 2020 CFB season.") -1543 json_data = get_cfbd_player_game_stats( -1544 api_key=cfbd_key, -1545 season=2020, -1546 season_type="postseason", -1547 week=1 -1548 ) -1549 print(json_data) -1550 time.sleep(5) -1551 -1552 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. -1553 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") -1554 json_data = get_cfbd_player_game_stats( -1555 api_key=cfbd_key, -1556 season=2018, -1557 team="Alabama" -1558 ) -1559 print(json_data) -1560 time.sleep(5) -1561 -1562 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. -1563 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") -1564 json_data = get_cfbd_player_game_stats( -1565 api_key=cfbd_key, -1566 season=2020, -1567 conference_abv="ACC" -1568 ) -1569 print(json_data) -1570 time.sleep(5) -1571 -1572 # Get get passing stats from players who played in week 7 of the 2017 CFB season. -1573 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") -1574 json_data = get_cfbd_player_game_stats( -1575 api_key=cfbd_key, -1576 season=2017, -1577 week=7, -1578 stat_category="pasing" -1579 ) -1580 print(json_data) -1581 time.sleep(5) -1582 -1583 # Get player game stats from the 2021 Virbo Citrus Bowl, -1584 # a bowl game that happened in the 2020 CFB season. -1585 print("Get player game stats from the 2021 Virbo Citrus Bowl, a bowl game that happened in the 2020 CFB season.") -1586 json_data = get_cfbd_player_game_stats( -1587 api_key=cfbd_key, -1588 season=2020, -1589 game_id=401256199 -1590 ) -1591 print(json_data) -1592 time.sleep(5) -1593 -1594 # You can also tell this function to just return the API call as -1595 # a Dictionary (read: JSON) object. -1596 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1597 json_data = get_cfbd_player_game_stats( -1598 season=2020, -1599 week=10, -1600 api_key=cfbd_key, -1601 return_as_dict=True -1602 ) -1603 print(json_data) -1604 -1605 else: -1606 # Alternatively, if the CFBD API key exists in this python environment, -1607 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -1608 # you could just call these functions directly, without setting the API key -1609 # in the script. -1610 print("Using the user's API key suposedly loaded into this python environment for this example.") -1611 -1612 # Get player game stats for week 10 of the 2020 CFB season. -1613 print("Get player game stats for week 10 of the 2020 CFB season.") -1614 json_data = get_cfbd_player_game_stats( -1615 season=2020, -1616 week=10 -1617 ) -1618 print(json_data) -1619 time.sleep(5) -1620 -1621 # Get postseason player game stats for the 2020 CFB season. -1622 print("Get postseason player game stats for the 2020 CFB season.") -1623 json_data = get_cfbd_player_game_stats( -1624 season=2020, -1625 season_type="postseason", -1626 week=1 -1627 ) -1628 print(json_data) -1629 time.sleep(5) -1630 -1631 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. -1632 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") -1633 json_data = get_cfbd_player_game_stats( -1634 season=2018, -1635 team="Alabama" -1636 ) -1637 print(json_data) -1638 time.sleep(5) -1639 -1640 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. -1641 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") -1642 json_data = get_cfbd_player_game_stats( -1643 season=2020, -1644 conference_abv="ACC" -1645 ) -1646 print(json_data) -1647 time.sleep(5) -1648 -1649 # Get get passing stats from players who played in week 7 of the 2017 CFB season. -1650 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") -1651 json_data = get_cfbd_player_game_stats( -1652 season=2017, -1653 week=7, -1654 stat_category="passing" -1655 ) -1656 print(json_data) -1657 time.sleep(5) -1658 -1659 # Get player game stats from the 2021 Virbo Citrus Bowl, -1660 # a bowl game that happened in the 2020 CFB season, -1661 # between the Aubrun Tigers, and the Northwestern Wildcats. -1662 print("Get player game stats from the 2021 Virbo Citrus Bowl, "+ -1663 "a bowl game that happened in the 2020 CFB season between the Aubrun Tigers, and the Northwestern Wildcats.") -1664 json_data = get_cfbd_player_game_stats( -1665 season=2020, -1666 game_id=401256199 -1667 ) -1668 print(json_data) -1669 time.sleep(5) +1525 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1526 +1527 if cfbd_key != "tigersAreAwsome": +1528 print("Using the user's API key declared in this script for this example.") +1529 +1530 # Get player game stats for week 10 of the 2020 CFB season. +1531 print("Get player game stats for week 10 of the 2020 CFB season.") +1532 json_data = get_cfbd_player_game_stats( +1533 api_key=cfbd_key, +1534 season=2020, +1535 week=10 +1536 ) +1537 print(json_data) +1538 time.sleep(5) +1539 +1540 # Get postseason player game stats for the 2020 CFB season. +1541 print("Get postseason player game stats for the 2020 CFB season.") +1542 json_data = get_cfbd_player_game_stats( +1543 api_key=cfbd_key, +1544 season=2020, +1545 season_type="postseason", +1546 week=1 +1547 ) +1548 print(json_data) +1549 time.sleep(5) +1550 +1551 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. +1552 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") +1553 json_data = get_cfbd_player_game_stats( +1554 api_key=cfbd_key, +1555 season=2018, +1556 team="Alabama" +1557 ) +1558 print(json_data) +1559 time.sleep(5) +1560 +1561 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. +1562 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") +1563 json_data = get_cfbd_player_game_stats( +1564 api_key=cfbd_key, +1565 season=2020, +1566 conference_abv="ACC" +1567 ) +1568 print(json_data) +1569 time.sleep(5) +1570 +1571 # Get get passing stats from players who played in week 7 of the 2017 CFB season. +1572 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") +1573 json_data = get_cfbd_player_game_stats( +1574 api_key=cfbd_key, +1575 season=2017, +1576 week=7, +1577 stat_category="pasing" +1578 ) +1579 print(json_data) +1580 time.sleep(5) +1581 +1582 # Get player game stats from the 2021 Virbo Citrus Bowl, +1583 # a bowl game that happened in the 2020 CFB season. +1584 print("Get player game stats from the 2021 Virbo Citrus Bowl, a bowl game that happened in the 2020 CFB season.") +1585 json_data = get_cfbd_player_game_stats( +1586 api_key=cfbd_key, +1587 season=2020, +1588 game_id=401256199 +1589 ) +1590 print(json_data) +1591 time.sleep(5) +1592 +1593 # You can also tell this function to just return the API call as +1594 # a Dictionary (read: JSON) object. +1595 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1596 json_data = get_cfbd_player_game_stats( +1597 season=2020, +1598 week=10, +1599 api_key=cfbd_key, +1600 return_as_dict=True +1601 ) +1602 print(json_data) +1603 +1604 else: +1605 # Alternatively, if the CFBD API key exists in this python environment, +1606 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1607 # you could just call these functions directly, without setting the API key +1608 # in the script. +1609 print("Using the user's API key suposedly loaded into this python environment for this example.") +1610 +1611 # Get player game stats for week 10 of the 2020 CFB season. +1612 print("Get player game stats for week 10 of the 2020 CFB season.") +1613 json_data = get_cfbd_player_game_stats( +1614 season=2020, +1615 week=10 +1616 ) +1617 print(json_data) +1618 time.sleep(5) +1619 +1620 # Get postseason player game stats for the 2020 CFB season. +1621 print("Get postseason player game stats for the 2020 CFB season.") +1622 json_data = get_cfbd_player_game_stats( +1623 season=2020, +1624 season_type="postseason", +1625 week=1 +1626 ) +1627 print(json_data) +1628 time.sleep(5) +1629 +1630 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. +1631 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") +1632 json_data = get_cfbd_player_game_stats( +1633 season=2018, +1634 team="Alabama" +1635 ) +1636 print(json_data) +1637 time.sleep(5) +1638 +1639 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. +1640 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") +1641 json_data = get_cfbd_player_game_stats( +1642 season=2020, +1643 conference_abv="ACC" +1644 ) +1645 print(json_data) +1646 time.sleep(5) +1647 +1648 # Get get passing stats from players who played in week 7 of the 2017 CFB season. +1649 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") +1650 json_data = get_cfbd_player_game_stats( +1651 season=2017, +1652 week=7, +1653 stat_category="passing" +1654 ) +1655 print(json_data) +1656 time.sleep(5) +1657 +1658 # Get player game stats from the 2021 Virbo Citrus Bowl, +1659 # a bowl game that happened in the 2020 CFB season, +1660 # between the Aubrun Tigers, and the Northwestern Wildcats. +1661 print("Get player game stats from the 2021 Virbo Citrus Bowl, "+ +1662 "a bowl game that happened in the 2020 CFB season between the Aubrun Tigers, and the Northwestern Wildcats.") +1663 json_data = get_cfbd_player_game_stats( +1664 season=2020, +1665 game_id=401256199 +1666 ) +1667 print(json_data) +1668 time.sleep(5) +1669 1670 -1671 -1672 # You can also tell this function to just return the API call as -1673 # a Dictionary (read: JSON) object. -1674 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1675 json_data = get_cfbd_player_game_stats( -1676 season=2020, -1677 week=10, -1678 return_as_dict=True -1679 ) -1680 print(json_data) -1681 -1682 ``` -1683 Returns -1684 ---------- -1685 A pandas `DataFrame` object with player game stats data, -1686 or (if `return_as_dict` is set to `True`) -1687 a dictionary object with player game stats data. -1688 -1689 """ -1690 -1691 rebuilt_json = {} -1692 now = datetime.now() -1693 cfb_games_df = pd.DataFrame() -1694 row_df = pd.DataFrame() -1695 url = "https://api.collegefootballdata.com/games/players" -1696 stat_columns = [ -1697 'game_id', -1698 'team_name', -1699 'team_confrence', -1700 'player_id', -1701 'player_name', -1702 'home_away', -1703 # PASS -1704 'passing_C/ATT', -1705 'passing_COMP', -1706 'passing_ATT', -1707 'passing_YDS', -1708 'passing_AVG', -1709 'passing_TD', -1710 'passing_INT', -1711 'passing_QBR', -1712 # RUSH -1713 'rushing_CAR', -1714 'rushing_YDS', -1715 'rushing_AVG', -1716 'rushing_TD', -1717 'rushing_LONG', -1718 # REC -1719 'receiving_REC', -1720 'receiving_YDS', -1721 'receiving_AVG', -1722 'receiving_TD', -1723 'receiving_LONG', -1724 # FUM -1725 'fumbles_FUM', -1726 'fumbles_LOST', -1727 'fumbles_REC', -1728 # DEFENSE -1729 'defensive_TOT', -1730 'defensive_SOLO', -1731 'defensive_TFL', -1732 'defensive_QB HUR', -1733 'defensive_SACKS', -1734 'defensive_PD', -1735 'defensive_TD', -1736 # INT -1737 'interceptions_INT', -1738 'interceptions_YDS', -1739 'interceptions_TD', -1740 # PUNT -1741 'punting_NO', -1742 'punting_YDS', -1743 'punting_AVG', -1744 'punting_TB', -1745 'punting_In 20', -1746 'punting_LONG', -1747 # KICK -1748 'kicking_FG', -1749 'kicking_FGM', -1750 'kicking_FGA', -1751 'kicking_PCT', -1752 'kicking_LONG', -1753 'kicking_XP', -1754 'kicking_XPM', -1755 'kicking_XPA', -1756 'kicking_PTS', -1757 # KR -1758 'kickReturns_NO', -1759 'kickReturns_YDS', -1760 'kickReturns_AVG', -1761 'kickReturns_TD', -1762 'kickReturns_LONG', -1763 # PR -1764 'puntReturns_NO', -1765 'puntReturns_YDS', -1766 'puntReturns_AVG', -1767 'puntReturns_TD', -1768 'puntReturns_LONG' -1769 ] -1770 -1771 ######################################################################################################################################################################################################## -1772 -1773 if api_key != None: -1774 real_api_key = api_key -1775 del api_key -1776 else: -1777 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -1778 -1779 if real_api_key == "tigersAreAwsome": -1780 raise ValueError( -1781 "You actually need to change `cfbd_key` to your CFBD API key.") -1782 elif "Bearer " in real_api_key: -1783 pass -1784 elif "Bearer" in real_api_key: -1785 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -1786 else: -1787 real_api_key = "Bearer " + real_api_key -1788 -1789 if season == None: -1790 # This should never happen without user tampering, but if it does, -1791 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -1792 raise SystemError( -1793 "I don't know how, I don't know why, " + -1794 "but you managed to call this function while `season` was `None` (NULL)," + -1795 " and the function got to this point in the code." + -1796 "\nIf you have a GitHub account, " + -1797 "please raise an issue on this python package's GitHub page:\n" + -1798 "https://github.com/armstjc/cfbd-json-py/issues" -1799 ) -1800 elif season > now.year: -1801 raise ValueError(f"`season` cannot be greater than {season}.") -1802 elif season < 1869: -1803 raise ValueError(f"`season` cannot be less than 1869.") -1804 -1805 if season_type != "regular" and season_type != "postseason": -1806 raise ValueError( -1807 "`season_type` must be set to either \"regular\" or " + -1808 "\"postseason\" for this function to work." -1809 ) -1810 -1811 # `week`, `team`, and/or `conference` -1812 # must be not null for this function to work. -1813 -1814 if week == None and team == None and conference_abv == None and game_id == None: -1815 raise ValueError( -1816 "To use `get_cfbd_player_game_stats()`," + -1817 " `week`, `team`, and/or `conference_abv` need to be set to a non-null value." -1818 ) -1819 -1820 filter_by_stat_category = False -1821 -1822 if stat_category == None: -1823 pass -1824 elif stat_category == "passing": -1825 filter_by_stat_category = True -1826 elif stat_category == "rushing": -1827 filter_by_stat_category = True -1828 elif stat_category == "receiving": -1829 filter_by_stat_category = True -1830 elif stat_category == "fumbles": -1831 filter_by_stat_category = True -1832 elif stat_category == "passing": -1833 filter_by_stat_category = True -1834 elif stat_category == "defensive": -1835 filter_by_stat_category = True -1836 elif stat_category == "interceptions": -1837 filter_by_stat_category = True -1838 elif stat_category == "punting": -1839 filter_by_stat_category = True -1840 elif stat_category == "kicking": -1841 filter_by_stat_category = True -1842 elif stat_category == "kickReturns": -1843 filter_by_stat_category = True -1844 elif stat_category == "puntReturns": -1845 filter_by_stat_category = True -1846 else: -1847 raise ValueError( -1848 "Invalid input for `stat_category`." + -1849 "\nValid inputs are:" + -1850 """ -1851 - `passing` -1852 - `rushing` -1853 - `receiving` -1854 - `fumbles` -1855 - `defensive` -1856 - `interceptions` -1857 - `punting` -1858 - `kicking` -1859 - `kickReturns` -1860 - `puntReturns` -1861 """ -1862 ) -1863 -1864 # URL builder -1865 ######################################################################################################################################################################################################## -1866 -1867 # Required by the API -1868 url += f"?year={season}" -1869 -1870 if game_id != None: -1871 url += f"&gameId={game_id}" -1872 -1873 if stat_category != None: -1874 url += f"&category={stat_category}" -1875 -1876 if week != None or team != None or conference_abv != None: -1877 logging.warning( -1878 "When calling `cfbd_json_py.games.get_cfbd_player_game_stats()`, " + -1879 "and setting `game_id` to a non-null value, " + -1880 "only `season`, `stat_category`, and `game_id` are considered " + -1881 "when calling the CFBD API." -1882 ) -1883 else: -1884 if season_type != None: -1885 url += f"&seasonType={season_type}" -1886 -1887 if week != None: -1888 url += f"&week={week}" -1889 -1890 if team != None: -1891 url += f"&team={team}" -1892 -1893 if conference_abv != None: -1894 url += f"&conference={conference_abv}" -1895 -1896 headers = { -1897 'Authorization': f'{real_api_key}', -1898 'accept': 'application/json' -1899 } -1900 -1901 response = requests.get(url, headers=headers) -1902 time.sleep(0.1) -1903 -1904 if response.status_code == 200: -1905 pass -1906 elif response.status_code == 401: -1907 raise ConnectionRefusedError( -1908 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -1909 ) -1910 else: -1911 raise ConnectionError( -1912 f'Could not connect.\nHTTP Status code {response.status_code}' -1913 ) -1914 -1915 json_data = response.json() -1916 -1917 if return_as_dict == True: -1918 return json_data -1919 -1920 for game in tqdm(json_data): -1921 game_id = game['id'] -1922 -1923 for team in game['teams']: -1924 team_name = team['school'] -1925 team_confrence = team['conference'] -1926 home_away = team['homeAway'] -1927 -1928 for s_category in team['categories']: -1929 if s_category['name'] == "passing": -1930 for stat in s_category['types']: -1931 -1932 if stat['name'] == "C/ATT": # passing_C/ATT -1933 -1934 for i in stat['athletes']: -1935 player_id = int(i['id']) -1936 player_name = i['name'] -1937 player_stat = i['stat'] -1938 -1939 if rebuilt_json.get(player_id) == None: -1940 rebuilt_json[player_id] = {} -1941 -1942 rebuilt_json[player_id]['game_id'] = game_id -1943 rebuilt_json[player_id]['team_name'] = team_name -1944 rebuilt_json[player_id]['team_confrence'] = team_confrence -1945 rebuilt_json[player_id]['player_id'] = player_id -1946 rebuilt_json[player_id]['player_name'] = player_name -1947 rebuilt_json[player_id]['home_away'] = home_away -1948 rebuilt_json[player_id]['passing_C/ATT'] = player_stat -1949 -1950 elif stat['name'] == "YDS": # passing_YDS -1951 -1952 for i in stat['athletes']: -1953 player_id = int(i['id']) -1954 player_name = i['name'] -1955 player_stat = int(i['stat']) -1956 -1957 if rebuilt_json.get(player_id) == None: -1958 rebuilt_json[player_id] = {} -1959 -1960 rebuilt_json[player_id]['game_id'] = game_id -1961 rebuilt_json[player_id]['team_name'] = team_name -1962 rebuilt_json[player_id]['team_confrence'] = team_confrence -1963 rebuilt_json[player_id]['player_id'] = player_id -1964 rebuilt_json[player_id]['player_name'] = player_name -1965 rebuilt_json[player_id]['home_away'] = home_away -1966 rebuilt_json[player_id]['passing_YDS'] = player_stat -1967 -1968 elif stat['name'] == "AVG": # passing_AVG -1969 for i in stat['athletes']: -1970 player_id = int(i['id']) -1971 player_name = i['name'] -1972 player_stat = float(i['stat']) -1973 -1974 if rebuilt_json.get(player_id) == None: -1975 rebuilt_json[player_id] = {} -1976 -1977 rebuilt_json[player_id]['game_id'] = game_id -1978 rebuilt_json[player_id]['team_name'] = team_name -1979 rebuilt_json[player_id]['team_confrence'] = team_confrence -1980 rebuilt_json[player_id]['player_id'] = player_id -1981 rebuilt_json[player_id]['player_name'] = player_name -1982 rebuilt_json[player_id]['home_away'] = home_away -1983 rebuilt_json[player_id]['passing_AVG'] = player_stat -1984 -1985 elif stat['name'] == "TD": # passing_TD -1986 -1987 for i in stat['athletes']: -1988 player_id = int(i['id']) -1989 player_name = i['name'] -1990 player_stat = int(i['stat']) -1991 -1992 if rebuilt_json.get(player_id) == None: -1993 rebuilt_json[player_id] = {} -1994 -1995 rebuilt_json[player_id]['game_id'] = game_id -1996 rebuilt_json[player_id]['team_name'] = team_name -1997 rebuilt_json[player_id]['team_confrence'] = team_confrence -1998 rebuilt_json[player_id]['player_id'] = player_id -1999 rebuilt_json[player_id]['player_name'] = player_name -2000 rebuilt_json[player_id]['home_away'] = home_away -2001 rebuilt_json[player_id]['passing_TD'] = player_stat -2002 -2003 elif stat['name'] == "INT": # passing_INT -2004 -2005 for i in stat['athletes']: -2006 player_id = int(i['id']) -2007 player_name = i['name'] -2008 player_stat = int(i['stat']) -2009 -2010 if rebuilt_json.get(player_id) == None: -2011 rebuilt_json[player_id] = {} -2012 -2013 rebuilt_json[player_id]['game_id'] = game_id -2014 rebuilt_json[player_id]['team_name'] = team_name -2015 rebuilt_json[player_id]['team_confrence'] = team_confrence -2016 rebuilt_json[player_id]['player_id'] = player_id -2017 rebuilt_json[player_id]['player_name'] = player_name -2018 rebuilt_json[player_id]['home_away'] = home_away -2019 rebuilt_json[player_id]['passing_INT'] = player_stat -2020 -2021 elif stat['name'] == "QBR": # passing_QBR -2022 for i in stat['athletes']: -2023 player_id = int(i['id']) -2024 player_name = i['name'] -2025 try: -2026 player_stat = float(i['stat']) -2027 except: -2028 player_stat = None -2029 -2030 if rebuilt_json.get(player_id) == None: -2031 rebuilt_json[player_id] = {} -2032 -2033 rebuilt_json[player_id]['game_id'] = game_id -2034 rebuilt_json[player_id]['team_name'] = team_name -2035 rebuilt_json[player_id]['team_confrence'] = team_confrence -2036 rebuilt_json[player_id]['player_id'] = player_id -2037 rebuilt_json[player_id]['player_name'] = player_name -2038 rebuilt_json[player_id]['home_away'] = home_away -2039 rebuilt_json[player_id]['passing_QBR'] = player_stat -2040 -2041 else: -2042 raise IndexError( -2043 f"Unhandled stat: \t{stat['name']}") -2044 # passing_df = pd.DataFrame(s_category['types']) -2045 elif s_category['name'] == "rushing": -2046 for stat in s_category['types']: -2047 if stat['name'] == "CAR": # rushing_CAR -2048 for i in stat['athletes']: -2049 player_id = int(i['id']) -2050 player_name = i['name'] -2051 player_stat = int(i['stat']) -2052 -2053 if rebuilt_json.get(player_id) == None: -2054 rebuilt_json[player_id] = {} -2055 -2056 rebuilt_json[player_id]['game_id'] = game_id -2057 rebuilt_json[player_id]['team_name'] = team_name -2058 rebuilt_json[player_id]['team_confrence'] = team_confrence -2059 rebuilt_json[player_id]['player_id'] = player_id -2060 rebuilt_json[player_id]['player_name'] = player_name -2061 rebuilt_json[player_id]['home_away'] = home_away -2062 rebuilt_json[player_id]['rushing_CAR'] = player_stat -2063 -2064 elif stat['name'] == "YDS": # rushing_YDS -2065 for i in stat['athletes']: -2066 player_id = int(i['id']) -2067 player_name = i['name'] -2068 player_stat = int(i['stat']) -2069 -2070 if rebuilt_json.get(player_id) == None: -2071 rebuilt_json[player_id] = {} -2072 -2073 rebuilt_json[player_id]['game_id'] = game_id -2074 rebuilt_json[player_id]['team_name'] = team_name -2075 rebuilt_json[player_id]['team_confrence'] = team_confrence -2076 rebuilt_json[player_id]['player_id'] = player_id -2077 rebuilt_json[player_id]['player_name'] = player_name -2078 rebuilt_json[player_id]['home_away'] = home_away -2079 rebuilt_json[player_id]['rushing_YDS'] = player_stat -2080 -2081 elif stat['name'] == "AVG": # rushing_AVG -2082 for i in stat['athletes']: -2083 player_id = int(i['id']) -2084 player_name = i['name'] -2085 player_stat = float(i['stat']) -2086 -2087 if rebuilt_json.get(player_id) == None: -2088 rebuilt_json[player_id] = {} -2089 -2090 rebuilt_json[player_id]['game_id'] = game_id -2091 rebuilt_json[player_id]['team_name'] = team_name -2092 rebuilt_json[player_id]['team_confrence'] = team_confrence -2093 rebuilt_json[player_id]['player_id'] = player_id -2094 rebuilt_json[player_id]['player_name'] = player_name -2095 rebuilt_json[player_id]['home_away'] = home_away -2096 rebuilt_json[player_id]['rushing_AVG'] = player_stat -2097 -2098 elif stat['name'] == "TD": # rushing_TD -2099 for i in stat['athletes']: -2100 player_id = int(i['id']) -2101 player_name = i['name'] -2102 player_stat = int(i['stat']) -2103 -2104 if rebuilt_json.get(player_id) == None: -2105 rebuilt_json[player_id] = {} -2106 -2107 rebuilt_json[player_id]['game_id'] = game_id -2108 rebuilt_json[player_id]['team_name'] = team_name -2109 rebuilt_json[player_id]['team_confrence'] = team_confrence -2110 rebuilt_json[player_id]['player_id'] = player_id -2111 rebuilt_json[player_id]['player_name'] = player_name -2112 rebuilt_json[player_id]['home_away'] = home_away -2113 rebuilt_json[player_id]['rushing_TD'] = player_stat -2114 -2115 elif stat['name'] == "LONG": # rushing_LONG -2116 for i in stat['athletes']: -2117 player_id = int(i['id']) -2118 player_name = i['name'] -2119 player_stat = int(i['stat']) -2120 -2121 if rebuilt_json.get(player_id) == None: -2122 rebuilt_json[player_id] = {} -2123 -2124 rebuilt_json[player_id]['game_id'] = game_id -2125 rebuilt_json[player_id]['team_name'] = team_name -2126 rebuilt_json[player_id]['team_confrence'] = team_confrence -2127 rebuilt_json[player_id]['player_id'] = player_id -2128 rebuilt_json[player_id]['player_name'] = player_name -2129 rebuilt_json[player_id]['home_away'] = home_away -2130 rebuilt_json[player_id]['rushing_LONG'] = player_stat -2131 -2132 else: -2133 raise IndexError( -2134 f"Unhandled stat: \t{stat['name']}") -2135 -2136 elif s_category['name'] == "receiving": -2137 for stat in s_category['types']: -2138 if stat['name'] == "REC": # receiving_REC -2139 for i in stat['athletes']: -2140 player_id = int(i['id']) -2141 player_name = i['name'] -2142 player_stat = int(i['stat']) -2143 -2144 if rebuilt_json.get(player_id) == None: -2145 rebuilt_json[player_id] = {} -2146 -2147 rebuilt_json[player_id]['game_id'] = game_id -2148 rebuilt_json[player_id]['team_name'] = team_name -2149 rebuilt_json[player_id]['team_confrence'] = team_confrence -2150 rebuilt_json[player_id]['player_id'] = player_id -2151 rebuilt_json[player_id]['player_name'] = player_name -2152 rebuilt_json[player_id]['home_away'] = home_away -2153 rebuilt_json[player_id]['receiving_REC'] = player_stat -2154 -2155 elif stat['name'] == "YDS": # receiving_YDS -2156 for i in stat['athletes']: -2157 player_id = int(i['id']) -2158 player_name = i['name'] -2159 player_stat = int(i['stat']) -2160 -2161 if rebuilt_json.get(player_id) == None: -2162 rebuilt_json[player_id] = {} -2163 -2164 rebuilt_json[player_id]['game_id'] = game_id -2165 rebuilt_json[player_id]['team_name'] = team_name -2166 rebuilt_json[player_id]['team_confrence'] = team_confrence -2167 rebuilt_json[player_id]['player_id'] = player_id -2168 rebuilt_json[player_id]['player_name'] = player_name -2169 rebuilt_json[player_id]['home_away'] = home_away -2170 rebuilt_json[player_id]['receiving_YDS'] = player_stat -2171 -2172 elif stat['name'] == "AVG": # receiving_AVG -2173 for i in stat['athletes']: -2174 player_id = int(i['id']) -2175 player_name = i['name'] -2176 player_stat = float(i['stat']) -2177 -2178 if rebuilt_json.get(player_id) == None: -2179 rebuilt_json[player_id] = {} -2180 -2181 rebuilt_json[player_id]['game_id'] = game_id -2182 rebuilt_json[player_id]['team_name'] = team_name -2183 rebuilt_json[player_id]['team_confrence'] = team_confrence -2184 rebuilt_json[player_id]['player_id'] = player_id -2185 rebuilt_json[player_id]['player_name'] = player_name -2186 rebuilt_json[player_id]['home_away'] = home_away -2187 rebuilt_json[player_id]['receiving_AVG'] = player_stat -2188 -2189 elif stat['name'] == "TD": # receiving_TD -2190 for i in stat['athletes']: -2191 player_id = int(i['id']) -2192 player_name = i['name'] -2193 player_stat = int(i['stat']) -2194 -2195 if rebuilt_json.get(player_id) == None: -2196 rebuilt_json[player_id] = {} -2197 -2198 rebuilt_json[player_id]['game_id'] = game_id -2199 rebuilt_json[player_id]['team_name'] = team_name -2200 rebuilt_json[player_id]['team_confrence'] = team_confrence -2201 rebuilt_json[player_id]['player_id'] = player_id -2202 rebuilt_json[player_id]['player_name'] = player_name -2203 rebuilt_json[player_id]['home_away'] = home_away -2204 rebuilt_json[player_id]['receiving_TD'] = player_stat -2205 -2206 elif stat['name'] == "LONG": # receiving_LONG -2207 for i in stat['athletes']: -2208 player_id = int(i['id']) -2209 player_name = i['name'] -2210 player_stat = int(i['stat']) -2211 -2212 if rebuilt_json.get(player_id) == None: -2213 rebuilt_json[player_id] = {} -2214 -2215 rebuilt_json[player_id]['game_id'] = game_id -2216 rebuilt_json[player_id]['team_name'] = team_name -2217 rebuilt_json[player_id]['team_confrence'] = team_confrence -2218 rebuilt_json[player_id]['player_id'] = player_id -2219 rebuilt_json[player_id]['player_name'] = player_name -2220 rebuilt_json[player_id]['home_away'] = home_away -2221 rebuilt_json[player_id]['receiving_LONG'] = player_stat -2222 -2223 else: -2224 raise IndexError( -2225 f"Unhandled stat: \t{stat['name']}") -2226 -2227 elif s_category['name'] == "fumbles": -2228 for stat in s_category['types']: -2229 if stat['name'] == "FUM": # fumbles_FUM -2230 for i in stat['athletes']: -2231 player_id = int(i['id']) -2232 player_name = i['name'] -2233 player_stat = int(i['stat']) -2234 -2235 if rebuilt_json.get(player_id) == None: -2236 rebuilt_json[player_id] = {} -2237 -2238 rebuilt_json[player_id]['game_id'] = game_id -2239 rebuilt_json[player_id]['team_name'] = team_name -2240 rebuilt_json[player_id]['team_confrence'] = team_confrence -2241 rebuilt_json[player_id]['player_id'] = player_id -2242 rebuilt_json[player_id]['player_name'] = player_name -2243 rebuilt_json[player_id]['home_away'] = home_away -2244 rebuilt_json[player_id]['fumbles_FUM'] = player_stat -2245 -2246 elif stat['name'] == "LOST": # fumbles_LOST -2247 for i in stat['athletes']: -2248 player_id = int(i['id']) -2249 player_name = i['name'] -2250 player_stat = int(i['stat']) -2251 -2252 if rebuilt_json.get(player_id) == None: -2253 rebuilt_json[player_id] = {} -2254 -2255 rebuilt_json[player_id]['game_id'] = game_id -2256 rebuilt_json[player_id]['team_name'] = team_name -2257 rebuilt_json[player_id]['team_confrence'] = team_confrence -2258 rebuilt_json[player_id]['player_id'] = player_id -2259 rebuilt_json[player_id]['player_name'] = player_name -2260 rebuilt_json[player_id]['home_away'] = home_away -2261 rebuilt_json[player_id]['fumbles_LOST'] = player_stat -2262 -2263 elif stat['name'] == "REC": # fumbles_REC -2264 for i in stat['athletes']: -2265 player_id = int(i['id']) -2266 player_name = i['name'] -2267 player_stat = int(i['stat']) -2268 -2269 if rebuilt_json.get(player_id) == None: -2270 rebuilt_json[player_id] = {} -2271 -2272 rebuilt_json[player_id]['game_id'] = game_id -2273 rebuilt_json[player_id]['team_name'] = team_name -2274 rebuilt_json[player_id]['team_confrence'] = team_confrence -2275 rebuilt_json[player_id]['player_id'] = player_id -2276 rebuilt_json[player_id]['player_name'] = player_name -2277 rebuilt_json[player_id]['home_away'] = home_away -2278 rebuilt_json[player_id]['fumbles_REC'] = player_stat -2279 -2280 else: -2281 raise IndexError( -2282 f"Unhandled stat: \t{stat['name']}") -2283 -2284 elif s_category['name'] == "defensive": -2285 for stat in s_category['types']: -2286 if stat['name'] == "TOT": # defensive_TOT -2287 for i in stat['athletes']: -2288 player_id = int(i['id']) -2289 player_name = i['name'] -2290 player_stat = int(i['stat']) -2291 -2292 if rebuilt_json.get(player_id) == None: -2293 rebuilt_json[player_id] = {} -2294 -2295 rebuilt_json[player_id]['game_id'] = game_id -2296 rebuilt_json[player_id]['team_name'] = team_name -2297 rebuilt_json[player_id]['team_confrence'] = team_confrence -2298 rebuilt_json[player_id]['player_id'] = player_id -2299 rebuilt_json[player_id]['player_name'] = player_name -2300 rebuilt_json[player_id]['home_away'] = home_away -2301 rebuilt_json[player_id]['defensive_TOT'] = player_stat -2302 -2303 elif stat['name'] == "SOLO": # defensive_SOLO -2304 for i in stat['athletes']: -2305 player_id = int(i['id']) -2306 player_name = i['name'] -2307 player_stat = int(i['stat']) -2308 -2309 if rebuilt_json.get(player_id) == None: -2310 rebuilt_json[player_id] = {} -2311 -2312 rebuilt_json[player_id]['game_id'] = game_id -2313 rebuilt_json[player_id]['team_name'] = team_name -2314 rebuilt_json[player_id]['team_confrence'] = team_confrence -2315 rebuilt_json[player_id]['player_id'] = player_id -2316 rebuilt_json[player_id]['player_name'] = player_name -2317 rebuilt_json[player_id]['home_away'] = home_away -2318 rebuilt_json[player_id]['defensive_SOLO'] = player_stat -2319 -2320 elif stat['name'] == "TFL": # defensive_TFL -2321 for i in stat['athletes']: -2322 player_id = int(i['id']) -2323 player_name = i['name'] -2324 player_stat = float(i['stat']) -2325 -2326 if rebuilt_json.get(player_id) == None: -2327 rebuilt_json[player_id] = {} -2328 -2329 rebuilt_json[player_id]['game_id'] = game_id -2330 rebuilt_json[player_id]['team_name'] = team_name -2331 rebuilt_json[player_id]['team_confrence'] = team_confrence -2332 rebuilt_json[player_id]['player_id'] = player_id -2333 rebuilt_json[player_id]['player_name'] = player_name -2334 rebuilt_json[player_id]['home_away'] = home_away -2335 rebuilt_json[player_id]['defensive_TFL'] = player_stat -2336 -2337 elif stat['name'] == "QB HUR": # defensive_QB HUR -2338 for i in stat['athletes']: -2339 player_id = int(i['id']) -2340 player_name = i['name'] -2341 player_stat = int(i['stat']) -2342 -2343 if rebuilt_json.get(player_id) == None: -2344 rebuilt_json[player_id] = {} -2345 -2346 rebuilt_json[player_id]['game_id'] = game_id -2347 rebuilt_json[player_id]['team_name'] = team_name -2348 rebuilt_json[player_id]['team_confrence'] = team_confrence -2349 rebuilt_json[player_id]['player_id'] = player_id -2350 rebuilt_json[player_id]['player_name'] = player_name -2351 rebuilt_json[player_id]['home_away'] = home_away -2352 rebuilt_json[player_id]['defensive_QB HUR'] = player_stat -2353 -2354 elif stat['name'] == "SACKS": # defensive_SACKS -2355 for i in stat['athletes']: -2356 player_id = int(i['id']) -2357 player_name = i['name'] -2358 player_stat = float(i['stat']) -2359 -2360 if rebuilt_json.get(player_id) == None: -2361 rebuilt_json[player_id] = {} -2362 -2363 rebuilt_json[player_id]['game_id'] = game_id -2364 rebuilt_json[player_id]['team_name'] = team_name -2365 rebuilt_json[player_id]['team_confrence'] = team_confrence -2366 rebuilt_json[player_id]['player_id'] = player_id -2367 rebuilt_json[player_id]['player_name'] = player_name -2368 rebuilt_json[player_id]['home_away'] = home_away -2369 rebuilt_json[player_id]['defensive_SACKS'] = player_stat -2370 -2371 elif stat['name'] == "PD": # defensive_PD -2372 for i in stat['athletes']: -2373 player_id = int(i['id']) -2374 player_name = i['name'] -2375 player_stat = int(i['stat']) -2376 -2377 if rebuilt_json.get(player_id) == None: -2378 rebuilt_json[player_id] = {} -2379 -2380 rebuilt_json[player_id]['game_id'] = game_id -2381 rebuilt_json[player_id]['team_name'] = team_name -2382 rebuilt_json[player_id]['team_confrence'] = team_confrence -2383 rebuilt_json[player_id]['player_id'] = player_id -2384 rebuilt_json[player_id]['player_name'] = player_name -2385 rebuilt_json[player_id]['home_away'] = home_away -2386 rebuilt_json[player_id]['defensive_PD'] = player_stat -2387 -2388 elif stat['name'] == "TD": # defensive_TD -2389 for i in stat['athletes']: -2390 player_id = int(i['id']) -2391 player_name = i['name'] -2392 player_stat = int(i['stat']) -2393 -2394 if rebuilt_json.get(player_id) == None: -2395 rebuilt_json[player_id] = {} -2396 -2397 rebuilt_json[player_id]['game_id'] = game_id -2398 rebuilt_json[player_id]['team_name'] = team_name -2399 rebuilt_json[player_id]['team_confrence'] = team_confrence -2400 rebuilt_json[player_id]['player_id'] = player_id -2401 rebuilt_json[player_id]['player_name'] = player_name -2402 rebuilt_json[player_id]['home_away'] = home_away -2403 rebuilt_json[player_id]['defensive_TD'] = player_stat -2404 -2405 else: -2406 raise IndexError( -2407 f"Unhandled stat: \t{stat['name']}") -2408 -2409 elif s_category['name'] == "interceptions": -2410 for stat in s_category['types']: -2411 if stat['name'] == "INT": # interceptions_INT -2412 for i in stat['athletes']: -2413 player_id = int(i['id']) -2414 player_name = i['name'] -2415 player_stat = int(i['stat']) -2416 -2417 if rebuilt_json.get(player_id) == None: -2418 rebuilt_json[player_id] = {} -2419 -2420 rebuilt_json[player_id]['game_id'] = game_id -2421 rebuilt_json[player_id]['team_name'] = team_name -2422 rebuilt_json[player_id]['team_confrence'] = team_confrence -2423 rebuilt_json[player_id]['player_id'] = player_id -2424 rebuilt_json[player_id]['player_name'] = player_name -2425 rebuilt_json[player_id]['home_away'] = home_away -2426 rebuilt_json[player_id]['interceptions_INT'] = player_stat -2427 -2428 elif stat['name'] == "YDS": # interceptions_YDS -2429 for i in stat['athletes']: -2430 player_id = int(i['id']) -2431 player_name = i['name'] -2432 player_stat = int(i['stat']) -2433 -2434 if rebuilt_json.get(player_id) == None: -2435 rebuilt_json[player_id] = {} -2436 -2437 rebuilt_json[player_id]['game_id'] = game_id -2438 rebuilt_json[player_id]['team_name'] = team_name -2439 rebuilt_json[player_id]['team_confrence'] = team_confrence -2440 rebuilt_json[player_id]['player_id'] = player_id -2441 rebuilt_json[player_id]['player_name'] = player_name -2442 rebuilt_json[player_id]['home_away'] = home_away -2443 rebuilt_json[player_id]['interceptions_YDS'] = player_stat -2444 -2445 elif stat['name'] == "TD": # interceptions_TD -2446 for i in stat['athletes']: -2447 player_id = int(i['id']) -2448 player_name = i['name'] -2449 player_stat = int(i['stat']) -2450 -2451 if rebuilt_json.get(player_id) == None: -2452 rebuilt_json[player_id] = {} -2453 -2454 rebuilt_json[player_id]['game_id'] = game_id -2455 rebuilt_json[player_id]['team_name'] = team_name -2456 rebuilt_json[player_id]['team_confrence'] = team_confrence -2457 rebuilt_json[player_id]['player_id'] = player_id -2458 rebuilt_json[player_id]['player_name'] = player_name -2459 rebuilt_json[player_id]['home_away'] = home_away -2460 rebuilt_json[player_id]['interceptions_TD'] = player_stat -2461 -2462 else: -2463 raise IndexError( -2464 f"Unhandled stat: \t{stat['name']}") -2465 -2466 elif s_category['name'] == "punting": -2467 for stat in s_category['types']: -2468 if stat['name'] == "NO": # punting_NO -2469 for i in stat['athletes']: -2470 player_id = int(i['id']) -2471 player_name = i['name'] -2472 player_stat = int(i['stat']) -2473 -2474 if rebuilt_json.get(player_id) == None: -2475 rebuilt_json[player_id] = {} -2476 -2477 rebuilt_json[player_id]['game_id'] = game_id -2478 rebuilt_json[player_id]['team_name'] = team_name -2479 rebuilt_json[player_id]['team_confrence'] = team_confrence -2480 rebuilt_json[player_id]['player_id'] = player_id -2481 rebuilt_json[player_id]['player_name'] = player_name -2482 rebuilt_json[player_id]['home_away'] = home_away -2483 rebuilt_json[player_id]['punting_NO'] = player_stat -2484 -2485 elif stat['name'] == "YDS": # punting_YDS -2486 for i in stat['athletes']: -2487 player_id = int(i['id']) -2488 player_name = i['name'] -2489 player_stat = int(i['stat']) -2490 -2491 if rebuilt_json.get(player_id) == None: -2492 rebuilt_json[player_id] = {} -2493 -2494 rebuilt_json[player_id]['game_id'] = game_id -2495 rebuilt_json[player_id]['team_name'] = team_name -2496 rebuilt_json[player_id]['team_confrence'] = team_confrence -2497 rebuilt_json[player_id]['player_id'] = player_id -2498 rebuilt_json[player_id]['player_name'] = player_name -2499 rebuilt_json[player_id]['home_away'] = home_away -2500 rebuilt_json[player_id]['punting_YDS'] = player_stat -2501 -2502 elif stat['name'] == "AVG": # punting_AVG -2503 for i in stat['athletes']: -2504 player_id = int(i['id']) -2505 player_name = i['name'] -2506 player_stat = float(i['stat']) -2507 -2508 if rebuilt_json.get(player_id) == None: -2509 rebuilt_json[player_id] = {} -2510 -2511 rebuilt_json[player_id]['game_id'] = game_id -2512 rebuilt_json[player_id]['team_name'] = team_name -2513 rebuilt_json[player_id]['team_confrence'] = team_confrence -2514 rebuilt_json[player_id]['player_id'] = player_id -2515 rebuilt_json[player_id]['player_name'] = player_name -2516 rebuilt_json[player_id]['home_away'] = home_away -2517 rebuilt_json[player_id]['punting_AVG'] = player_stat -2518 -2519 elif stat['name'] == "TB": # punting_TB -2520 for i in stat['athletes']: -2521 player_id = int(i['id']) -2522 player_name = i['name'] -2523 player_stat = int(i['stat']) -2524 -2525 if rebuilt_json.get(player_id) == None: -2526 rebuilt_json[player_id] = {} -2527 -2528 rebuilt_json[player_id]['game_id'] = game_id -2529 rebuilt_json[player_id]['team_name'] = team_name -2530 rebuilt_json[player_id]['team_confrence'] = team_confrence -2531 rebuilt_json[player_id]['player_id'] = player_id -2532 rebuilt_json[player_id]['player_name'] = player_name -2533 rebuilt_json[player_id]['home_away'] = home_away -2534 rebuilt_json[player_id]['punting_TB'] = player_stat -2535 -2536 elif stat['name'] == "In 20": # punting_In 20 -2537 for i in stat['athletes']: -2538 player_id = int(i['id']) -2539 player_name = i['name'] -2540 player_stat = int(i['stat']) -2541 -2542 if rebuilt_json.get(player_id) == None: -2543 rebuilt_json[player_id] = {} -2544 -2545 rebuilt_json[player_id]['game_id'] = game_id -2546 rebuilt_json[player_id]['team_name'] = team_name -2547 rebuilt_json[player_id]['team_confrence'] = team_confrence -2548 rebuilt_json[player_id]['player_id'] = player_id -2549 rebuilt_json[player_id]['player_name'] = player_name -2550 rebuilt_json[player_id]['home_away'] = home_away -2551 rebuilt_json[player_id]['punting_In 20'] = player_stat -2552 -2553 elif stat['name'] == "LONG": # punting_LONG -2554 for i in stat['athletes']: -2555 player_id = int(i['id']) -2556 player_name = i['name'] -2557 player_stat = int(i['stat']) -2558 -2559 if rebuilt_json.get(player_id) == None: -2560 rebuilt_json[player_id] = {} -2561 -2562 rebuilt_json[player_id]['game_id'] = game_id -2563 rebuilt_json[player_id]['team_name'] = team_name -2564 rebuilt_json[player_id]['team_confrence'] = team_confrence -2565 rebuilt_json[player_id]['player_id'] = player_id -2566 rebuilt_json[player_id]['player_name'] = player_name -2567 rebuilt_json[player_id]['home_away'] = home_away -2568 rebuilt_json[player_id]['punting_LONG'] = player_stat -2569 -2570 else: -2571 raise IndexError( -2572 f"Unhandled stat: \t{stat['name']}") -2573 -2574 elif s_category['name'] == "kicking": -2575 for stat in s_category['types']: -2576 if stat['name'] == "FG": # kicking_FG -2577 for i in stat['athletes']: -2578 player_id = int(i['id']) -2579 player_name = i['name'] -2580 player_stat = i['stat'] -2581 -2582 if rebuilt_json.get(player_id) == None: -2583 rebuilt_json[player_id] = {} -2584 -2585 rebuilt_json[player_id]['game_id'] = game_id -2586 rebuilt_json[player_id]['team_name'] = team_name -2587 rebuilt_json[player_id]['team_confrence'] = team_confrence -2588 rebuilt_json[player_id]['player_id'] = player_id -2589 rebuilt_json[player_id]['player_name'] = player_name -2590 rebuilt_json[player_id]['home_away'] = home_away -2591 rebuilt_json[player_id]['kicking_FG'] = player_stat -2592 -2593 elif stat['name'] == "TOT": # kicking_FG, special case -2594 for i in stat['athletes']: -2595 player_id = int(i['id']) -2596 player_name = i['name'] -2597 player_stat = i['stat'] -2598 -2599 if rebuilt_json.get(player_id) == None: -2600 rebuilt_json[player_id] = {} -2601 -2602 rebuilt_json[player_id]['game_id'] = game_id -2603 rebuilt_json[player_id]['team_name'] = team_name -2604 rebuilt_json[player_id]['team_confrence'] = team_confrence -2605 rebuilt_json[player_id]['player_id'] = player_id -2606 rebuilt_json[player_id]['player_name'] = player_name -2607 rebuilt_json[player_id]['home_away'] = home_away -2608 rebuilt_json[player_id]['kicking_FG'] = player_stat -2609 -2610 elif stat['name'] == "PCT": # kicking_PCT -2611 for i in stat['athletes']: -2612 player_id = int(i['id']) -2613 player_name = i['name'] -2614 player_stat = float(i['stat']) -2615 -2616 if rebuilt_json.get(player_id) == None: -2617 rebuilt_json[player_id] = {} -2618 -2619 rebuilt_json[player_id]['game_id'] = game_id -2620 rebuilt_json[player_id]['team_name'] = team_name -2621 rebuilt_json[player_id]['team_confrence'] = team_confrence -2622 rebuilt_json[player_id]['player_id'] = player_id -2623 rebuilt_json[player_id]['player_name'] = player_name -2624 rebuilt_json[player_id]['home_away'] = home_away -2625 rebuilt_json[player_id]['kicking_PCT'] = player_stat -2626 -2627 elif stat['name'] == "LONG": # kicking_LONG -2628 for i in stat['athletes']: -2629 player_id = int(i['id']) -2630 player_name = i['name'] -2631 player_stat = int(i['stat']) -2632 -2633 if rebuilt_json.get(player_id) == None: -2634 rebuilt_json[player_id] = {} -2635 -2636 rebuilt_json[player_id]['game_id'] = game_id -2637 rebuilt_json[player_id]['team_name'] = team_name -2638 rebuilt_json[player_id]['team_confrence'] = team_confrence -2639 rebuilt_json[player_id]['player_id'] = player_id -2640 rebuilt_json[player_id]['player_name'] = player_name -2641 rebuilt_json[player_id]['home_away'] = home_away -2642 rebuilt_json[player_id]['kicking_LONG'] = player_stat -2643 -2644 elif stat['name'] == "XP": # kicking_XP -2645 for i in stat['athletes']: -2646 player_id = int(i['id']) -2647 player_name = i['name'] -2648 player_stat = i['stat'] -2649 -2650 if rebuilt_json.get(player_id) == None: -2651 rebuilt_json[player_id] = {} -2652 -2653 rebuilt_json[player_id]['game_id'] = game_id -2654 rebuilt_json[player_id]['team_name'] = team_name -2655 rebuilt_json[player_id]['team_confrence'] = team_confrence -2656 rebuilt_json[player_id]['player_id'] = player_id -2657 rebuilt_json[player_id]['player_name'] = player_name -2658 rebuilt_json[player_id]['home_away'] = home_away -2659 rebuilt_json[player_id]['kicking_XP'] = player_stat -2660 -2661 elif stat['name'] == "PTS": # kicking_PTS -2662 for i in stat['athletes']: -2663 player_id = int(i['id']) -2664 player_name = i['name'] -2665 player_stat = int(i['stat']) -2666 -2667 if rebuilt_json.get(player_id) == None: -2668 rebuilt_json[player_id] = {} -2669 -2670 rebuilt_json[player_id]['game_id'] = game_id -2671 rebuilt_json[player_id]['team_name'] = team_name -2672 rebuilt_json[player_id]['team_confrence'] = team_confrence -2673 rebuilt_json[player_id]['player_id'] = player_id -2674 rebuilt_json[player_id]['player_name'] = player_name -2675 rebuilt_json[player_id]['home_away'] = home_away -2676 rebuilt_json[player_id]['kicking_PTS'] = player_stat -2677 -2678 else: -2679 raise IndexError( -2680 f"Unhandled stat: \t{stat['name']}") -2681 -2682 elif s_category['name'] == "kickReturns": -2683 for stat in s_category['types']: -2684 if stat['name'] == "NO": # kickReturns_NO -2685 for i in stat['athletes']: -2686 player_id = int(i['id']) -2687 player_name = i['name'] -2688 player_stat = int(i['stat']) -2689 -2690 if rebuilt_json.get(player_id) == None: -2691 rebuilt_json[player_id] = {} -2692 -2693 rebuilt_json[player_id]['game_id'] = game_id -2694 rebuilt_json[player_id]['team_name'] = team_name -2695 rebuilt_json[player_id]['team_confrence'] = team_confrence -2696 rebuilt_json[player_id]['player_id'] = player_id -2697 rebuilt_json[player_id]['player_name'] = player_name -2698 rebuilt_json[player_id]['home_away'] = home_away -2699 rebuilt_json[player_id]['kickReturns_NO'] = player_stat -2700 -2701 elif stat['name'] == "YDS": # kickReturns_YDS -2702 for i in stat['athletes']: -2703 player_id = int(i['id']) -2704 player_name = i['name'] -2705 player_stat = int(i['stat']) -2706 -2707 if rebuilt_json.get(player_id) == None: -2708 rebuilt_json[player_id] = {} -2709 -2710 rebuilt_json[player_id]['game_id'] = game_id -2711 rebuilt_json[player_id]['team_name'] = team_name -2712 rebuilt_json[player_id]['team_confrence'] = team_confrence -2713 rebuilt_json[player_id]['player_id'] = player_id -2714 rebuilt_json[player_id]['player_name'] = player_name -2715 rebuilt_json[player_id]['home_away'] = home_away -2716 rebuilt_json[player_id]['kickReturns_YDS'] = player_stat -2717 -2718 elif stat['name'] == "AVG": # kickReturns_AVG -2719 for i in stat['athletes']: -2720 player_id = int(i['id']) -2721 player_name = i['name'] -2722 player_stat = float(i['stat']) -2723 -2724 if rebuilt_json.get(player_id) == None: -2725 rebuilt_json[player_id] = {} -2726 -2727 rebuilt_json[player_id]['game_id'] = game_id -2728 rebuilt_json[player_id]['team_name'] = team_name -2729 rebuilt_json[player_id]['team_confrence'] = team_confrence -2730 rebuilt_json[player_id]['player_id'] = player_id -2731 rebuilt_json[player_id]['player_name'] = player_name -2732 rebuilt_json[player_id]['home_away'] = home_away -2733 rebuilt_json[player_id]['kickReturns_AVG'] = player_stat -2734 -2735 elif stat['name'] == "TD": # kickReturns_TD -2736 for i in stat['athletes']: -2737 player_id = int(i['id']) -2738 player_name = i['name'] -2739 player_stat = int(i['stat']) -2740 -2741 if rebuilt_json.get(player_id) == None: -2742 rebuilt_json[player_id] = {} -2743 -2744 rebuilt_json[player_id]['game_id'] = game_id -2745 rebuilt_json[player_id]['team_name'] = team_name -2746 rebuilt_json[player_id]['team_confrence'] = team_confrence -2747 rebuilt_json[player_id]['player_id'] = player_id -2748 rebuilt_json[player_id]['player_name'] = player_name -2749 rebuilt_json[player_id]['home_away'] = home_away -2750 rebuilt_json[player_id]['kickReturns_TD'] = player_stat -2751 -2752 elif stat['name'] == "LONG": # kickReturns_LONG -2753 for i in stat['athletes']: -2754 player_id = int(i['id']) -2755 player_name = i['name'] -2756 player_stat = int(i['stat']) -2757 -2758 if rebuilt_json.get(player_id) == None: -2759 rebuilt_json[player_id] = {} -2760 -2761 rebuilt_json[player_id]['game_id'] = game_id -2762 rebuilt_json[player_id]['team_name'] = team_name -2763 rebuilt_json[player_id]['team_confrence'] = team_confrence -2764 rebuilt_json[player_id]['player_id'] = player_id -2765 rebuilt_json[player_id]['player_name'] = player_name -2766 rebuilt_json[player_id]['home_away'] = home_away -2767 rebuilt_json[player_id]['kickReturns_LONG'] = player_stat -2768 -2769 else: -2770 raise IndexError( -2771 f"Unhandled stat: \t{stat['name']}") -2772 -2773 elif s_category['name'] == "puntReturns": -2774 for stat in s_category['types']: -2775 if stat['name'] == "NO": # puntReturns_NO -2776 for i in stat['athletes']: -2777 player_id = int(i['id']) -2778 player_name = i['name'] -2779 player_stat = int(i['stat']) -2780 -2781 if rebuilt_json.get(player_id) == None: -2782 rebuilt_json[player_id] = {} -2783 -2784 rebuilt_json[player_id]['game_id'] = game_id -2785 rebuilt_json[player_id]['team_name'] = team_name -2786 rebuilt_json[player_id]['team_confrence'] = team_confrence -2787 rebuilt_json[player_id]['player_id'] = player_id -2788 rebuilt_json[player_id]['player_name'] = player_name -2789 rebuilt_json[player_id]['home_away'] = home_away -2790 rebuilt_json[player_id]['puntReturns_NO'] = player_stat -2791 -2792 elif stat['name'] == "YDS": # puntReturns_YDS -2793 for i in stat['athletes']: -2794 player_id = int(i['id']) -2795 player_name = i['name'] -2796 player_stat = int(i['stat']) -2797 -2798 if rebuilt_json.get(player_id) == None: -2799 rebuilt_json[player_id] = {} -2800 -2801 rebuilt_json[player_id]['game_id'] = game_id -2802 rebuilt_json[player_id]['team_name'] = team_name -2803 rebuilt_json[player_id]['team_confrence'] = team_confrence -2804 rebuilt_json[player_id]['player_id'] = player_id -2805 rebuilt_json[player_id]['player_name'] = player_name -2806 rebuilt_json[player_id]['home_away'] = home_away -2807 rebuilt_json[player_id]['puntReturns_YDS'] = player_stat -2808 -2809 elif stat['name'] == "AVG": # puntReturns_AVG -2810 for i in stat['athletes']: -2811 player_id = int(i['id']) -2812 player_name = i['name'] -2813 player_stat = float(i['stat']) -2814 -2815 if rebuilt_json.get(player_id) == None: -2816 rebuilt_json[player_id] = {} -2817 -2818 rebuilt_json[player_id]['game_id'] = game_id -2819 rebuilt_json[player_id]['team_name'] = team_name -2820 rebuilt_json[player_id]['team_confrence'] = team_confrence -2821 rebuilt_json[player_id]['player_id'] = player_id -2822 rebuilt_json[player_id]['player_name'] = player_name -2823 rebuilt_json[player_id]['home_away'] = home_away -2824 rebuilt_json[player_id]['puntReturns_AVG'] = player_stat -2825 -2826 elif stat['name'] == "TD": # puntReturns_TD -2827 for i in stat['athletes']: -2828 player_id = int(i['id']) -2829 player_name = i['name'] -2830 player_stat = int(i['stat']) -2831 -2832 if rebuilt_json.get(player_id) == None: -2833 rebuilt_json[player_id] = {} -2834 -2835 rebuilt_json[player_id]['game_id'] = game_id -2836 rebuilt_json[player_id]['team_name'] = team_name -2837 rebuilt_json[player_id]['team_confrence'] = team_confrence -2838 rebuilt_json[player_id]['player_id'] = player_id -2839 rebuilt_json[player_id]['player_name'] = player_name -2840 rebuilt_json[player_id]['home_away'] = home_away -2841 rebuilt_json[player_id]['puntReturns_TD'] = player_stat -2842 -2843 elif stat['name'] == "LONG": # puntReturns_LONG -2844 for i in stat['athletes']: -2845 player_id = int(i['id']) -2846 player_name = i['name'] -2847 player_stat = int(i['stat']) -2848 -2849 if rebuilt_json.get(player_id) == None: -2850 rebuilt_json[player_id] = {} -2851 -2852 rebuilt_json[player_id]['game_id'] = game_id -2853 rebuilt_json[player_id]['team_name'] = team_name -2854 rebuilt_json[player_id]['team_confrence'] = team_confrence -2855 rebuilt_json[player_id]['player_id'] = player_id -2856 rebuilt_json[player_id]['player_name'] = player_name -2857 rebuilt_json[player_id]['home_away'] = home_away -2858 rebuilt_json[player_id]['puntReturns_LONG'] = player_stat -2859 -2860 else: -2861 raise IndexError( -2862 f"Unhandled stat: \t{stat['name']}") -2863 -2864 else: -2865 raise IndexError(f"Unhandled stat category: \t{ -2866 s_category['name']}") +1671 # You can also tell this function to just return the API call as +1672 # a Dictionary (read: JSON) object. +1673 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1674 json_data = get_cfbd_player_game_stats( +1675 season=2020, +1676 week=10, +1677 return_as_dict=True +1678 ) +1679 print(json_data) +1680 +1681 ``` +1682 Returns +1683 ---------- +1684 A pandas `DataFrame` object with player game stats data, +1685 or (if `return_as_dict` is set to `True`) +1686 a dictionary object with player game stats data. +1687 +1688 """ +1689 +1690 rebuilt_json = {} +1691 now = datetime.now() +1692 cfb_games_df = pd.DataFrame() +1693 row_df = pd.DataFrame() +1694 url = "https://api.collegefootballdata.com/games/players" +1695 stat_columns = [ +1696 'game_id', +1697 'team_name', +1698 'team_confrence', +1699 'player_id', +1700 'player_name', +1701 'home_away', +1702 # PASS +1703 'passing_C/ATT', +1704 'passing_COMP', +1705 'passing_ATT', +1706 'passing_YDS', +1707 'passing_AVG', +1708 'passing_TD', +1709 'passing_INT', +1710 'passing_QBR', +1711 # RUSH +1712 'rushing_CAR', +1713 'rushing_YDS', +1714 'rushing_AVG', +1715 'rushing_TD', +1716 'rushing_LONG', +1717 # REC +1718 'receiving_REC', +1719 'receiving_YDS', +1720 'receiving_AVG', +1721 'receiving_TD', +1722 'receiving_LONG', +1723 # FUM +1724 'fumbles_FUM', +1725 'fumbles_LOST', +1726 'fumbles_REC', +1727 # DEFENSE +1728 'defensive_TOT', +1729 'defensive_SOLO', +1730 'defensive_TFL', +1731 'defensive_QB HUR', +1732 'defensive_SACKS', +1733 'defensive_PD', +1734 'defensive_TD', +1735 # INT +1736 'interceptions_INT', +1737 'interceptions_YDS', +1738 'interceptions_TD', +1739 # PUNT +1740 'punting_NO', +1741 'punting_YDS', +1742 'punting_AVG', +1743 'punting_TB', +1744 'punting_In 20', +1745 'punting_LONG', +1746 # KICK +1747 'kicking_FG', +1748 'kicking_FGM', +1749 'kicking_FGA', +1750 'kicking_PCT', +1751 'kicking_LONG', +1752 'kicking_XP', +1753 'kicking_XPM', +1754 'kicking_XPA', +1755 'kicking_PTS', +1756 # KR +1757 'kickReturns_NO', +1758 'kickReturns_YDS', +1759 'kickReturns_AVG', +1760 'kickReturns_TD', +1761 'kickReturns_LONG', +1762 # PR +1763 'puntReturns_NO', +1764 'puntReturns_YDS', +1765 'puntReturns_AVG', +1766 'puntReturns_TD', +1767 'puntReturns_LONG' +1768 ] +1769 +1770 ######################################################################################################################################################################################################## +1771 +1772 if api_key != None: +1773 real_api_key = api_key +1774 del api_key +1775 else: +1776 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1777 +1778 if real_api_key == "tigersAreAwsome": +1779 raise ValueError( +1780 "You actually need to change `cfbd_key` to your CFBD API key.") +1781 elif "Bearer " in real_api_key: +1782 pass +1783 elif "Bearer" in real_api_key: +1784 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1785 else: +1786 real_api_key = "Bearer " + real_api_key +1787 +1788 if season == None: +1789 # This should never happen without user tampering, but if it does, +1790 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +1791 raise SystemError( +1792 "I don't know how, I don't know why, " + +1793 "but you managed to call this function while `season` was `None` (NULL)," + +1794 " and the function got to this point in the code." + +1795 "\nIf you have a GitHub account, " + +1796 "please raise an issue on this python package's GitHub page:\n" + +1797 "https://github.com/armstjc/cfbd-json-py/issues" +1798 ) +1799 elif season > now.year: +1800 raise ValueError(f"`season` cannot be greater than {season}.") +1801 elif season < 1869: +1802 raise ValueError(f"`season` cannot be less than 1869.") +1803 +1804 if season_type != "regular" and season_type != "postseason": +1805 raise ValueError( +1806 "`season_type` must be set to either \"regular\" or " + +1807 "\"postseason\" for this function to work." +1808 ) +1809 +1810 # `week`, `team`, and/or `conference` +1811 # must be not null for this function to work. +1812 +1813 if week == None and team == None and conference_abv == None and game_id == None: +1814 raise ValueError( +1815 "To use `get_cfbd_player_game_stats()`," + +1816 " `week`, `team`, and/or `conference_abv` need to be set to a non-null value." +1817 ) +1818 +1819 filter_by_stat_category = False +1820 +1821 if stat_category == None: +1822 pass +1823 elif stat_category == "passing": +1824 filter_by_stat_category = True +1825 elif stat_category == "rushing": +1826 filter_by_stat_category = True +1827 elif stat_category == "receiving": +1828 filter_by_stat_category = True +1829 elif stat_category == "fumbles": +1830 filter_by_stat_category = True +1831 elif stat_category == "passing": +1832 filter_by_stat_category = True +1833 elif stat_category == "defensive": +1834 filter_by_stat_category = True +1835 elif stat_category == "interceptions": +1836 filter_by_stat_category = True +1837 elif stat_category == "punting": +1838 filter_by_stat_category = True +1839 elif stat_category == "kicking": +1840 filter_by_stat_category = True +1841 elif stat_category == "kickReturns": +1842 filter_by_stat_category = True +1843 elif stat_category == "puntReturns": +1844 filter_by_stat_category = True +1845 else: +1846 raise ValueError( +1847 "Invalid input for `stat_category`." + +1848 "\nValid inputs are:" + +1849 """ +1850 - `passing` +1851 - `rushing` +1852 - `receiving` +1853 - `fumbles` +1854 - `defensive` +1855 - `interceptions` +1856 - `punting` +1857 - `kicking` +1858 - `kickReturns` +1859 - `puntReturns` +1860 """ +1861 ) +1862 +1863 # URL builder +1864 ######################################################################################################################################################################################################## +1865 +1866 # Required by the API +1867 url += f"?year={season}" +1868 +1869 if game_id != None: +1870 url += f"&gameId={game_id}" +1871 +1872 if stat_category != None: +1873 url += f"&category={stat_category}" +1874 +1875 if week != None or team != None or conference_abv != None: +1876 logging.warning( +1877 "When calling `cfbd_json_py.games.get_cfbd_player_game_stats()`, " + +1878 "and setting `game_id` to a non-null value, " + +1879 "only `season`, `stat_category`, and `game_id` are considered " + +1880 "when calling the CFBD API." +1881 ) +1882 else: +1883 if season_type != None: +1884 url += f"&seasonType={season_type}" +1885 +1886 if week != None: +1887 url += f"&week={week}" +1888 +1889 if team != None: +1890 url += f"&team={team}" +1891 +1892 if conference_abv != None: +1893 url += f"&conference={conference_abv}" +1894 +1895 headers = { +1896 'Authorization': f'{real_api_key}', +1897 'accept': 'application/json' +1898 } +1899 +1900 response = requests.get(url, headers=headers) +1901 +1902 +1903 if response.status_code == 200: +1904 pass +1905 elif response.status_code == 401: +1906 raise ConnectionRefusedError( +1907 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1908 ) +1909 else: +1910 raise ConnectionError( +1911 f'Could not connect.\nHTTP Status code {response.status_code}' +1912 ) +1913 +1914 json_data = response.json() +1915 +1916 if return_as_dict == True: +1917 return json_data +1918 +1919 for game in tqdm(json_data): +1920 game_id = game['id'] +1921 +1922 for team in game['teams']: +1923 team_name = team['school'] +1924 team_confrence = team['conference'] +1925 home_away = team['homeAway'] +1926 +1927 for s_category in team['categories']: +1928 if s_category['name'] == "passing": +1929 for stat in s_category['types']: +1930 +1931 if stat['name'] == "C/ATT": # passing_C/ATT +1932 +1933 for i in stat['athletes']: +1934 player_id = int(i['id']) +1935 player_name = i['name'] +1936 player_stat = i['stat'] +1937 +1938 if rebuilt_json.get(player_id) == None: +1939 rebuilt_json[player_id] = {} +1940 +1941 rebuilt_json[player_id]['game_id'] = game_id +1942 rebuilt_json[player_id]['team_name'] = team_name +1943 rebuilt_json[player_id]['team_confrence'] = team_confrence +1944 rebuilt_json[player_id]['player_id'] = player_id +1945 rebuilt_json[player_id]['player_name'] = player_name +1946 rebuilt_json[player_id]['home_away'] = home_away +1947 rebuilt_json[player_id]['passing_C/ATT'] = player_stat +1948 +1949 elif stat['name'] == "YDS": # passing_YDS +1950 +1951 for i in stat['athletes']: +1952 player_id = int(i['id']) +1953 player_name = i['name'] +1954 player_stat = int(i['stat']) +1955 +1956 if rebuilt_json.get(player_id) == None: +1957 rebuilt_json[player_id] = {} +1958 +1959 rebuilt_json[player_id]['game_id'] = game_id +1960 rebuilt_json[player_id]['team_name'] = team_name +1961 rebuilt_json[player_id]['team_confrence'] = team_confrence +1962 rebuilt_json[player_id]['player_id'] = player_id +1963 rebuilt_json[player_id]['player_name'] = player_name +1964 rebuilt_json[player_id]['home_away'] = home_away +1965 rebuilt_json[player_id]['passing_YDS'] = player_stat +1966 +1967 elif stat['name'] == "AVG": # passing_AVG +1968 for i in stat['athletes']: +1969 player_id = int(i['id']) +1970 player_name = i['name'] +1971 player_stat = float(i['stat']) +1972 +1973 if rebuilt_json.get(player_id) == None: +1974 rebuilt_json[player_id] = {} +1975 +1976 rebuilt_json[player_id]['game_id'] = game_id +1977 rebuilt_json[player_id]['team_name'] = team_name +1978 rebuilt_json[player_id]['team_confrence'] = team_confrence +1979 rebuilt_json[player_id]['player_id'] = player_id +1980 rebuilt_json[player_id]['player_name'] = player_name +1981 rebuilt_json[player_id]['home_away'] = home_away +1982 rebuilt_json[player_id]['passing_AVG'] = player_stat +1983 +1984 elif stat['name'] == "TD": # passing_TD +1985 +1986 for i in stat['athletes']: +1987 player_id = int(i['id']) +1988 player_name = i['name'] +1989 player_stat = int(i['stat']) +1990 +1991 if rebuilt_json.get(player_id) == None: +1992 rebuilt_json[player_id] = {} +1993 +1994 rebuilt_json[player_id]['game_id'] = game_id +1995 rebuilt_json[player_id]['team_name'] = team_name +1996 rebuilt_json[player_id]['team_confrence'] = team_confrence +1997 rebuilt_json[player_id]['player_id'] = player_id +1998 rebuilt_json[player_id]['player_name'] = player_name +1999 rebuilt_json[player_id]['home_away'] = home_away +2000 rebuilt_json[player_id]['passing_TD'] = player_stat +2001 +2002 elif stat['name'] == "INT": # passing_INT +2003 +2004 for i in stat['athletes']: +2005 player_id = int(i['id']) +2006 player_name = i['name'] +2007 player_stat = int(i['stat']) +2008 +2009 if rebuilt_json.get(player_id) == None: +2010 rebuilt_json[player_id] = {} +2011 +2012 rebuilt_json[player_id]['game_id'] = game_id +2013 rebuilt_json[player_id]['team_name'] = team_name +2014 rebuilt_json[player_id]['team_confrence'] = team_confrence +2015 rebuilt_json[player_id]['player_id'] = player_id +2016 rebuilt_json[player_id]['player_name'] = player_name +2017 rebuilt_json[player_id]['home_away'] = home_away +2018 rebuilt_json[player_id]['passing_INT'] = player_stat +2019 +2020 elif stat['name'] == "QBR": # passing_QBR +2021 for i in stat['athletes']: +2022 player_id = int(i['id']) +2023 player_name = i['name'] +2024 try: +2025 player_stat = float(i['stat']) +2026 except: +2027 player_stat = None +2028 +2029 if rebuilt_json.get(player_id) == None: +2030 rebuilt_json[player_id] = {} +2031 +2032 rebuilt_json[player_id]['game_id'] = game_id +2033 rebuilt_json[player_id]['team_name'] = team_name +2034 rebuilt_json[player_id]['team_confrence'] = team_confrence +2035 rebuilt_json[player_id]['player_id'] = player_id +2036 rebuilt_json[player_id]['player_name'] = player_name +2037 rebuilt_json[player_id]['home_away'] = home_away +2038 rebuilt_json[player_id]['passing_QBR'] = player_stat +2039 +2040 else: +2041 raise IndexError( +2042 f"Unhandled stat: \t{stat['name']}") +2043 # passing_df = pd.DataFrame(s_category['types']) +2044 elif s_category['name'] == "rushing": +2045 for stat in s_category['types']: +2046 if stat['name'] == "CAR": # rushing_CAR +2047 for i in stat['athletes']: +2048 player_id = int(i['id']) +2049 player_name = i['name'] +2050 player_stat = int(i['stat']) +2051 +2052 if rebuilt_json.get(player_id) == None: +2053 rebuilt_json[player_id] = {} +2054 +2055 rebuilt_json[player_id]['game_id'] = game_id +2056 rebuilt_json[player_id]['team_name'] = team_name +2057 rebuilt_json[player_id]['team_confrence'] = team_confrence +2058 rebuilt_json[player_id]['player_id'] = player_id +2059 rebuilt_json[player_id]['player_name'] = player_name +2060 rebuilt_json[player_id]['home_away'] = home_away +2061 rebuilt_json[player_id]['rushing_CAR'] = player_stat +2062 +2063 elif stat['name'] == "YDS": # rushing_YDS +2064 for i in stat['athletes']: +2065 player_id = int(i['id']) +2066 player_name = i['name'] +2067 player_stat = int(i['stat']) +2068 +2069 if rebuilt_json.get(player_id) == None: +2070 rebuilt_json[player_id] = {} +2071 +2072 rebuilt_json[player_id]['game_id'] = game_id +2073 rebuilt_json[player_id]['team_name'] = team_name +2074 rebuilt_json[player_id]['team_confrence'] = team_confrence +2075 rebuilt_json[player_id]['player_id'] = player_id +2076 rebuilt_json[player_id]['player_name'] = player_name +2077 rebuilt_json[player_id]['home_away'] = home_away +2078 rebuilt_json[player_id]['rushing_YDS'] = player_stat +2079 +2080 elif stat['name'] == "AVG": # rushing_AVG +2081 for i in stat['athletes']: +2082 player_id = int(i['id']) +2083 player_name = i['name'] +2084 player_stat = float(i['stat']) +2085 +2086 if rebuilt_json.get(player_id) == None: +2087 rebuilt_json[player_id] = {} +2088 +2089 rebuilt_json[player_id]['game_id'] = game_id +2090 rebuilt_json[player_id]['team_name'] = team_name +2091 rebuilt_json[player_id]['team_confrence'] = team_confrence +2092 rebuilt_json[player_id]['player_id'] = player_id +2093 rebuilt_json[player_id]['player_name'] = player_name +2094 rebuilt_json[player_id]['home_away'] = home_away +2095 rebuilt_json[player_id]['rushing_AVG'] = player_stat +2096 +2097 elif stat['name'] == "TD": # rushing_TD +2098 for i in stat['athletes']: +2099 player_id = int(i['id']) +2100 player_name = i['name'] +2101 player_stat = int(i['stat']) +2102 +2103 if rebuilt_json.get(player_id) == None: +2104 rebuilt_json[player_id] = {} +2105 +2106 rebuilt_json[player_id]['game_id'] = game_id +2107 rebuilt_json[player_id]['team_name'] = team_name +2108 rebuilt_json[player_id]['team_confrence'] = team_confrence +2109 rebuilt_json[player_id]['player_id'] = player_id +2110 rebuilt_json[player_id]['player_name'] = player_name +2111 rebuilt_json[player_id]['home_away'] = home_away +2112 rebuilt_json[player_id]['rushing_TD'] = player_stat +2113 +2114 elif stat['name'] == "LONG": # rushing_LONG +2115 for i in stat['athletes']: +2116 player_id = int(i['id']) +2117 player_name = i['name'] +2118 player_stat = int(i['stat']) +2119 +2120 if rebuilt_json.get(player_id) == None: +2121 rebuilt_json[player_id] = {} +2122 +2123 rebuilt_json[player_id]['game_id'] = game_id +2124 rebuilt_json[player_id]['team_name'] = team_name +2125 rebuilt_json[player_id]['team_confrence'] = team_confrence +2126 rebuilt_json[player_id]['player_id'] = player_id +2127 rebuilt_json[player_id]['player_name'] = player_name +2128 rebuilt_json[player_id]['home_away'] = home_away +2129 rebuilt_json[player_id]['rushing_LONG'] = player_stat +2130 +2131 else: +2132 raise IndexError( +2133 f"Unhandled stat: \t{stat['name']}") +2134 +2135 elif s_category['name'] == "receiving": +2136 for stat in s_category['types']: +2137 if stat['name'] == "REC": # receiving_REC +2138 for i in stat['athletes']: +2139 player_id = int(i['id']) +2140 player_name = i['name'] +2141 player_stat = int(i['stat']) +2142 +2143 if rebuilt_json.get(player_id) == None: +2144 rebuilt_json[player_id] = {} +2145 +2146 rebuilt_json[player_id]['game_id'] = game_id +2147 rebuilt_json[player_id]['team_name'] = team_name +2148 rebuilt_json[player_id]['team_confrence'] = team_confrence +2149 rebuilt_json[player_id]['player_id'] = player_id +2150 rebuilt_json[player_id]['player_name'] = player_name +2151 rebuilt_json[player_id]['home_away'] = home_away +2152 rebuilt_json[player_id]['receiving_REC'] = player_stat +2153 +2154 elif stat['name'] == "YDS": # receiving_YDS +2155 for i in stat['athletes']: +2156 player_id = int(i['id']) +2157 player_name = i['name'] +2158 player_stat = int(i['stat']) +2159 +2160 if rebuilt_json.get(player_id) == None: +2161 rebuilt_json[player_id] = {} +2162 +2163 rebuilt_json[player_id]['game_id'] = game_id +2164 rebuilt_json[player_id]['team_name'] = team_name +2165 rebuilt_json[player_id]['team_confrence'] = team_confrence +2166 rebuilt_json[player_id]['player_id'] = player_id +2167 rebuilt_json[player_id]['player_name'] = player_name +2168 rebuilt_json[player_id]['home_away'] = home_away +2169 rebuilt_json[player_id]['receiving_YDS'] = player_stat +2170 +2171 elif stat['name'] == "AVG": # receiving_AVG +2172 for i in stat['athletes']: +2173 player_id = int(i['id']) +2174 player_name = i['name'] +2175 player_stat = float(i['stat']) +2176 +2177 if rebuilt_json.get(player_id) == None: +2178 rebuilt_json[player_id] = {} +2179 +2180 rebuilt_json[player_id]['game_id'] = game_id +2181 rebuilt_json[player_id]['team_name'] = team_name +2182 rebuilt_json[player_id]['team_confrence'] = team_confrence +2183 rebuilt_json[player_id]['player_id'] = player_id +2184 rebuilt_json[player_id]['player_name'] = player_name +2185 rebuilt_json[player_id]['home_away'] = home_away +2186 rebuilt_json[player_id]['receiving_AVG'] = player_stat +2187 +2188 elif stat['name'] == "TD": # receiving_TD +2189 for i in stat['athletes']: +2190 player_id = int(i['id']) +2191 player_name = i['name'] +2192 player_stat = int(i['stat']) +2193 +2194 if rebuilt_json.get(player_id) == None: +2195 rebuilt_json[player_id] = {} +2196 +2197 rebuilt_json[player_id]['game_id'] = game_id +2198 rebuilt_json[player_id]['team_name'] = team_name +2199 rebuilt_json[player_id]['team_confrence'] = team_confrence +2200 rebuilt_json[player_id]['player_id'] = player_id +2201 rebuilt_json[player_id]['player_name'] = player_name +2202 rebuilt_json[player_id]['home_away'] = home_away +2203 rebuilt_json[player_id]['receiving_TD'] = player_stat +2204 +2205 elif stat['name'] == "LONG": # receiving_LONG +2206 for i in stat['athletes']: +2207 player_id = int(i['id']) +2208 player_name = i['name'] +2209 player_stat = int(i['stat']) +2210 +2211 if rebuilt_json.get(player_id) == None: +2212 rebuilt_json[player_id] = {} +2213 +2214 rebuilt_json[player_id]['game_id'] = game_id +2215 rebuilt_json[player_id]['team_name'] = team_name +2216 rebuilt_json[player_id]['team_confrence'] = team_confrence +2217 rebuilt_json[player_id]['player_id'] = player_id +2218 rebuilt_json[player_id]['player_name'] = player_name +2219 rebuilt_json[player_id]['home_away'] = home_away +2220 rebuilt_json[player_id]['receiving_LONG'] = player_stat +2221 +2222 else: +2223 raise IndexError( +2224 f"Unhandled stat: \t{stat['name']}") +2225 +2226 elif s_category['name'] == "fumbles": +2227 for stat in s_category['types']: +2228 if stat['name'] == "FUM": # fumbles_FUM +2229 for i in stat['athletes']: +2230 player_id = int(i['id']) +2231 player_name = i['name'] +2232 player_stat = int(i['stat']) +2233 +2234 if rebuilt_json.get(player_id) == None: +2235 rebuilt_json[player_id] = {} +2236 +2237 rebuilt_json[player_id]['game_id'] = game_id +2238 rebuilt_json[player_id]['team_name'] = team_name +2239 rebuilt_json[player_id]['team_confrence'] = team_confrence +2240 rebuilt_json[player_id]['player_id'] = player_id +2241 rebuilt_json[player_id]['player_name'] = player_name +2242 rebuilt_json[player_id]['home_away'] = home_away +2243 rebuilt_json[player_id]['fumbles_FUM'] = player_stat +2244 +2245 elif stat['name'] == "LOST": # fumbles_LOST +2246 for i in stat['athletes']: +2247 player_id = int(i['id']) +2248 player_name = i['name'] +2249 player_stat = int(i['stat']) +2250 +2251 if rebuilt_json.get(player_id) == None: +2252 rebuilt_json[player_id] = {} +2253 +2254 rebuilt_json[player_id]['game_id'] = game_id +2255 rebuilt_json[player_id]['team_name'] = team_name +2256 rebuilt_json[player_id]['team_confrence'] = team_confrence +2257 rebuilt_json[player_id]['player_id'] = player_id +2258 rebuilt_json[player_id]['player_name'] = player_name +2259 rebuilt_json[player_id]['home_away'] = home_away +2260 rebuilt_json[player_id]['fumbles_LOST'] = player_stat +2261 +2262 elif stat['name'] == "REC": # fumbles_REC +2263 for i in stat['athletes']: +2264 player_id = int(i['id']) +2265 player_name = i['name'] +2266 player_stat = int(i['stat']) +2267 +2268 if rebuilt_json.get(player_id) == None: +2269 rebuilt_json[player_id] = {} +2270 +2271 rebuilt_json[player_id]['game_id'] = game_id +2272 rebuilt_json[player_id]['team_name'] = team_name +2273 rebuilt_json[player_id]['team_confrence'] = team_confrence +2274 rebuilt_json[player_id]['player_id'] = player_id +2275 rebuilt_json[player_id]['player_name'] = player_name +2276 rebuilt_json[player_id]['home_away'] = home_away +2277 rebuilt_json[player_id]['fumbles_REC'] = player_stat +2278 +2279 else: +2280 raise IndexError( +2281 f"Unhandled stat: \t{stat['name']}") +2282 +2283 elif s_category['name'] == "defensive": +2284 for stat in s_category['types']: +2285 if stat['name'] == "TOT": # defensive_TOT +2286 for i in stat['athletes']: +2287 player_id = int(i['id']) +2288 player_name = i['name'] +2289 player_stat = int(i['stat']) +2290 +2291 if rebuilt_json.get(player_id) == None: +2292 rebuilt_json[player_id] = {} +2293 +2294 rebuilt_json[player_id]['game_id'] = game_id +2295 rebuilt_json[player_id]['team_name'] = team_name +2296 rebuilt_json[player_id]['team_confrence'] = team_confrence +2297 rebuilt_json[player_id]['player_id'] = player_id +2298 rebuilt_json[player_id]['player_name'] = player_name +2299 rebuilt_json[player_id]['home_away'] = home_away +2300 rebuilt_json[player_id]['defensive_TOT'] = player_stat +2301 +2302 elif stat['name'] == "SOLO": # defensive_SOLO +2303 for i in stat['athletes']: +2304 player_id = int(i['id']) +2305 player_name = i['name'] +2306 player_stat = int(i['stat']) +2307 +2308 if rebuilt_json.get(player_id) == None: +2309 rebuilt_json[player_id] = {} +2310 +2311 rebuilt_json[player_id]['game_id'] = game_id +2312 rebuilt_json[player_id]['team_name'] = team_name +2313 rebuilt_json[player_id]['team_confrence'] = team_confrence +2314 rebuilt_json[player_id]['player_id'] = player_id +2315 rebuilt_json[player_id]['player_name'] = player_name +2316 rebuilt_json[player_id]['home_away'] = home_away +2317 rebuilt_json[player_id]['defensive_SOLO'] = player_stat +2318 +2319 elif stat['name'] == "TFL": # defensive_TFL +2320 for i in stat['athletes']: +2321 player_id = int(i['id']) +2322 player_name = i['name'] +2323 player_stat = float(i['stat']) +2324 +2325 if rebuilt_json.get(player_id) == None: +2326 rebuilt_json[player_id] = {} +2327 +2328 rebuilt_json[player_id]['game_id'] = game_id +2329 rebuilt_json[player_id]['team_name'] = team_name +2330 rebuilt_json[player_id]['team_confrence'] = team_confrence +2331 rebuilt_json[player_id]['player_id'] = player_id +2332 rebuilt_json[player_id]['player_name'] = player_name +2333 rebuilt_json[player_id]['home_away'] = home_away +2334 rebuilt_json[player_id]['defensive_TFL'] = player_stat +2335 +2336 elif stat['name'] == "QB HUR": # defensive_QB HUR +2337 for i in stat['athletes']: +2338 player_id = int(i['id']) +2339 player_name = i['name'] +2340 player_stat = int(i['stat']) +2341 +2342 if rebuilt_json.get(player_id) == None: +2343 rebuilt_json[player_id] = {} +2344 +2345 rebuilt_json[player_id]['game_id'] = game_id +2346 rebuilt_json[player_id]['team_name'] = team_name +2347 rebuilt_json[player_id]['team_confrence'] = team_confrence +2348 rebuilt_json[player_id]['player_id'] = player_id +2349 rebuilt_json[player_id]['player_name'] = player_name +2350 rebuilt_json[player_id]['home_away'] = home_away +2351 rebuilt_json[player_id]['defensive_QB HUR'] = player_stat +2352 +2353 elif stat['name'] == "SACKS": # defensive_SACKS +2354 for i in stat['athletes']: +2355 player_id = int(i['id']) +2356 player_name = i['name'] +2357 player_stat = float(i['stat']) +2358 +2359 if rebuilt_json.get(player_id) == None: +2360 rebuilt_json[player_id] = {} +2361 +2362 rebuilt_json[player_id]['game_id'] = game_id +2363 rebuilt_json[player_id]['team_name'] = team_name +2364 rebuilt_json[player_id]['team_confrence'] = team_confrence +2365 rebuilt_json[player_id]['player_id'] = player_id +2366 rebuilt_json[player_id]['player_name'] = player_name +2367 rebuilt_json[player_id]['home_away'] = home_away +2368 rebuilt_json[player_id]['defensive_SACKS'] = player_stat +2369 +2370 elif stat['name'] == "PD": # defensive_PD +2371 for i in stat['athletes']: +2372 player_id = int(i['id']) +2373 player_name = i['name'] +2374 player_stat = int(i['stat']) +2375 +2376 if rebuilt_json.get(player_id) == None: +2377 rebuilt_json[player_id] = {} +2378 +2379 rebuilt_json[player_id]['game_id'] = game_id +2380 rebuilt_json[player_id]['team_name'] = team_name +2381 rebuilt_json[player_id]['team_confrence'] = team_confrence +2382 rebuilt_json[player_id]['player_id'] = player_id +2383 rebuilt_json[player_id]['player_name'] = player_name +2384 rebuilt_json[player_id]['home_away'] = home_away +2385 rebuilt_json[player_id]['defensive_PD'] = player_stat +2386 +2387 elif stat['name'] == "TD": # defensive_TD +2388 for i in stat['athletes']: +2389 player_id = int(i['id']) +2390 player_name = i['name'] +2391 player_stat = int(i['stat']) +2392 +2393 if rebuilt_json.get(player_id) == None: +2394 rebuilt_json[player_id] = {} +2395 +2396 rebuilt_json[player_id]['game_id'] = game_id +2397 rebuilt_json[player_id]['team_name'] = team_name +2398 rebuilt_json[player_id]['team_confrence'] = team_confrence +2399 rebuilt_json[player_id]['player_id'] = player_id +2400 rebuilt_json[player_id]['player_name'] = player_name +2401 rebuilt_json[player_id]['home_away'] = home_away +2402 rebuilt_json[player_id]['defensive_TD'] = player_stat +2403 +2404 else: +2405 raise IndexError( +2406 f"Unhandled stat: \t{stat['name']}") +2407 +2408 elif s_category['name'] == "interceptions": +2409 for stat in s_category['types']: +2410 if stat['name'] == "INT": # interceptions_INT +2411 for i in stat['athletes']: +2412 player_id = int(i['id']) +2413 player_name = i['name'] +2414 player_stat = int(i['stat']) +2415 +2416 if rebuilt_json.get(player_id) == None: +2417 rebuilt_json[player_id] = {} +2418 +2419 rebuilt_json[player_id]['game_id'] = game_id +2420 rebuilt_json[player_id]['team_name'] = team_name +2421 rebuilt_json[player_id]['team_confrence'] = team_confrence +2422 rebuilt_json[player_id]['player_id'] = player_id +2423 rebuilt_json[player_id]['player_name'] = player_name +2424 rebuilt_json[player_id]['home_away'] = home_away +2425 rebuilt_json[player_id]['interceptions_INT'] = player_stat +2426 +2427 elif stat['name'] == "YDS": # interceptions_YDS +2428 for i in stat['athletes']: +2429 player_id = int(i['id']) +2430 player_name = i['name'] +2431 player_stat = int(i['stat']) +2432 +2433 if rebuilt_json.get(player_id) == None: +2434 rebuilt_json[player_id] = {} +2435 +2436 rebuilt_json[player_id]['game_id'] = game_id +2437 rebuilt_json[player_id]['team_name'] = team_name +2438 rebuilt_json[player_id]['team_confrence'] = team_confrence +2439 rebuilt_json[player_id]['player_id'] = player_id +2440 rebuilt_json[player_id]['player_name'] = player_name +2441 rebuilt_json[player_id]['home_away'] = home_away +2442 rebuilt_json[player_id]['interceptions_YDS'] = player_stat +2443 +2444 elif stat['name'] == "TD": # interceptions_TD +2445 for i in stat['athletes']: +2446 player_id = int(i['id']) +2447 player_name = i['name'] +2448 player_stat = int(i['stat']) +2449 +2450 if rebuilt_json.get(player_id) == None: +2451 rebuilt_json[player_id] = {} +2452 +2453 rebuilt_json[player_id]['game_id'] = game_id +2454 rebuilt_json[player_id]['team_name'] = team_name +2455 rebuilt_json[player_id]['team_confrence'] = team_confrence +2456 rebuilt_json[player_id]['player_id'] = player_id +2457 rebuilt_json[player_id]['player_name'] = player_name +2458 rebuilt_json[player_id]['home_away'] = home_away +2459 rebuilt_json[player_id]['interceptions_TD'] = player_stat +2460 +2461 else: +2462 raise IndexError( +2463 f"Unhandled stat: \t{stat['name']}") +2464 +2465 elif s_category['name'] == "punting": +2466 for stat in s_category['types']: +2467 if stat['name'] == "NO": # punting_NO +2468 for i in stat['athletes']: +2469 player_id = int(i['id']) +2470 player_name = i['name'] +2471 player_stat = int(i['stat']) +2472 +2473 if rebuilt_json.get(player_id) == None: +2474 rebuilt_json[player_id] = {} +2475 +2476 rebuilt_json[player_id]['game_id'] = game_id +2477 rebuilt_json[player_id]['team_name'] = team_name +2478 rebuilt_json[player_id]['team_confrence'] = team_confrence +2479 rebuilt_json[player_id]['player_id'] = player_id +2480 rebuilt_json[player_id]['player_name'] = player_name +2481 rebuilt_json[player_id]['home_away'] = home_away +2482 rebuilt_json[player_id]['punting_NO'] = player_stat +2483 +2484 elif stat['name'] == "YDS": # punting_YDS +2485 for i in stat['athletes']: +2486 player_id = int(i['id']) +2487 player_name = i['name'] +2488 player_stat = int(i['stat']) +2489 +2490 if rebuilt_json.get(player_id) == None: +2491 rebuilt_json[player_id] = {} +2492 +2493 rebuilt_json[player_id]['game_id'] = game_id +2494 rebuilt_json[player_id]['team_name'] = team_name +2495 rebuilt_json[player_id]['team_confrence'] = team_confrence +2496 rebuilt_json[player_id]['player_id'] = player_id +2497 rebuilt_json[player_id]['player_name'] = player_name +2498 rebuilt_json[player_id]['home_away'] = home_away +2499 rebuilt_json[player_id]['punting_YDS'] = player_stat +2500 +2501 elif stat['name'] == "AVG": # punting_AVG +2502 for i in stat['athletes']: +2503 player_id = int(i['id']) +2504 player_name = i['name'] +2505 player_stat = float(i['stat']) +2506 +2507 if rebuilt_json.get(player_id) == None: +2508 rebuilt_json[player_id] = {} +2509 +2510 rebuilt_json[player_id]['game_id'] = game_id +2511 rebuilt_json[player_id]['team_name'] = team_name +2512 rebuilt_json[player_id]['team_confrence'] = team_confrence +2513 rebuilt_json[player_id]['player_id'] = player_id +2514 rebuilt_json[player_id]['player_name'] = player_name +2515 rebuilt_json[player_id]['home_away'] = home_away +2516 rebuilt_json[player_id]['punting_AVG'] = player_stat +2517 +2518 elif stat['name'] == "TB": # punting_TB +2519 for i in stat['athletes']: +2520 player_id = int(i['id']) +2521 player_name = i['name'] +2522 player_stat = int(i['stat']) +2523 +2524 if rebuilt_json.get(player_id) == None: +2525 rebuilt_json[player_id] = {} +2526 +2527 rebuilt_json[player_id]['game_id'] = game_id +2528 rebuilt_json[player_id]['team_name'] = team_name +2529 rebuilt_json[player_id]['team_confrence'] = team_confrence +2530 rebuilt_json[player_id]['player_id'] = player_id +2531 rebuilt_json[player_id]['player_name'] = player_name +2532 rebuilt_json[player_id]['home_away'] = home_away +2533 rebuilt_json[player_id]['punting_TB'] = player_stat +2534 +2535 elif stat['name'] == "In 20": # punting_In 20 +2536 for i in stat['athletes']: +2537 player_id = int(i['id']) +2538 player_name = i['name'] +2539 player_stat = int(i['stat']) +2540 +2541 if rebuilt_json.get(player_id) == None: +2542 rebuilt_json[player_id] = {} +2543 +2544 rebuilt_json[player_id]['game_id'] = game_id +2545 rebuilt_json[player_id]['team_name'] = team_name +2546 rebuilt_json[player_id]['team_confrence'] = team_confrence +2547 rebuilt_json[player_id]['player_id'] = player_id +2548 rebuilt_json[player_id]['player_name'] = player_name +2549 rebuilt_json[player_id]['home_away'] = home_away +2550 rebuilt_json[player_id]['punting_In 20'] = player_stat +2551 +2552 elif stat['name'] == "LONG": # punting_LONG +2553 for i in stat['athletes']: +2554 player_id = int(i['id']) +2555 player_name = i['name'] +2556 player_stat = int(i['stat']) +2557 +2558 if rebuilt_json.get(player_id) == None: +2559 rebuilt_json[player_id] = {} +2560 +2561 rebuilt_json[player_id]['game_id'] = game_id +2562 rebuilt_json[player_id]['team_name'] = team_name +2563 rebuilt_json[player_id]['team_confrence'] = team_confrence +2564 rebuilt_json[player_id]['player_id'] = player_id +2565 rebuilt_json[player_id]['player_name'] = player_name +2566 rebuilt_json[player_id]['home_away'] = home_away +2567 rebuilt_json[player_id]['punting_LONG'] = player_stat +2568 +2569 else: +2570 raise IndexError( +2571 f"Unhandled stat: \t{stat['name']}") +2572 +2573 elif s_category['name'] == "kicking": +2574 for stat in s_category['types']: +2575 if stat['name'] == "FG": # kicking_FG +2576 for i in stat['athletes']: +2577 player_id = int(i['id']) +2578 player_name = i['name'] +2579 player_stat = i['stat'] +2580 +2581 if rebuilt_json.get(player_id) == None: +2582 rebuilt_json[player_id] = {} +2583 +2584 rebuilt_json[player_id]['game_id'] = game_id +2585 rebuilt_json[player_id]['team_name'] = team_name +2586 rebuilt_json[player_id]['team_confrence'] = team_confrence +2587 rebuilt_json[player_id]['player_id'] = player_id +2588 rebuilt_json[player_id]['player_name'] = player_name +2589 rebuilt_json[player_id]['home_away'] = home_away +2590 rebuilt_json[player_id]['kicking_FG'] = player_stat +2591 +2592 elif stat['name'] == "TOT": # kicking_FG, special case +2593 for i in stat['athletes']: +2594 player_id = int(i['id']) +2595 player_name = i['name'] +2596 player_stat = i['stat'] +2597 +2598 if rebuilt_json.get(player_id) == None: +2599 rebuilt_json[player_id] = {} +2600 +2601 rebuilt_json[player_id]['game_id'] = game_id +2602 rebuilt_json[player_id]['team_name'] = team_name +2603 rebuilt_json[player_id]['team_confrence'] = team_confrence +2604 rebuilt_json[player_id]['player_id'] = player_id +2605 rebuilt_json[player_id]['player_name'] = player_name +2606 rebuilt_json[player_id]['home_away'] = home_away +2607 rebuilt_json[player_id]['kicking_FG'] = player_stat +2608 +2609 elif stat['name'] == "PCT": # kicking_PCT +2610 for i in stat['athletes']: +2611 player_id = int(i['id']) +2612 player_name = i['name'] +2613 player_stat = float(i['stat']) +2614 +2615 if rebuilt_json.get(player_id) == None: +2616 rebuilt_json[player_id] = {} +2617 +2618 rebuilt_json[player_id]['game_id'] = game_id +2619 rebuilt_json[player_id]['team_name'] = team_name +2620 rebuilt_json[player_id]['team_confrence'] = team_confrence +2621 rebuilt_json[player_id]['player_id'] = player_id +2622 rebuilt_json[player_id]['player_name'] = player_name +2623 rebuilt_json[player_id]['home_away'] = home_away +2624 rebuilt_json[player_id]['kicking_PCT'] = player_stat +2625 +2626 elif stat['name'] == "LONG": # kicking_LONG +2627 for i in stat['athletes']: +2628 player_id = int(i['id']) +2629 player_name = i['name'] +2630 player_stat = int(i['stat']) +2631 +2632 if rebuilt_json.get(player_id) == None: +2633 rebuilt_json[player_id] = {} +2634 +2635 rebuilt_json[player_id]['game_id'] = game_id +2636 rebuilt_json[player_id]['team_name'] = team_name +2637 rebuilt_json[player_id]['team_confrence'] = team_confrence +2638 rebuilt_json[player_id]['player_id'] = player_id +2639 rebuilt_json[player_id]['player_name'] = player_name +2640 rebuilt_json[player_id]['home_away'] = home_away +2641 rebuilt_json[player_id]['kicking_LONG'] = player_stat +2642 +2643 elif stat['name'] == "XP": # kicking_XP +2644 for i in stat['athletes']: +2645 player_id = int(i['id']) +2646 player_name = i['name'] +2647 player_stat = i['stat'] +2648 +2649 if rebuilt_json.get(player_id) == None: +2650 rebuilt_json[player_id] = {} +2651 +2652 rebuilt_json[player_id]['game_id'] = game_id +2653 rebuilt_json[player_id]['team_name'] = team_name +2654 rebuilt_json[player_id]['team_confrence'] = team_confrence +2655 rebuilt_json[player_id]['player_id'] = player_id +2656 rebuilt_json[player_id]['player_name'] = player_name +2657 rebuilt_json[player_id]['home_away'] = home_away +2658 rebuilt_json[player_id]['kicking_XP'] = player_stat +2659 +2660 elif stat['name'] == "PTS": # kicking_PTS +2661 for i in stat['athletes']: +2662 player_id = int(i['id']) +2663 player_name = i['name'] +2664 player_stat = int(i['stat']) +2665 +2666 if rebuilt_json.get(player_id) == None: +2667 rebuilt_json[player_id] = {} +2668 +2669 rebuilt_json[player_id]['game_id'] = game_id +2670 rebuilt_json[player_id]['team_name'] = team_name +2671 rebuilt_json[player_id]['team_confrence'] = team_confrence +2672 rebuilt_json[player_id]['player_id'] = player_id +2673 rebuilt_json[player_id]['player_name'] = player_name +2674 rebuilt_json[player_id]['home_away'] = home_away +2675 rebuilt_json[player_id]['kicking_PTS'] = player_stat +2676 +2677 else: +2678 raise IndexError( +2679 f"Unhandled stat: \t{stat['name']}") +2680 +2681 elif s_category['name'] == "kickReturns": +2682 for stat in s_category['types']: +2683 if stat['name'] == "NO": # kickReturns_NO +2684 for i in stat['athletes']: +2685 player_id = int(i['id']) +2686 player_name = i['name'] +2687 player_stat = int(i['stat']) +2688 +2689 if rebuilt_json.get(player_id) == None: +2690 rebuilt_json[player_id] = {} +2691 +2692 rebuilt_json[player_id]['game_id'] = game_id +2693 rebuilt_json[player_id]['team_name'] = team_name +2694 rebuilt_json[player_id]['team_confrence'] = team_confrence +2695 rebuilt_json[player_id]['player_id'] = player_id +2696 rebuilt_json[player_id]['player_name'] = player_name +2697 rebuilt_json[player_id]['home_away'] = home_away +2698 rebuilt_json[player_id]['kickReturns_NO'] = player_stat +2699 +2700 elif stat['name'] == "YDS": # kickReturns_YDS +2701 for i in stat['athletes']: +2702 player_id = int(i['id']) +2703 player_name = i['name'] +2704 player_stat = int(i['stat']) +2705 +2706 if rebuilt_json.get(player_id) == None: +2707 rebuilt_json[player_id] = {} +2708 +2709 rebuilt_json[player_id]['game_id'] = game_id +2710 rebuilt_json[player_id]['team_name'] = team_name +2711 rebuilt_json[player_id]['team_confrence'] = team_confrence +2712 rebuilt_json[player_id]['player_id'] = player_id +2713 rebuilt_json[player_id]['player_name'] = player_name +2714 rebuilt_json[player_id]['home_away'] = home_away +2715 rebuilt_json[player_id]['kickReturns_YDS'] = player_stat +2716 +2717 elif stat['name'] == "AVG": # kickReturns_AVG +2718 for i in stat['athletes']: +2719 player_id = int(i['id']) +2720 player_name = i['name'] +2721 player_stat = float(i['stat']) +2722 +2723 if rebuilt_json.get(player_id) == None: +2724 rebuilt_json[player_id] = {} +2725 +2726 rebuilt_json[player_id]['game_id'] = game_id +2727 rebuilt_json[player_id]['team_name'] = team_name +2728 rebuilt_json[player_id]['team_confrence'] = team_confrence +2729 rebuilt_json[player_id]['player_id'] = player_id +2730 rebuilt_json[player_id]['player_name'] = player_name +2731 rebuilt_json[player_id]['home_away'] = home_away +2732 rebuilt_json[player_id]['kickReturns_AVG'] = player_stat +2733 +2734 elif stat['name'] == "TD": # kickReturns_TD +2735 for i in stat['athletes']: +2736 player_id = int(i['id']) +2737 player_name = i['name'] +2738 player_stat = int(i['stat']) +2739 +2740 if rebuilt_json.get(player_id) == None: +2741 rebuilt_json[player_id] = {} +2742 +2743 rebuilt_json[player_id]['game_id'] = game_id +2744 rebuilt_json[player_id]['team_name'] = team_name +2745 rebuilt_json[player_id]['team_confrence'] = team_confrence +2746 rebuilt_json[player_id]['player_id'] = player_id +2747 rebuilt_json[player_id]['player_name'] = player_name +2748 rebuilt_json[player_id]['home_away'] = home_away +2749 rebuilt_json[player_id]['kickReturns_TD'] = player_stat +2750 +2751 elif stat['name'] == "LONG": # kickReturns_LONG +2752 for i in stat['athletes']: +2753 player_id = int(i['id']) +2754 player_name = i['name'] +2755 player_stat = int(i['stat']) +2756 +2757 if rebuilt_json.get(player_id) == None: +2758 rebuilt_json[player_id] = {} +2759 +2760 rebuilt_json[player_id]['game_id'] = game_id +2761 rebuilt_json[player_id]['team_name'] = team_name +2762 rebuilt_json[player_id]['team_confrence'] = team_confrence +2763 rebuilt_json[player_id]['player_id'] = player_id +2764 rebuilt_json[player_id]['player_name'] = player_name +2765 rebuilt_json[player_id]['home_away'] = home_away +2766 rebuilt_json[player_id]['kickReturns_LONG'] = player_stat +2767 +2768 else: +2769 raise IndexError( +2770 f"Unhandled stat: \t{stat['name']}") +2771 +2772 elif s_category['name'] == "puntReturns": +2773 for stat in s_category['types']: +2774 if stat['name'] == "NO": # puntReturns_NO +2775 for i in stat['athletes']: +2776 player_id = int(i['id']) +2777 player_name = i['name'] +2778 player_stat = int(i['stat']) +2779 +2780 if rebuilt_json.get(player_id) == None: +2781 rebuilt_json[player_id] = {} +2782 +2783 rebuilt_json[player_id]['game_id'] = game_id +2784 rebuilt_json[player_id]['team_name'] = team_name +2785 rebuilt_json[player_id]['team_confrence'] = team_confrence +2786 rebuilt_json[player_id]['player_id'] = player_id +2787 rebuilt_json[player_id]['player_name'] = player_name +2788 rebuilt_json[player_id]['home_away'] = home_away +2789 rebuilt_json[player_id]['puntReturns_NO'] = player_stat +2790 +2791 elif stat['name'] == "YDS": # puntReturns_YDS +2792 for i in stat['athletes']: +2793 player_id = int(i['id']) +2794 player_name = i['name'] +2795 player_stat = int(i['stat']) +2796 +2797 if rebuilt_json.get(player_id) == None: +2798 rebuilt_json[player_id] = {} +2799 +2800 rebuilt_json[player_id]['game_id'] = game_id +2801 rebuilt_json[player_id]['team_name'] = team_name +2802 rebuilt_json[player_id]['team_confrence'] = team_confrence +2803 rebuilt_json[player_id]['player_id'] = player_id +2804 rebuilt_json[player_id]['player_name'] = player_name +2805 rebuilt_json[player_id]['home_away'] = home_away +2806 rebuilt_json[player_id]['puntReturns_YDS'] = player_stat +2807 +2808 elif stat['name'] == "AVG": # puntReturns_AVG +2809 for i in stat['athletes']: +2810 player_id = int(i['id']) +2811 player_name = i['name'] +2812 player_stat = float(i['stat']) +2813 +2814 if rebuilt_json.get(player_id) == None: +2815 rebuilt_json[player_id] = {} +2816 +2817 rebuilt_json[player_id]['game_id'] = game_id +2818 rebuilt_json[player_id]['team_name'] = team_name +2819 rebuilt_json[player_id]['team_confrence'] = team_confrence +2820 rebuilt_json[player_id]['player_id'] = player_id +2821 rebuilt_json[player_id]['player_name'] = player_name +2822 rebuilt_json[player_id]['home_away'] = home_away +2823 rebuilt_json[player_id]['puntReturns_AVG'] = player_stat +2824 +2825 elif stat['name'] == "TD": # puntReturns_TD +2826 for i in stat['athletes']: +2827 player_id = int(i['id']) +2828 player_name = i['name'] +2829 player_stat = int(i['stat']) +2830 +2831 if rebuilt_json.get(player_id) == None: +2832 rebuilt_json[player_id] = {} +2833 +2834 rebuilt_json[player_id]['game_id'] = game_id +2835 rebuilt_json[player_id]['team_name'] = team_name +2836 rebuilt_json[player_id]['team_confrence'] = team_confrence +2837 rebuilt_json[player_id]['player_id'] = player_id +2838 rebuilt_json[player_id]['player_name'] = player_name +2839 rebuilt_json[player_id]['home_away'] = home_away +2840 rebuilt_json[player_id]['puntReturns_TD'] = player_stat +2841 +2842 elif stat['name'] == "LONG": # puntReturns_LONG +2843 for i in stat['athletes']: +2844 player_id = int(i['id']) +2845 player_name = i['name'] +2846 player_stat = int(i['stat']) +2847 +2848 if rebuilt_json.get(player_id) == None: +2849 rebuilt_json[player_id] = {} +2850 +2851 rebuilt_json[player_id]['game_id'] = game_id +2852 rebuilt_json[player_id]['team_name'] = team_name +2853 rebuilt_json[player_id]['team_confrence'] = team_confrence +2854 rebuilt_json[player_id]['player_id'] = player_id +2855 rebuilt_json[player_id]['player_name'] = player_name +2856 rebuilt_json[player_id]['home_away'] = home_away +2857 rebuilt_json[player_id]['puntReturns_LONG'] = player_stat +2858 +2859 else: +2860 raise IndexError( +2861 f"Unhandled stat: \t{stat['name']}") +2862 +2863 else: +2864 raise IndexError( +2865 f"Unhandled stat category: \t{s_category['name']}" +2866 ) 2867 2868 for key, value in tqdm(rebuilt_json.items()): 2869 # print(key) @@ -3339,7 +3339,7 @@
3262 3263 `api_key_dir` (str, optional): 3264 Optional argument. -3265 If `api_key` is set to a string non-empty string, this variable is ignored. +3265 If `api_key` is set to am empty string, this variable is ignored. 3266 If `api_key_dir` is null, and `api_key` is null, 3267 this function will try to find a CFBD API key file in this user's home directory. 3268 If `api_key_dir` is set to a string, and `api_key` is null, @@ -3457,7 +3457,7 @@
3380 } 3381 3382 response = requests.get(url, headers=headers) -3383 time.sleep(0.1) +3383 3384 3385 if response.status_code == 200: 3386 pass @@ -3628,496 +3628,496 @@
-20def get_cfbd_games( - 21 season: int, - 22 api_key: str = None, - 23 api_key_dir: str = None, - 24 season_type: str = "regular", - 25 week: int = None, - 26 team: str = None, - 27 home_team: str = None, - 28 away_team: str = None, - 29 conference_abv: str = None, - 30 ncaa_division: str = "fbs", - 31 game_id: int = None, - 32 return_as_dict: bool = False): - 33 """ - 34 Retrives game schedule data from the CFBD API. - 35 - 36 Parameters - 37 ---------- - 38 `season` (int, mandatory): - 39 Required argument. - 40 Specifies the season you want CFB game information from. - 41 This must be specified, otherwise this package, and by extension - 42 the CFBD API, will not accept the request to get CFB game information. - 43 - 44 `api_key` (str, optional): - 45 Semi-optional argument. - 46 If `api_key` is null, this function will attempt to load a CFBD API key - 47 from the python environment, or from a file on this computer. - 48 If `api_key` is not null, this function will automatically assume that the - 49 inputted `api_key` is a valid CFBD API key. - 50 - 51 `api_key_dir` (str, optional): - 52 Optional argument. - 53 If `api_key` is set to a string non-empty string, this variable is ignored. - 54 If `api_key_dir` is null, and `api_key` is null, - 55 this function will try to find a CFBD API key file in this user's home directory. - 56 If `api_key_dir` is set to a string, and `api_key` is null, - 57 this function will assume that `api_key_dir` is a directory, - 58 and will try to find a CFBD API key file in that directory. - 59 - 60 `season_type` (str, semi-optional): - 61 Semi-optional argument. - 62 By defualt, this will be set to "regular", for the CFB regular season. - 63 If you want CFB game information for non-regular season games, - 64 set `season_type` to "postseason". - 65 If `season_type` is set to anything but "regular" or "postseason", - 66 a `ValueError()` will be raised. - 67 - 68 `week` (int, optional): - 69 Optional argument. - 70 If `week` is set to an integer, this function will attempt - 71 to load CFB game data from games in that season, and in that week. - 72 - 73 `team` (str, optional): - 74 Optional argument. - 75 If you only want CFB game information for a team, - 76 regardless if they are the home/away team, - 77 set `team` to the name of the team you want CFB game information from. - 78 - 79 `home_team` (str, optional): - 80 Optional argument. - 81 If you only want game information for a team, - 82 where that team was the home team in this season, - 83 set `home_team` to the name of the team you want game information for. - 84 - 85 `away_team` (str, optional): - 86 Optional argument. - 87 If you only want game information for a team, - 88 where that team was the away team in this season, - 89 set `away_team` to the name of the team you want game information for. - 90 - 91 `conference_abv` (str, optional): - 92 Optional argument. - 93 If you only want game information from games - 94 involving teams a specific confrence, - 95 set `conference_abv` to the abbreviation - 96 of the conference you want game information from. - 97 - 98 `ncaa_division` (str, semi-optional): - 99 Semi-optional argument. -100 By default, `ncaa_division` will be set to "fbs", -101 short for the Football Bowl Subdivision (FBS), -102 formerly known as D1-A (read as "division one single A"), -103 the highest level in the NCAA football pyramid, -104 where teams can scolarship up to 85 players -105 on their football team soley for athletic ability, -106 and often have the largest athletics budgets -107 within the NCAA. -108 -109 Other valid inputs are: -110 - "fcs": Football Championship Subdivision (FCS), -111 formerly known as D1-AA (read as "division one double A"). -112 An FCS school is still in the 1st division of the NCAA, -113 making them elligable for the March Madness tournament, -114 but may not have the resources to compete at the FBS level -115 at this time. FCS schools are limited to 63 athletic scolarships -116 for football. -117 - "ii": NCAA Division II. Schools in this and D3 are not -118 elligable for the March Madness tournament, -119 and are limited to 36 athletic scolarships for their football team. -120 - "iii": NCAA Division III. The largest single division within the -121 NCAA football pyramid. -122 D3 schools have the distinction of being part of -123 the only NCAA division that cannot give out scolarships soley -124 for athletic ability. -125 -126 `game_id` (int, optional): -127 Optional argument. -128 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get -129 game information just for that game ID. -130 -131 `return_as_dict` (bool, semi-optional): -132 Semi-optional argument. -133 If you want this function to return the data as a dictionary (read: JSON object), -134 instead of a pandas `DataFrame` object, -135 set `return_as_dict` to `True`. -136 -137 Usage -138 ---------- -139 ``` -140 import time -141 -142 from cfbd_json_py.games import get_cfbd_games +@@ -4140,7 +4140,7 @@19def get_cfbd_games( + 20 season: int, + 21 api_key: str = None, + 22 api_key_dir: str = None, + 23 season_type: str = "regular", + 24 week: int = None, + 25 team: str = None, + 26 home_team: str = None, + 27 away_team: str = None, + 28 conference_abv: str = None, + 29 ncaa_division: str = "fbs", + 30 game_id: int = None, + 31 return_as_dict: bool = False): + 32 """ + 33 Retrives game schedule data from the CFBD API. + 34 + 35 Parameters + 36 ---------- + 37 `season` (int, mandatory): + 38 Required argument. + 39 Specifies the season you want CFB game information from. + 40 This must be specified, otherwise this package, and by extension + 41 the CFBD API, will not accept the request to get CFB game information. + 42 + 43 `api_key` (str, optional): + 44 Semi-optional argument. + 45 If `api_key` is null, this function will attempt to load a CFBD API key + 46 from the python environment, or from a file on this computer. + 47 If `api_key` is not null, this function will automatically assume that the + 48 inputted `api_key` is a valid CFBD API key. + 49 + 50 `api_key_dir` (str, optional): + 51 Optional argument. + 52 If `api_key` is set to am empty string, this variable is ignored. + 53 If `api_key_dir` is null, and `api_key` is null, + 54 this function will try to find a CFBD API key file in this user's home directory. + 55 If `api_key_dir` is set to a string, and `api_key` is null, + 56 this function will assume that `api_key_dir` is a directory, + 57 and will try to find a CFBD API key file in that directory. + 58 + 59 `season_type` (str, semi-optional): + 60 Semi-optional argument. + 61 By defualt, this will be set to "regular", for the CFB regular season. + 62 If you want CFB game information for non-regular season games, + 63 set `season_type` to "postseason". + 64 If `season_type` is set to anything but "regular" or "postseason", + 65 a `ValueError()` will be raised. + 66 + 67 `week` (int, optional): + 68 Optional argument. + 69 If `week` is set to an integer, this function will attempt + 70 to load CFB game data from games in that season, and in that week. + 71 + 72 `team` (str, optional): + 73 Optional argument. + 74 If you only want CFB game information for a team, + 75 regardless if they are the home/away team, + 76 set `team` to the name of the team you want CFB game information from. + 77 + 78 `home_team` (str, optional): + 79 Optional argument. + 80 If you only want game information for a team, + 81 where that team was the home team in this season, + 82 set `home_team` to the name of the team you want game information for. + 83 + 84 `away_team` (str, optional): + 85 Optional argument. + 86 If you only want game information for a team, + 87 where that team was the away team in this season, + 88 set `away_team` to the name of the team you want game information for. + 89 + 90 `conference_abv` (str, optional): + 91 Optional argument. + 92 If you only want game information from games + 93 involving teams a specific confrence, + 94 set `conference_abv` to the abbreviation + 95 of the conference you want game information from. + 96 + 97 `ncaa_division` (str, semi-optional): + 98 Semi-optional argument. + 99 By default, `ncaa_division` will be set to "fbs", +100 short for the Football Bowl Subdivision (FBS), +101 formerly known as D1-A (read as "division one single A"), +102 the highest level in the NCAA football pyramid, +103 where teams can scolarship up to 85 players +104 on their football team soley for athletic ability, +105 and often have the largest athletics budgets +106 within the NCAA. +107 +108 Other valid inputs are: +109 - "fcs": Football Championship Subdivision (FCS), +110 formerly known as D1-AA (read as "division one double A"). +111 An FCS school is still in the 1st division of the NCAA, +112 making them elligable for the March Madness tournament, +113 but may not have the resources to compete at the FBS level +114 at this time. FCS schools are limited to 63 athletic scolarships +115 for football. +116 - "ii": NCAA Division II. Schools in this and D3 are not +117 elligable for the March Madness tournament, +118 and are limited to 36 athletic scolarships for their football team. +119 - "iii": NCAA Division III. The largest single division within the +120 NCAA football pyramid. +121 D3 schools have the distinction of being part of +122 the only NCAA division that cannot give out scolarships soley +123 for athletic ability. +124 +125 `game_id` (int, optional): +126 Optional argument. +127 If `game_id` is set to a game ID, `get_cfb_betting_lines()` will try to get +128 game information just for that game ID. +129 +130 `return_as_dict` (bool, semi-optional): +131 Semi-optional argument. +132 If you want this function to return the data as a dictionary (read: JSON object), +133 instead of a pandas `DataFrame` object, +134 set `return_as_dict` to `True`. +135 +136 Usage +137 ---------- +138 ``` +139 import time +140 +141 from cfbd_json_py.games import get_cfbd_games +142 143 -144 -145 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -146 -147 if cfbd_key != "tigersAreAwsome": -148 print("Using the user's API key declared in this script for this example.") -149 -150 # Get CFB games from the 2020 CFB season. -151 print("Get CFB games from the 2020 CFB season.") -152 json_data = get_cfbd_games( -153 api_key=cfbd_key, -154 season=2020 -155 ) -156 print(json_data) -157 time.sleep(5) -158 -159 # Get CFB games from week 10 of the 2020 CFB season. -160 print("Get CFB games from week 10 of the 2020 CFB season.") -161 json_data = get_cfbd_games( -162 api_key=cfbd_key, -163 season=2020, -164 week=10 -165 ) -166 print(json_data) -167 time.sleep(5) -168 -169 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. -170 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") -171 json_data = get_cfbd_games( -172 api_key=cfbd_key, -173 season=2019, -174 team="LSU" -175 ) -176 print(json_data) -177 time.sleep(5) -178 -179 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. -180 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") -181 json_data = get_cfbd_games( -182 api_key=cfbd_key, -183 season=2021, -184 home_team="Cincinnati" -185 ) -186 print(json_data) -187 time.sleep(5) -188 -189 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. -190 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") -191 json_data = get_cfbd_games( -192 api_key=cfbd_key, -193 season=2019, -194 away_team="Ohio" -195 ) -196 print(json_data) -197 time.sleep(5) -198 -199 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. -200 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") -201 json_data = get_cfbd_games( -202 api_key=cfbd_key, -203 season=2018, -204 away_team="Ohio" -205 ) -206 print(json_data) -207 time.sleep(5) -208 -209 # Get 2022 college football games where one or more teams competing -210 # was a Football Championship Subdivision team. -211 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") -212 json_data = get_cfbd_games( -213 api_key=cfbd_key, -214 season=2018, -215 away_team="Ohio" -216 ) -217 print(json_data) -218 time.sleep(5) -219 -220 # Get game information for the -221 # 2021 American Athletic Confrence (AAC) Championship Game. -222 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") -223 json_data = get_cfbd_games( -224 api_key=cfbd_key, -225 season=2018, -226 game_id=401331162 -227 ) -228 print(json_data) -229 time.sleep(5) -230 -231 # You can also tell this function to just return the API call as -232 # a Dictionary (read: JSON) object. -233 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -234 json_data = get_cfbd_games( -235 season=2020, -236 week=10, -237 api_key=cfbd_key, -238 return_as_dict=True -239 ) -240 print(json_data) -241 -242 else: -243 # Alternatively, if the CFBD API key exists in this python environment, -244 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -245 # you could just call these functions directly, without setting the API key -246 # in the script. -247 print("Using the user's API key suposedly loaded into this python environment for this example.") -248 -249 # Get CFB games from the 2020 CFB season. -250 print("Get CFB games from the 2020 CFB season.") -251 json_data = get_cfbd_games( -252 season=2020 -253 ) -254 print(json_data) -255 time.sleep(5) -256 -257 # Get CFB games from week 10 of the 2020 CFB season. -258 print("Get CFB games from week 10 of the 2020 CFB season.") -259 json_data = get_cfbd_games( -260 season=2020, -261 week=10 -262 ) -263 print(json_data) -264 time.sleep(5) -265 -266 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. -267 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") -268 json_data = get_cfbd_games( -269 season=2019, -270 team="LSU" -271 ) -272 print(json_data) -273 time.sleep(5) -274 -275 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. -276 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") -277 json_data = get_cfbd_games( -278 season=2021, -279 home_team="Cincinnati" -280 ) -281 print(json_data) -282 time.sleep(5) -283 -284 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. -285 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") -286 json_data = get_cfbd_games( -287 season=2019, -288 away_team="Ohio" -289 ) -290 print(json_data) -291 time.sleep(5) -292 -293 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. -294 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") -295 json_data = get_cfbd_games( -296 season=2018, -297 away_team="Ohio" -298 ) -299 print(json_data) -300 time.sleep(5) -301 -302 # Get 2022 college football games where one or more teams competing -303 # was a Football Championship Subdivision team. -304 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") -305 json_data = get_cfbd_games( -306 season=2018, -307 away_team="Ohio" -308 ) -309 print(json_data) -310 time.sleep(5) -311 -312 # Get game information for the -313 # 2021 American Athletic Confrence (AAC) Championship Game. -314 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") -315 json_data = get_cfbd_games( -316 season=2018, -317 game_id=401331162 -318 ) -319 print(json_data) -320 time.sleep(5) -321 -322 # You can also tell this function to just return the API call as -323 # a Dictionary (read: JSON) object. -324 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -325 json_data = get_cfbd_games( -326 season=2020, -327 week=10, -328 return_as_dict=True -329 ) -330 print(json_data) -331 -332 ``` -333 Returns -334 ---------- -335 A pandas `DataFrame` object with college football game information, -336 or (if `return_as_dict` is set to `True`) -337 a dictionary object with college football game information. -338 """ -339 -340 now = datetime.now() -341 cfb_games_df = pd.DataFrame() -342 row_df = pd.DataFrame() -343 url = "https://api.collegefootballdata.com/games" -344 -345 ######################################################################################################################################################################################################## -346 -347 if api_key != None: -348 real_api_key = api_key -349 del api_key -350 else: -351 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -352 -353 if real_api_key == "tigersAreAwsome": -354 raise ValueError( -355 "You actually need to change `cfbd_key` to your CFBD API key.") -356 elif "Bearer " in real_api_key: -357 pass -358 elif "Bearer" in real_api_key: -359 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -360 else: -361 real_api_key = "Bearer " + real_api_key -362 -363 if season == None: -364 # This should never happen without user tampering, but if it does, -365 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -366 raise SystemError( -367 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + -368 " and the function got to this point in the code." + -369 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + -370 "https://github.com/armstjc/cfbd-json-py/issues" -371 ) -372 elif season > now.year: -373 raise ValueError(f"`season` cannot be greater than {season}.") -374 elif season < 1869: -375 raise ValueError(f"`season` cannot be less than 1869.") -376 -377 if season_type != "regular" and season_type != "postseason": -378 raise ValueError( -379 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") -380 -381 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ -382 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": -383 pass -384 else: -385 raise ValueError( -386 "An invalid NCAA Division was inputted when calling this function." + -387 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + -388 f"\n\nYou entered: \n{ncaa_division}" -389 ) -390 -391 # URL builder -392 ######################################################################################################################################################################################################## -393 -394 # Required by API -395 url += f"?seasonType={season_type}" -396 -397 if game_id != None: -398 url += f"&year={season}" -399 url += f"&id={game_id}" -400 -401 if team != None or home_team != None \ -402 or away_team != None or conference_abv != None \ -403 or week != None: -404 logging.warning( -405 "When calling `cfbd_json_py.games.get_cfbd_games()`, " + -406 "and setting `game_id` to a non-null value, " + -407 "only `season` and `game_id` are considered " + -408 "when calling the CFBD API." -409 ) -410 -411 else: -412 url += f"&year={season}" -413 -414 # Optional for the API -415 if week != None: -416 url += f"&week={week}" -417 -418 if team != None: -419 url += f"&team={team}" -420 -421 if home_team != None: -422 url += f"&home={home_team}" -423 -424 if away_team != None: -425 url += f"&away={away_team}" -426 -427 if conference_abv != None: -428 url += f"&conference={conference_abv}" -429 -430 if ncaa_division != None: -431 url += f"&division={ncaa_division}" -432 -433 headers = { -434 'Authorization': f'{real_api_key}', -435 'accept': 'application/json' -436 } -437 -438 response = requests.get(url, headers=headers) -439 time.sleep(0.1) -440 -441 if response.status_code == 200: -442 pass -443 elif response.status_code == 401: -444 raise ConnectionRefusedError( -445 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -446 ) -447 else: -448 raise ConnectionError( -449 f'Could not connect.\nHTTP Status code {response.status_code}' -450 ) -451 -452 json_data = response.json() -453 -454 if return_as_dict == True: -455 return json_data -456 -457 for game in tqdm(json_data): -458 g_id = game['id'] -459 row_df = pd.DataFrame( -460 { -461 "game_id": g_id -462 }, index=[0] -463 ) -464 del g_id -465 -466 row_df['season'] = game['season'] -467 row_df['week'] = game['week'] -468 row_df['season_type'] = game['season_type'] -469 row_df['start_date'] = game['start_date'] -470 row_df['start_time_tbd'] = game['start_time_tbd'] -471 row_df['is_game_completed'] = game['completed'] -472 row_df['is_neutral_site'] = game['neutral_site'] -473 row_df['is_conference_game'] = game['conference_game'] -474 row_df['game_attendance'] = game['attendance'] -475 row_df['venue_id'] = game['venue_id'] -476 row_df['venue_name'] = game['venue'] -477 row_df['home_id'] = game['home_id'] -478 row_df['home_team'] = game['home_team'] -479 row_df['home_conference'] = game['home_conference'] -480 row_df['home_division'] = game['home_division'] -481 row_df['home_points'] = game['home_points'] -482 row_df['home_line_scores'] = str(game['home_line_scores']) -483 row_df['home_post_win_prob'] = game['home_post_win_prob'] -484 row_df['home_pregame_elo'] = game['home_pregame_elo'] -485 row_df['home_postgame_elo'] = game['home_postgame_elo'] -486 row_df['away_id'] = game['away_id'] -487 row_df['away_team'] = game['away_team'] -488 row_df['away_conference'] = game['away_conference'] -489 row_df['away_division'] = game['away_division'] -490 row_df['away_points'] = game['away_points'] -491 row_df['away_line_scores'] = str(game['away_line_scores']) -492 row_df['away_post_win_prob'] = game['away_post_win_prob'] -493 row_df['away_pregame_elo'] = game['away_pregame_elo'] -494 row_df['away_postgame_elo'] = game['away_postgame_elo'] -495 row_df['excitement_index'] = game['excitement_index'] -496 row_df['highlights'] = game['highlights'] -497 row_df['notes'] = game['notes'] -498 -499 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) -500 del row_df -501 -502 if len(cfb_games_df) == 0: -503 logging.error( -504 "The CFBD API accepted your inputs, " + -505 "but found no data within your specified input paramaters." + -506 " Please double check your input paramaters." -507 ) -508 -509 return cfb_games_df +144 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +145 +146 if cfbd_key != "tigersAreAwsome": +147 print("Using the user's API key declared in this script for this example.") +148 +149 # Get CFB games from the 2020 CFB season. +150 print("Get CFB games from the 2020 CFB season.") +151 json_data = get_cfbd_games( +152 api_key=cfbd_key, +153 season=2020 +154 ) +155 print(json_data) +156 time.sleep(5) +157 +158 # Get CFB games from week 10 of the 2020 CFB season. +159 print("Get CFB games from week 10 of the 2020 CFB season.") +160 json_data = get_cfbd_games( +161 api_key=cfbd_key, +162 season=2020, +163 week=10 +164 ) +165 print(json_data) +166 time.sleep(5) +167 +168 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. +169 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") +170 json_data = get_cfbd_games( +171 api_key=cfbd_key, +172 season=2019, +173 team="LSU" +174 ) +175 print(json_data) +176 time.sleep(5) +177 +178 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. +179 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") +180 json_data = get_cfbd_games( +181 api_key=cfbd_key, +182 season=2021, +183 home_team="Cincinnati" +184 ) +185 print(json_data) +186 time.sleep(5) +187 +188 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. +189 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") +190 json_data = get_cfbd_games( +191 api_key=cfbd_key, +192 season=2019, +193 away_team="Ohio" +194 ) +195 print(json_data) +196 time.sleep(5) +197 +198 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. +199 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") +200 json_data = get_cfbd_games( +201 api_key=cfbd_key, +202 season=2018, +203 away_team="Ohio" +204 ) +205 print(json_data) +206 time.sleep(5) +207 +208 # Get 2022 college football games where one or more teams competing +209 # was a Football Championship Subdivision team. +210 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") +211 json_data = get_cfbd_games( +212 api_key=cfbd_key, +213 season=2018, +214 away_team="Ohio" +215 ) +216 print(json_data) +217 time.sleep(5) +218 +219 # Get game information for the +220 # 2021 American Athletic Confrence (AAC) Championship Game. +221 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") +222 json_data = get_cfbd_games( +223 api_key=cfbd_key, +224 season=2018, +225 game_id=401331162 +226 ) +227 print(json_data) +228 time.sleep(5) +229 +230 # You can also tell this function to just return the API call as +231 # a Dictionary (read: JSON) object. +232 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +233 json_data = get_cfbd_games( +234 season=2020, +235 week=10, +236 api_key=cfbd_key, +237 return_as_dict=True +238 ) +239 print(json_data) +240 +241 else: +242 # Alternatively, if the CFBD API key exists in this python environment, +243 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +244 # you could just call these functions directly, without setting the API key +245 # in the script. +246 print("Using the user's API key suposedly loaded into this python environment for this example.") +247 +248 # Get CFB games from the 2020 CFB season. +249 print("Get CFB games from the 2020 CFB season.") +250 json_data = get_cfbd_games( +251 season=2020 +252 ) +253 print(json_data) +254 time.sleep(5) +255 +256 # Get CFB games from week 10 of the 2020 CFB season. +257 print("Get CFB games from week 10 of the 2020 CFB season.") +258 json_data = get_cfbd_games( +259 season=2020, +260 week=10 +261 ) +262 print(json_data) +263 time.sleep(5) +264 +265 # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers. +266 print("Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.") +267 json_data = get_cfbd_games( +268 season=2019, +269 team="LSU" +270 ) +271 print(json_data) +272 time.sleep(5) +273 +274 # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team. +275 print("Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.") +276 json_data = get_cfbd_games( +277 season=2021, +278 home_team="Cincinnati" +279 ) +280 print(json_data) +281 time.sleep(5) +282 +283 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. +284 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") +285 json_data = get_cfbd_games( +286 season=2019, +287 away_team="Ohio" +288 ) +289 print(json_data) +290 time.sleep(5) +291 +292 # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team. +293 print("Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.") +294 json_data = get_cfbd_games( +295 season=2018, +296 away_team="Ohio" +297 ) +298 print(json_data) +299 time.sleep(5) +300 +301 # Get 2022 college football games where one or more teams competing +302 # was a Football Championship Subdivision team. +303 print("Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.") +304 json_data = get_cfbd_games( +305 season=2018, +306 away_team="Ohio" +307 ) +308 print(json_data) +309 time.sleep(5) +310 +311 # Get game information for the +312 # 2021 American Athletic Confrence (AAC) Championship Game. +313 print("Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.") +314 json_data = get_cfbd_games( +315 season=2018, +316 game_id=401331162 +317 ) +318 print(json_data) +319 time.sleep(5) +320 +321 # You can also tell this function to just return the API call as +322 # a Dictionary (read: JSON) object. +323 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +324 json_data = get_cfbd_games( +325 season=2020, +326 week=10, +327 return_as_dict=True +328 ) +329 print(json_data) +330 +331 ``` +332 Returns +333 ---------- +334 A pandas `DataFrame` object with college football game information, +335 or (if `return_as_dict` is set to `True`) +336 a dictionary object with college football game information. +337 """ +338 +339 now = datetime.now() +340 cfb_games_df = pd.DataFrame() +341 row_df = pd.DataFrame() +342 url = "https://api.collegefootballdata.com/games" +343 +344 ######################################################################################################################################################################################################## +345 +346 if api_key != None: +347 real_api_key = api_key +348 del api_key +349 else: +350 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +351 +352 if real_api_key == "tigersAreAwsome": +353 raise ValueError( +354 "You actually need to change `cfbd_key` to your CFBD API key.") +355 elif "Bearer " in real_api_key: +356 pass +357 elif "Bearer" in real_api_key: +358 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +359 else: +360 real_api_key = "Bearer " + real_api_key +361 +362 if season == None: +363 # This should never happen without user tampering, but if it does, +364 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +365 raise SystemError( +366 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +367 " and the function got to this point in the code." + +368 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +369 "https://github.com/armstjc/cfbd-json-py/issues" +370 ) +371 elif season > now.year: +372 raise ValueError(f"`season` cannot be greater than {season}.") +373 elif season < 1869: +374 raise ValueError(f"`season` cannot be less than 1869.") +375 +376 if season_type != "regular" and season_type != "postseason": +377 raise ValueError( +378 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +379 +380 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ +381 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": +382 pass +383 else: +384 raise ValueError( +385 "An invalid NCAA Division was inputted when calling this function." + +386 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + +387 f"\n\nYou entered: \n{ncaa_division}" +388 ) +389 +390 # URL builder +391 ######################################################################################################################################################################################################## +392 +393 # Required by API +394 url += f"?seasonType={season_type}" +395 +396 if game_id != None: +397 url += f"&year={season}" +398 url += f"&id={game_id}" +399 +400 if team != None or home_team != None \ +401 or away_team != None or conference_abv != None \ +402 or week != None: +403 logging.warning( +404 "When calling `cfbd_json_py.games.get_cfbd_games()`, " + +405 "and setting `game_id` to a non-null value, " + +406 "only `season` and `game_id` are considered " + +407 "when calling the CFBD API." +408 ) +409 +410 else: +411 url += f"&year={season}" +412 +413 # Optional for the API +414 if week != None: +415 url += f"&week={week}" +416 +417 if team != None: +418 url += f"&team={team}" +419 +420 if home_team != None: +421 url += f"&home={home_team}" +422 +423 if away_team != None: +424 url += f"&away={away_team}" +425 +426 if conference_abv != None: +427 url += f"&conference={conference_abv}" +428 +429 if ncaa_division != None: +430 url += f"&division={ncaa_division}" +431 +432 headers = { +433 'Authorization': f'{real_api_key}', +434 'accept': 'application/json' +435 } +436 +437 response = requests.get(url, headers=headers) +438 +439 +440 if response.status_code == 200: +441 pass +442 elif response.status_code == 401: +443 raise ConnectionRefusedError( +444 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +445 ) +446 else: +447 raise ConnectionError( +448 f'Could not connect.\nHTTP Status code {response.status_code}' +449 ) +450 +451 json_data = response.json() +452 +453 if return_as_dict == True: +454 return json_data +455 +456 for game in tqdm(json_data): +457 g_id = game['id'] +458 row_df = pd.DataFrame( +459 { +460 "game_id": g_id +461 }, index=[0] +462 ) +463 del g_id +464 +465 row_df['season'] = game['season'] +466 row_df['week'] = game['week'] +467 row_df['season_type'] = game['season_type'] +468 row_df['start_date'] = game['start_date'] +469 row_df['start_time_tbd'] = game['start_time_tbd'] +470 row_df['is_game_completed'] = game['completed'] +471 row_df['is_neutral_site'] = game['neutral_site'] +472 row_df['is_conference_game'] = game['conference_game'] +473 row_df['game_attendance'] = game['attendance'] +474 row_df['venue_id'] = game['venue_id'] +475 row_df['venue_name'] = game['venue'] +476 row_df['home_id'] = game['home_id'] +477 row_df['home_team'] = game['home_team'] +478 row_df['home_conference'] = game['home_conference'] +479 row_df['home_division'] = game['home_division'] +480 row_df['home_points'] = game['home_points'] +481 row_df['home_line_scores'] = str(game['home_line_scores']) +482 row_df['home_post_win_prob'] = game['home_post_win_prob'] +483 row_df['home_pregame_elo'] = game['home_pregame_elo'] +484 row_df['home_postgame_elo'] = game['home_postgame_elo'] +485 row_df['away_id'] = game['away_id'] +486 row_df['away_team'] = game['away_team'] +487 row_df['away_conference'] = game['away_conference'] +488 row_df['away_division'] = game['away_division'] +489 row_df['away_points'] = game['away_points'] +490 row_df['away_line_scores'] = str(game['away_line_scores']) +491 row_df['away_post_win_prob'] = game['away_post_win_prob'] +492 row_df['away_pregame_elo'] = game['away_pregame_elo'] +493 row_df['away_postgame_elo'] = game['away_postgame_elo'] +494 row_df['excitement_index'] = game['excitement_index'] +495 row_df['highlights'] = game['highlights'] +496 row_df['notes'] = game['notes'] +497 +498 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +499 del row_df +500 +501 if len(cfb_games_df) == 0: +502 logging.error( +503 "The CFBD API accepted your inputs, " + +504 "but found no data within your specified input paramaters." + +505 " Please double check your input paramaters." +506 ) +507 +508 return cfb_games_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -4441,289 +4441,289 @@Returns
-512def get_cfbd_team_records( -513 api_key: str = None, -514 api_key_dir: str = None, -515 season: int = None, -516 team: str = None, # Must specify either a year or team -517 conference_abv: str = None, -518 return_as_dict: bool = False): -519 """ -520 Get a team, or multiple team's record (wins, losses, ties) for home games, away games, -521 confrence games, and the team's record for that season. -522 -523 Parameters -524 ---------- -525 -526 `api_key` (str, optional): -527 Semi-optional argument. -528 If `api_key` is null, this function will attempt to load a CFBD API key -529 from the python environment, or from a file on this computer. -530 If `api_key` is not null, this function will automatically assume that the -531 inputted `api_key` is a valid CFBD API key. -532 -533 `api_key_dir` (str, optional): -534 Optional argument. -535 If `api_key` is set to a string non-empty string, this variable is ignored. -536 If `api_key_dir` is null, and `api_key` is null, -537 this function will try to find a CFBD API key file in this user's home directory. -538 If `api_key_dir` is set to a string, and `api_key` is null, -539 this function will assume that `api_key_dir` is a directory, -540 and will try to find a CFBD API key file in that directory. -541 -542 `season` (int, optional): -543 Semi-optional argument. -544 Specifies the season you want CFB team records data from. -545 You MUST set `season` or `team` to a non-null value for -546 this function to work. If you don't, a `ValueError()` -547 will be raised. -548 -549 `team` (str, optional): -550 Semi-ptional argument. -551 If you only want CFB team records data for a specific team, -552 set `team` to the name of the team you want CFB drive data from. -553 You MUST set `season` or `team` to a non-null value for -554 this function to work. If you don't, a `ValueError()` -555 will be raised. -556 -557 `conference_abv` (str, optional): -558 Optional argument. -559 If you only want CFB team records data from games -560 involving teams from a specific confrence, -561 set `conference_abv` to the abbreviation -562 of the conference you want CFB team records data from. -563 For a list of confrences, -564 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` -565 function. -566 -567 `return_as_dict` (bool, semi-optional): -568 Semi-optional argument. -569 If you want this function to return the data as a dictionary (read: JSON object), -570 instead of a pandas `DataFrame` object, -571 set `return_as_dict` to `True`. -572 -573 Usage -574 ---------- -575 ``` -576 import time -577 -578 from cfbd_json_py.games import get_cfbd_team_records +@@ -4741,7 +4741,7 @@511def get_cfbd_team_records( +512 api_key: str = None, +513 api_key_dir: str = None, +514 season: int = None, +515 team: str = None, # Must specify either a year or team +516 conference_abv: str = None, +517 return_as_dict: bool = False): +518 """ +519 Get a team, or multiple team's record (wins, losses, ties) for home games, away games, +520 confrence games, and the team's record for that season. +521 +522 Parameters +523 ---------- +524 +525 `api_key` (str, optional): +526 Semi-optional argument. +527 If `api_key` is null, this function will attempt to load a CFBD API key +528 from the python environment, or from a file on this computer. +529 If `api_key` is not null, this function will automatically assume that the +530 inputted `api_key` is a valid CFBD API key. +531 +532 `api_key_dir` (str, optional): +533 Optional argument. +534 If `api_key` is set to am empty string, this variable is ignored. +535 If `api_key_dir` is null, and `api_key` is null, +536 this function will try to find a CFBD API key file in this user's home directory. +537 If `api_key_dir` is set to a string, and `api_key` is null, +538 this function will assume that `api_key_dir` is a directory, +539 and will try to find a CFBD API key file in that directory. +540 +541 `season` (int, optional): +542 Semi-optional argument. +543 Specifies the season you want CFB team records data from. +544 You MUST set `season` or `team` to a non-null value for +545 this function to work. If you don't, a `ValueError()` +546 will be raised. +547 +548 `team` (str, optional): +549 Semi-ptional argument. +550 If you only want CFB team records data for a specific team, +551 set `team` to the name of the team you want CFB drive data from. +552 You MUST set `season` or `team` to a non-null value for +553 this function to work. If you don't, a `ValueError()` +554 will be raised. +555 +556 `conference_abv` (str, optional): +557 Optional argument. +558 If you only want CFB team records data from games +559 involving teams from a specific confrence, +560 set `conference_abv` to the abbreviation +561 of the conference you want CFB team records data from. +562 For a list of confrences, +563 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +564 function. +565 +566 `return_as_dict` (bool, semi-optional): +567 Semi-optional argument. +568 If you want this function to return the data as a dictionary (read: JSON object), +569 instead of a pandas `DataFrame` object, +570 set `return_as_dict` to `True`. +571 +572 Usage +573 ---------- +574 ``` +575 import time +576 +577 from cfbd_json_py.games import get_cfbd_team_records +578 579 -580 -581 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -582 -583 if cfbd_key != "tigersAreAwsome": -584 print("Using the user's API key declared in this script for this example.") -585 -586 # Get CFB team records from the 2020 CFB season. -587 print("Get CFB team records from the 2020 CFB season.") -588 json_data = get_cfbd_team_records( -589 api_key=cfbd_key, -590 season=2020 -591 ) -592 print(json_data) -593 time.sleep(5) -594 -595 # Get team records from football teams fielded by the University of Cincinnati. -596 print("Get team records from football teams fielded by the University of Cincinnati.") -597 json_data = get_cfbd_team_records( -598 api_key=cfbd_key, -599 team="Cincinnati" -600 ) -601 print(json_data) -602 time.sleep(5) -603 -604 # Get team records from football teams that played in the Big 10 (B1G) Confrence -605 # in the 2017 CFB season -606 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") -607 json_data = get_cfbd_team_records( -608 api_key=cfbd_key, -609 season=2017, -610 conference_abv="B1G" -611 ) -612 print(json_data) -613 time.sleep(5) +580 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +581 +582 if cfbd_key != "tigersAreAwsome": +583 print("Using the user's API key declared in this script for this example.") +584 +585 # Get CFB team records from the 2020 CFB season. +586 print("Get CFB team records from the 2020 CFB season.") +587 json_data = get_cfbd_team_records( +588 api_key=cfbd_key, +589 season=2020 +590 ) +591 print(json_data) +592 time.sleep(5) +593 +594 # Get team records from football teams fielded by the University of Cincinnati. +595 print("Get team records from football teams fielded by the University of Cincinnati.") +596 json_data = get_cfbd_team_records( +597 api_key=cfbd_key, +598 team="Cincinnati" +599 ) +600 print(json_data) +601 time.sleep(5) +602 +603 # Get team records from football teams that played in the Big 10 (B1G) Confrence +604 # in the 2017 CFB season +605 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") +606 json_data = get_cfbd_team_records( +607 api_key=cfbd_key, +608 season=2017, +609 conference_abv="B1G" +610 ) +611 print(json_data) +612 time.sleep(5) +613 614 -615 -616 # You can also tell this function to just return the API call as -617 # a Dictionary (read: JSON) object. -618 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -619 json_data = get_cfbd_team_records( -620 season=2020, -621 api_key=cfbd_key, -622 return_as_dict=True -623 ) -624 print(json_data) -625 -626 else: -627 # Alternatively, if the CFBD API key exists in this python environment, -628 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -629 # you could just call these functions directly, without setting the API key -630 # in the script. -631 print("Using the user's API key suposedly loaded into this python environment for this example.") -632 -633 # Get CFB team records from the 2020 CFB season. -634 print("Get CFB team records from the 2020 CFB season.") -635 json_data = get_cfbd_team_records( -636 season=2020 -637 ) -638 print(json_data) -639 time.sleep(5) -640 -641 # Get team records from football teams fielded by the University of Cincinnati. -642 print("Get team records from football teams fielded by the University of Cincinnati.") -643 json_data = get_cfbd_team_records( -644 team="Cincinnati" -645 ) -646 print(json_data) -647 time.sleep(5) -648 -649 # Get team records from football teams that played in the Big 10 (B1G) Confrence -650 # in the 2017 CFB season -651 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") -652 json_data = get_cfbd_team_records( -653 season=2017, -654 conference_abv="B1G" -655 ) -656 print(json_data) -657 time.sleep(5) -658 -659 # You can also tell this function to just return the API call as -660 # a Dictionary (read: JSON) object. -661 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -662 json_data = get_cfbd_team_records( -663 season=2020, -664 return_as_dict=True -665 ) -666 print(json_data) -667 -668 ``` -669 -670 Returns -671 ---------- -672 A pandas `DataFrame` object with CFB team records data, -673 or (if `return_as_dict` is set to `True`) -674 a dictionary object with CFB team records data. -675 -676 """ -677 -678 now = datetime.now() -679 cfb_records_df = pd.DataFrame() -680 row_df = pd.DataFrame() -681 url = "https://api.collegefootballdata.com/records" -682 -683 ######################################################################################################################################################################################################## -684 -685 if api_key != None: -686 real_api_key = api_key -687 del api_key -688 else: -689 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -690 -691 if real_api_key == "tigersAreAwsome": -692 raise ValueError( -693 "You actually need to change `cfbd_key` to your CFBD API key.") -694 elif "Bearer " in real_api_key: -695 pass -696 elif "Bearer" in real_api_key: -697 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -698 else: -699 real_api_key = "Bearer " + real_api_key -700 -701 if season != None and season > now.year: -702 raise ValueError(f"`season` cannot be greater than {season}.") -703 elif season != None and season < 1869: -704 raise ValueError(f"`season` cannot be less than 1869.") -705 -706 if season == None and team == None: -707 raise ValueError( -708 f"If you call `cfbd_json_py.games.get_cfbd_team_records()`, you must specifiy at least a team or CFB season.") -709 -710 # URL builder -711 ######################################################################################################################################################################################################## -712 url_elements = 0 -713 -714 if season != None and url_elements == 0: -715 url += f"?year={season}" -716 url_elements += 1 -717 elif season != None: -718 url += f"&year={season}" -719 url_elements += 1 -720 -721 if team != None and url_elements == 0: -722 url += f"?team={team}" -723 url_elements += 1 -724 elif team != None: -725 url += f"&team={team}" -726 url_elements += 1 -727 -728 if conference_abv != None and url_elements == 0: -729 url += f"?conference={conference_abv}" -730 url_elements += 1 -731 elif conference_abv != None: -732 url += f"&conference={conference_abv}" -733 url_elements += 1 -734 -735 headers = { -736 'Authorization': f'{real_api_key}', -737 'accept': 'application/json' -738 } -739 -740 response = requests.get(url, headers=headers) -741 time.sleep(0.1) -742 -743 if response.status_code == 200: -744 pass -745 elif response.status_code == 401: -746 raise ConnectionRefusedError( -747 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -748 ) -749 else: -750 raise ConnectionError( -751 f'Could not connect.\nHTTP Status code {response.status_code}' -752 ) -753 -754 json_data = response.json() -755 -756 if return_as_dict == True: -757 return json_data -758 -759 for team in json_data: -760 team_year = team['year'] -761 row_df = pd.DataFrame( -762 {"season": team_year}, -763 index=[0] -764 ) -765 row_df['team_id'] = team['teamId'] -766 row_df['team_name'] = team['team'] -767 row_df['conference_name'] = team['conference'] -768 if team['division'] == "" or team['division'] == None: -769 row_df['conference_division'] = None -770 else: -771 row_df['conference_division'] = team['division'] -772 -773 row_df['expected_wins'] = team['expectedWins'] -774 row_df['total_games'] = team['total']['games'] -775 row_df['total_wins'] = team['total']['wins'] -776 row_df['total_losses'] = team['total']['losses'] -777 row_df['total_ties'] = team['total']['ties'] -778 row_df['conference_games'] = team['conferenceGames']['games'] -779 row_df['conference_wins'] = team['conferenceGames']['wins'] -780 row_df['conference_losses'] = team['conferenceGames']['losses'] -781 row_df['conference_ties'] = team['conferenceGames']['ties'] -782 row_df['home_games'] = team['homeGames']['games'] -783 row_df['home_wins'] = team['homeGames']['wins'] -784 row_df['home_losses'] = team['homeGames']['losses'] -785 row_df['home_ties'] = team['homeGames']['ties'] -786 row_df['away_games'] = team['awayGames']['games'] -787 row_df['away_wins'] = team['awayGames']['wins'] -788 row_df['away_losses'] = team['awayGames']['losses'] -789 row_df['away_ties'] = team['awayGames']['ties'] -790 -791 cfb_records_df = pd.concat([cfb_records_df, row_df], ignore_index=True) -792 del row_df -793 -794 return cfb_records_df +615 # You can also tell this function to just return the API call as +616 # a Dictionary (read: JSON) object. +617 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +618 json_data = get_cfbd_team_records( +619 season=2020, +620 api_key=cfbd_key, +621 return_as_dict=True +622 ) +623 print(json_data) +624 +625 else: +626 # Alternatively, if the CFBD API key exists in this python environment, +627 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +628 # you could just call these functions directly, without setting the API key +629 # in the script. +630 print("Using the user's API key suposedly loaded into this python environment for this example.") +631 +632 # Get CFB team records from the 2020 CFB season. +633 print("Get CFB team records from the 2020 CFB season.") +634 json_data = get_cfbd_team_records( +635 season=2020 +636 ) +637 print(json_data) +638 time.sleep(5) +639 +640 # Get team records from football teams fielded by the University of Cincinnati. +641 print("Get team records from football teams fielded by the University of Cincinnati.") +642 json_data = get_cfbd_team_records( +643 team="Cincinnati" +644 ) +645 print(json_data) +646 time.sleep(5) +647 +648 # Get team records from football teams that played in the Big 10 (B1G) Confrence +649 # in the 2017 CFB season +650 print("Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season") +651 json_data = get_cfbd_team_records( +652 season=2017, +653 conference_abv="B1G" +654 ) +655 print(json_data) +656 time.sleep(5) +657 +658 # You can also tell this function to just return the API call as +659 # a Dictionary (read: JSON) object. +660 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +661 json_data = get_cfbd_team_records( +662 season=2020, +663 return_as_dict=True +664 ) +665 print(json_data) +666 +667 ``` +668 +669 Returns +670 ---------- +671 A pandas `DataFrame` object with CFB team records data, +672 or (if `return_as_dict` is set to `True`) +673 a dictionary object with CFB team records data. +674 +675 """ +676 +677 now = datetime.now() +678 cfb_records_df = pd.DataFrame() +679 row_df = pd.DataFrame() +680 url = "https://api.collegefootballdata.com/records" +681 +682 ######################################################################################################################################################################################################## +683 +684 if api_key != None: +685 real_api_key = api_key +686 del api_key +687 else: +688 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +689 +690 if real_api_key == "tigersAreAwsome": +691 raise ValueError( +692 "You actually need to change `cfbd_key` to your CFBD API key.") +693 elif "Bearer " in real_api_key: +694 pass +695 elif "Bearer" in real_api_key: +696 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +697 else: +698 real_api_key = "Bearer " + real_api_key +699 +700 if season != None and season > now.year: +701 raise ValueError(f"`season` cannot be greater than {season}.") +702 elif season != None and season < 1869: +703 raise ValueError(f"`season` cannot be less than 1869.") +704 +705 if season == None and team == None: +706 raise ValueError( +707 f"If you call `cfbd_json_py.games.get_cfbd_team_records()`, you must specifiy at least a team or CFB season.") +708 +709 # URL builder +710 ######################################################################################################################################################################################################## +711 url_elements = 0 +712 +713 if season != None and url_elements == 0: +714 url += f"?year={season}" +715 url_elements += 1 +716 elif season != None: +717 url += f"&year={season}" +718 url_elements += 1 +719 +720 if team != None and url_elements == 0: +721 url += f"?team={team}" +722 url_elements += 1 +723 elif team != None: +724 url += f"&team={team}" +725 url_elements += 1 +726 +727 if conference_abv != None and url_elements == 0: +728 url += f"?conference={conference_abv}" +729 url_elements += 1 +730 elif conference_abv != None: +731 url += f"&conference={conference_abv}" +732 url_elements += 1 +733 +734 headers = { +735 'Authorization': f'{real_api_key}', +736 'accept': 'application/json' +737 } +738 +739 response = requests.get(url, headers=headers) +740 +741 +742 if response.status_code == 200: +743 pass +744 elif response.status_code == 401: +745 raise ConnectionRefusedError( +746 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +747 ) +748 else: +749 raise ConnectionError( +750 f'Could not connect.\nHTTP Status code {response.status_code}' +751 ) +752 +753 json_data = response.json() +754 +755 if return_as_dict == True: +756 return json_data +757 +758 for team in json_data: +759 team_year = team['year'] +760 row_df = pd.DataFrame( +761 {"season": team_year}, +762 index=[0] +763 ) +764 row_df['team_id'] = team['teamId'] +765 row_df['team_name'] = team['team'] +766 row_df['conference_name'] = team['conference'] +767 if team['division'] == "" or team['division'] == None: +768 row_df['conference_division'] = None +769 else: +770 row_df['conference_division'] = team['division'] +771 +772 row_df['expected_wins'] = team['expectedWins'] +773 row_df['total_games'] = team['total']['games'] +774 row_df['total_wins'] = team['total']['wins'] +775 row_df['total_losses'] = team['total']['losses'] +776 row_df['total_ties'] = team['total']['ties'] +777 row_df['conference_games'] = team['conferenceGames']['games'] +778 row_df['conference_wins'] = team['conferenceGames']['wins'] +779 row_df['conference_losses'] = team['conferenceGames']['losses'] +780 row_df['conference_ties'] = team['conferenceGames']['ties'] +781 row_df['home_games'] = team['homeGames']['games'] +782 row_df['home_wins'] = team['homeGames']['wins'] +783 row_df['home_losses'] = team['homeGames']['losses'] +784 row_df['home_ties'] = team['homeGames']['ties'] +785 row_df['away_games'] = team['awayGames']['games'] +786 row_df['away_wins'] = team['awayGames']['wins'] +787 row_df['away_losses'] = team['awayGames']['losses'] +788 row_df['away_ties'] = team['awayGames']['ties'] +789 +790 cfb_records_df = pd.concat([cfb_records_df, row_df], ignore_index=True) +791 del row_df +792 +793 return cfb_records_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -4895,195 +4895,195 @@Returns
-797def get_cfbd_season_weeks( -798 season: int, -799 api_key: str = None, -800 api_key_dir: str = None, -801 return_as_dict: bool = False): -802 """ -803 Retrives a list of weeks that occured in a given CFB season. -804 -805 Parameters -806 ---------- -807 `season` (int, mandatory): -808 Required argument. -809 Specifies the season you want a list of weeks that occured in a given CFB season information from. -810 This must be specified, otherwise this package, and by extension -811 the CFBD API, will not accept the request to get a list of weeks that occured in a given CFB season information. -812 -813 `api_key` (str, optional): -814 Semi-optional argument. -815 If `api_key` is null, this function will attempt to load a CFBD API key -816 from the python environment, or from a file on this computer. -817 If `api_key` is not null, this function will automatically assume that the -818 inputted `api_key` is a valid CFBD API key. -819 -820 `api_key_dir` (str, optional): -821 Optional argument. -822 If `api_key` is set to a string non-empty string, this variable is ignored. -823 If `api_key_dir` is null, and `api_key` is null, -824 this function will try to find a CFBD API key file in this user's home directory. -825 If `api_key_dir` is set to a string, and `api_key` is null, -826 this function will assume that `api_key_dir` is a directory, -827 and will try to find a CFBD API key file in that directory. -828 -829 `return_as_dict` (bool, semi-optional): -830 Semi-optional argument. -831 If you want this function to return the data as a dictionary (read: JSON object), -832 instead of a pandas `DataFrame` object, -833 set `return_as_dict` to `True`. +@@ -5106,7 +5106,7 @@796def get_cfbd_season_weeks( +797 season: int, +798 api_key: str = None, +799 api_key_dir: str = None, +800 return_as_dict: bool = False): +801 """ +802 Retrives a list of weeks that occured in a given CFB season. +803 +804 Parameters +805 ---------- +806 `season` (int, mandatory): +807 Required argument. +808 Specifies the season you want a list of weeks that occured in a given CFB season information from. +809 This must be specified, otherwise this package, and by extension +810 the CFBD API, will not accept the request to get a list of weeks that occured in a given CFB season information. +811 +812 `api_key` (str, optional): +813 Semi-optional argument. +814 If `api_key` is null, this function will attempt to load a CFBD API key +815 from the python environment, or from a file on this computer. +816 If `api_key` is not null, this function will automatically assume that the +817 inputted `api_key` is a valid CFBD API key. +818 +819 `api_key_dir` (str, optional): +820 Optional argument. +821 If `api_key` is set to am empty string, this variable is ignored. +822 If `api_key_dir` is null, and `api_key` is null, +823 this function will try to find a CFBD API key file in this user's home directory. +824 If `api_key_dir` is set to a string, and `api_key` is null, +825 this function will assume that `api_key_dir` is a directory, +826 and will try to find a CFBD API key file in that directory. +827 +828 `return_as_dict` (bool, semi-optional): +829 Semi-optional argument. +830 If you want this function to return the data as a dictionary (read: JSON object), +831 instead of a pandas `DataFrame` object, +832 set `return_as_dict` to `True`. +833 834 -835 -836 Usage -837 ---------- -838 ``` -839 import time -840 -841 from cfbd_json_py.games import get_cfbd_season_weeks +835 Usage +836 ---------- +837 ``` +838 import time +839 +840 from cfbd_json_py.games import get_cfbd_season_weeks +841 842 -843 -844 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -845 -846 if cfbd_key != "tigersAreAwsome": -847 print("Using the user's API key declared in this script for this example.") -848 -849 # Get a list of weeks in the 2020 CFB season. -850 print("Get a list of weeks in the 2020 CFB season.") -851 json_data = get_cfbd_season_weeks( -852 api_key=cfbd_key, -853 season=2020 -854 ) -855 print(json_data) -856 time.sleep(5) +843 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +844 +845 if cfbd_key != "tigersAreAwsome": +846 print("Using the user's API key declared in this script for this example.") +847 +848 # Get a list of weeks in the 2020 CFB season. +849 print("Get a list of weeks in the 2020 CFB season.") +850 json_data = get_cfbd_season_weeks( +851 api_key=cfbd_key, +852 season=2020 +853 ) +854 print(json_data) +855 time.sleep(5) +856 857 -858 -859 # You can also tell this function to just return the API call as -860 # a Dictionary (read: JSON) object. -861 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -862 json_data = get_cfbd_season_weeks( -863 season=2020, -864 api_key=cfbd_key, -865 return_as_dict=True -866 ) -867 print(json_data) -868 -869 else: -870 # Alternatively, if the CFBD API key exists in this python environment, -871 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -872 # you could just call these functions directly, without setting the API key -873 # in the script. -874 print("Using the user's API key suposedly loaded into this python environment for this example.") -875 -876 # Get a list of weeks in the 2020 CFB season. -877 print("Get a list of weeks in the 2020 CFB season.") -878 json_data = get_cfbd_season_weeks( -879 season=2020 -880 ) -881 print(json_data) -882 time.sleep(5) +858 # You can also tell this function to just return the API call as +859 # a Dictionary (read: JSON) object. +860 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +861 json_data = get_cfbd_season_weeks( +862 season=2020, +863 api_key=cfbd_key, +864 return_as_dict=True +865 ) +866 print(json_data) +867 +868 else: +869 # Alternatively, if the CFBD API key exists in this python environment, +870 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +871 # you could just call these functions directly, without setting the API key +872 # in the script. +873 print("Using the user's API key suposedly loaded into this python environment for this example.") +874 +875 # Get a list of weeks in the 2020 CFB season. +876 print("Get a list of weeks in the 2020 CFB season.") +877 json_data = get_cfbd_season_weeks( +878 season=2020 +879 ) +880 print(json_data) +881 time.sleep(5) +882 883 -884 -885 # You can also tell this function to just return the API call as -886 # a Dictionary (read: JSON) object. -887 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -888 json_data = get_cfbd_season_weeks( -889 season=2020, -890 return_as_dict=True -891 ) -892 print(json_data) -893 -894 ``` -895 -896 Returns -897 ---------- -898 A pandas `DataFrame` object with a list of valid weeks in a given CFB season, -899 or (if `return_as_dict` is set to `True`) -900 a dictionary object with a list of valid weeks in a given CFB season. +884 # You can also tell this function to just return the API call as +885 # a Dictionary (read: JSON) object. +886 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +887 json_data = get_cfbd_season_weeks( +888 season=2020, +889 return_as_dict=True +890 ) +891 print(json_data) +892 +893 ``` +894 +895 Returns +896 ---------- +897 A pandas `DataFrame` object with a list of valid weeks in a given CFB season, +898 or (if `return_as_dict` is set to `True`) +899 a dictionary object with a list of valid weeks in a given CFB season. +900 901 -902 -903 """ -904 -905 now = datetime.now() -906 cfb_weeks_df = pd.DataFrame() -907 row_df = pd.DataFrame() -908 url = "https://api.collegefootballdata.com/calendar" -909 -910 ######################################################################################################################################################################################################## -911 -912 if api_key != None: -913 real_api_key = api_key -914 del api_key -915 else: -916 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -917 -918 if real_api_key == "tigersAreAwsome": -919 raise ValueError( -920 "You actually need to change `cfbd_key` to your CFBD API key.") -921 elif "Bearer " in real_api_key: -922 pass -923 elif "Bearer" in real_api_key: -924 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -925 else: -926 real_api_key = "Bearer " + real_api_key -927 -928 if season == None: -929 # This should never happen without user tampering, but if it does, -930 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -931 raise SystemError( -932 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + -933 " and the function got to this point in the code." + -934 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + -935 "https://github.com/armstjc/cfbd-json-py/issues" -936 ) -937 elif season > now.year: -938 raise ValueError(f"`season` cannot be greater than {season}.") -939 elif season < 1869: -940 raise ValueError(f"`season` cannot be less than 1869.") -941 -942 # URL builder -943 ######################################################################################################################################################################################################## -944 -945 # Required by API -946 url += f"?year={season}" -947 -948 headers = { -949 'Authorization': f'{real_api_key}', -950 'accept': 'application/json' -951 } -952 -953 response = requests.get(url, headers=headers) -954 time.sleep(0.1) -955 -956 if response.status_code == 200: -957 pass -958 elif response.status_code == 401: -959 raise ConnectionRefusedError( -960 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -961 ) -962 else: -963 raise ConnectionError( -964 f'Could not connect.\nHTTP Status code {response.status_code}' -965 ) -966 -967 json_data = response.json() -968 -969 if return_as_dict == True: -970 return json_data -971 -972 for week in json_data: -973 row_df = pd.DataFrame( -974 {"season": season}, -975 index=[0] -976 ) -977 row_df['week'] = week['week'] -978 row_df['season_type'] = week['seasonType'] -979 row_df['first_game_start'] = week['firstGameStart'] -980 row_df['last_game_start'] = week['lastGameStart'] -981 -982 cfb_weeks_df = pd.concat([cfb_weeks_df, row_df], ignore_index=True) -983 del row_df -984 -985 return cfb_weeks_df +902 """ +903 +904 now = datetime.now() +905 cfb_weeks_df = pd.DataFrame() +906 row_df = pd.DataFrame() +907 url = "https://api.collegefootballdata.com/calendar" +908 +909 ######################################################################################################################################################################################################## +910 +911 if api_key != None: +912 real_api_key = api_key +913 del api_key +914 else: +915 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +916 +917 if real_api_key == "tigersAreAwsome": +918 raise ValueError( +919 "You actually need to change `cfbd_key` to your CFBD API key.") +920 elif "Bearer " in real_api_key: +921 pass +922 elif "Bearer" in real_api_key: +923 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +924 else: +925 real_api_key = "Bearer " + real_api_key +926 +927 if season == None: +928 # This should never happen without user tampering, but if it does, +929 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +930 raise SystemError( +931 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +932 " and the function got to this point in the code." + +933 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +934 "https://github.com/armstjc/cfbd-json-py/issues" +935 ) +936 elif season > now.year: +937 raise ValueError(f"`season` cannot be greater than {season}.") +938 elif season < 1869: +939 raise ValueError(f"`season` cannot be less than 1869.") +940 +941 # URL builder +942 ######################################################################################################################################################################################################## +943 +944 # Required by API +945 url += f"?year={season}" +946 +947 headers = { +948 'Authorization': f'{real_api_key}', +949 'accept': 'application/json' +950 } +951 +952 response = requests.get(url, headers=headers) +953 +954 +955 if response.status_code == 200: +956 pass +957 elif response.status_code == 401: +958 raise ConnectionRefusedError( +959 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +960 ) +961 else: +962 raise ConnectionError( +963 f'Could not connect.\nHTTP Status code {response.status_code}' +964 ) +965 +966 json_data = response.json() +967 +968 if return_as_dict == True: +969 return json_data +970 +971 for week in json_data: +972 row_df = pd.DataFrame( +973 {"season": season}, +974 index=[0] +975 ) +976 row_df['week'] = week['week'] +977 row_df['season_type'] = week['seasonType'] +978 row_df['first_game_start'] = week['firstGameStart'] +979 row_df['last_game_start'] = week['lastGameStart'] +980 +981 cfb_weeks_df = pd.concat([cfb_weeks_df, row_df], ignore_index=True) +982 del row_df +983 +984 return cfb_weeks_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -5198,438 +5198,438 @@Returns
-988def get_cfbd_game_media_info( - 989 season: int, - 990 api_key: str = None, - 991 api_key_dir: str = None, - 992 season_type: str = "regular", # "regular", "postseason", or "both" - 993 week: int = None, - 994 team: str = None, - 995 conference_abv: str = None, - 996 media_type: str = "all", # "tv", "radio", "web", "ppv", or "mobile" - 997 ncaa_division: str = "fbs", - 998 return_as_dict: bool = False): - 999 """ -1000 Gets known media information for CFB games in a given CFB season. -1001 -1002 Parameters -1003 ---------- -1004 `season` (int, mandatory): -1005 Required argument. -1006 Specifies the season you want CFB media information from. -1007 This must be specified, otherwise this package, and by extension -1008 the CFBD API, will not accept the request to get CFB media information. -1009 -1010 `api_key` (str, optional): -1011 Semi-optional argument. -1012 If `api_key` is null, this function will attempt to load a CFBD API key -1013 from the python environment, or from a file on this computer. -1014 If `api_key` is not null, this function will automatically assume that the -1015 inputted `api_key` is a valid CFBD API key. -1016 -1017 `api_key_dir` (str, optional): -1018 Optional argument. -1019 If `api_key` is set to a string non-empty string, this variable is ignored. -1020 If `api_key_dir` is null, and `api_key` is null, -1021 this function will try to find a CFBD API key file in this user's home directory. -1022 If `api_key_dir` is set to a string, and `api_key` is null, -1023 this function will assume that `api_key_dir` is a directory, -1024 and will try to find a CFBD API key file in that directory. -1025 -1026 `season_type` (str, semi-optional): -1027 Semi-optional argument. -1028 By defualt, this will be set to "regular", for the CFB regular season. -1029 If you want CFB media information for non-regular season games, -1030 set `season_type` to "postseason". -1031 If you want both "regular" and "postseason" games retunred, -1032 set `season_type` to "both" -1033 If `season_type` is set to anything but "regular" or "postseason", -1034 a `ValueError()` will be raised. -1035 -1036 `week` (int, optional): -1037 Optional argument. -1038 If `week` is set to an integer, this function will attempt -1039 to load CFB media information from games in that season, and in that week. -1040 -1041 `team` (str, optional): -1042 Optional argument. -1043 If you only want CFB media information for a team, -1044 regardless if they are the home/away team, -1045 set `team` to the name of the team you want CFB media information from. -1046 -1047 `conference_abv` (str, optional): -1048 Optional argument. -1049 If you only want media information from games -1050 involving teams a specific confrence, -1051 set `conference_abv` to the abbreviation -1052 of the conference you want game information from. -1053 -1054 `media_type` (str, semi-optional): -1055 Semi-optional argument. -1056 If you only want game broadcast information for a specific type of broadcast, -1057 set this to the type of broadcast. -1058 -1059 Valid inputs are: -1060 - `all` (default): Returns all games, and all known broadcasters for those games. -1061 - `tv`: Returns all known TV broadcasters for CFB games in the requested timeframe. -1062 - `radio`: Returns all known radio broadcasters -1063 for CFB games in the requested timeframe. -1064 - `web`: Returns all known web broadcasts (like ESPN+) -1065 for CFB games in the requested timeframe. -1066 - `ppv`: Returns all known Pay Per View (PPV) broadcasts -1067 for CFB games in the requested timeframe. -1068 - `mobile`: Returns all known broadcasters that only broadcasted -1069 games on mobile devices (?) -1070 -1071 `ncaa_division` (str, semi-optional): -1072 Semi-optional argument. -1073 By default, `ncaa_division` will be set to "fbs", -1074 short for the Football Bowl Subdivision (FBS), -1075 formerly known as D1-A (read as "division one single A"), -1076 the highest level in the NCAA football pyramid, -1077 where teams can scolarship up to 85 players -1078 on their football team soley for athletic ability, -1079 and often have the largest athletics budgets -1080 within the NCAA. -1081 -1082 Other valid inputs are: -1083 - "fcs": Football Championship Subdivision (FCS), -1084 formerly known as D1-AA (read as "division one double A"). -1085 An FCS school is still in the 1st division of the NCAA, -1086 making them elligable for the March Madness tournament, -1087 but may not have the resources to compete at the FBS level -1088 at this time. FCS schools are limited to 63 athletic scolarships -1089 for football. -1090 - "ii": NCAA Division II. Schools in this and D3 are not -1091 elligable for the March Madness tournament, -1092 and are limited to 36 athletic scolarships for their football team. -1093 - "iii": NCAA Division III. The largest single division within the -1094 NCAA football pyramid. -1095 D3 schools have the distinction of being part of -1096 the only NCAA division that cannot give out scolarships soley -1097 for athletic ability. -1098 -1099 `return_as_dict` (bool, semi-optional): -1100 Semi-optional argument. -1101 If you want this function to return the data as a dictionary (read: JSON object), -1102 instead of a pandas `DataFrame` object, -1103 set `return_as_dict` to `True`. -1104 -1105 Usage -1106 ---------- -1107 ``` -1108 import time -1109 -1110 from cfbd_json_py.games import get_cfbd_game_media_info +@@ -5652,7 +5652,7 @@987def get_cfbd_game_media_info( + 988 season: int, + 989 api_key: str = None, + 990 api_key_dir: str = None, + 991 season_type: str = "regular", # "regular", "postseason", or "both" + 992 week: int = None, + 993 team: str = None, + 994 conference_abv: str = None, + 995 media_type: str = "all", # "tv", "radio", "web", "ppv", or "mobile" + 996 ncaa_division: str = "fbs", + 997 return_as_dict: bool = False): + 998 """ + 999 Gets known media information for CFB games in a given CFB season. +1000 +1001 Parameters +1002 ---------- +1003 `season` (int, mandatory): +1004 Required argument. +1005 Specifies the season you want CFB media information from. +1006 This must be specified, otherwise this package, and by extension +1007 the CFBD API, will not accept the request to get CFB media information. +1008 +1009 `api_key` (str, optional): +1010 Semi-optional argument. +1011 If `api_key` is null, this function will attempt to load a CFBD API key +1012 from the python environment, or from a file on this computer. +1013 If `api_key` is not null, this function will automatically assume that the +1014 inputted `api_key` is a valid CFBD API key. +1015 +1016 `api_key_dir` (str, optional): +1017 Optional argument. +1018 If `api_key` is set to am empty string, this variable is ignored. +1019 If `api_key_dir` is null, and `api_key` is null, +1020 this function will try to find a CFBD API key file in this user's home directory. +1021 If `api_key_dir` is set to a string, and `api_key` is null, +1022 this function will assume that `api_key_dir` is a directory, +1023 and will try to find a CFBD API key file in that directory. +1024 +1025 `season_type` (str, semi-optional): +1026 Semi-optional argument. +1027 By defualt, this will be set to "regular", for the CFB regular season. +1028 If you want CFB media information for non-regular season games, +1029 set `season_type` to "postseason". +1030 If you want both "regular" and "postseason" games retunred, +1031 set `season_type` to "both" +1032 If `season_type` is set to anything but "regular" or "postseason", +1033 a `ValueError()` will be raised. +1034 +1035 `week` (int, optional): +1036 Optional argument. +1037 If `week` is set to an integer, this function will attempt +1038 to load CFB media information from games in that season, and in that week. +1039 +1040 `team` (str, optional): +1041 Optional argument. +1042 If you only want CFB media information for a team, +1043 regardless if they are the home/away team, +1044 set `team` to the name of the team you want CFB media information from. +1045 +1046 `conference_abv` (str, optional): +1047 Optional argument. +1048 If you only want media information from games +1049 involving teams a specific confrence, +1050 set `conference_abv` to the abbreviation +1051 of the conference you want game information from. +1052 +1053 `media_type` (str, semi-optional): +1054 Semi-optional argument. +1055 If you only want game broadcast information for a specific type of broadcast, +1056 set this to the type of broadcast. +1057 +1058 Valid inputs are: +1059 - `all` (default): Returns all games, and all known broadcasters for those games. +1060 - `tv`: Returns all known TV broadcasters for CFB games in the requested timeframe. +1061 - `radio`: Returns all known radio broadcasters +1062 for CFB games in the requested timeframe. +1063 - `web`: Returns all known web broadcasts (like ESPN+) +1064 for CFB games in the requested timeframe. +1065 - `ppv`: Returns all known Pay Per View (PPV) broadcasts +1066 for CFB games in the requested timeframe. +1067 - `mobile`: Returns all known broadcasters that only broadcasted +1068 games on mobile devices (?) +1069 +1070 `ncaa_division` (str, semi-optional): +1071 Semi-optional argument. +1072 By default, `ncaa_division` will be set to "fbs", +1073 short for the Football Bowl Subdivision (FBS), +1074 formerly known as D1-A (read as "division one single A"), +1075 the highest level in the NCAA football pyramid, +1076 where teams can scolarship up to 85 players +1077 on their football team soley for athletic ability, +1078 and often have the largest athletics budgets +1079 within the NCAA. +1080 +1081 Other valid inputs are: +1082 - "fcs": Football Championship Subdivision (FCS), +1083 formerly known as D1-AA (read as "division one double A"). +1084 An FCS school is still in the 1st division of the NCAA, +1085 making them elligable for the March Madness tournament, +1086 but may not have the resources to compete at the FBS level +1087 at this time. FCS schools are limited to 63 athletic scolarships +1088 for football. +1089 - "ii": NCAA Division II. Schools in this and D3 are not +1090 elligable for the March Madness tournament, +1091 and are limited to 36 athletic scolarships for their football team. +1092 - "iii": NCAA Division III. The largest single division within the +1093 NCAA football pyramid. +1094 D3 schools have the distinction of being part of +1095 the only NCAA division that cannot give out scolarships soley +1096 for athletic ability. +1097 +1098 `return_as_dict` (bool, semi-optional): +1099 Semi-optional argument. +1100 If you want this function to return the data as a dictionary (read: JSON object), +1101 instead of a pandas `DataFrame` object, +1102 set `return_as_dict` to `True`. +1103 +1104 Usage +1105 ---------- +1106 ``` +1107 import time +1108 +1109 from cfbd_json_py.games import get_cfbd_game_media_info +1110 1111 -1112 -1113 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -1114 -1115 if cfbd_key != "tigersAreAwsome": -1116 print("Using the user's API key declared in this script for this example.") -1117 -1118 # Get a media information for the 2020 CFB season. -1119 print("Get a media information for the 2020 CFB season.") -1120 json_data = get_cfbd_game_media_info( -1121 api_key=cfbd_key, -1122 season=2020 -1123 ) -1124 print(json_data) -1125 time.sleep(5) -1126 -1127 # Get a media information for postseason games in the 2020 CFB season. -1128 print("Get a media information for the 2020 CFB season.") -1129 json_data = get_cfbd_game_media_info( -1130 api_key=cfbd_key, -1131 season=2020, -1132 season_type="postseason" -1133 ) -1134 print(json_data) -1135 time.sleep(5) -1136 -1137 # Get a media information for week 10 games in the 2020 CFB season. -1138 print("Get a media information for week 10 games in the 2020 CFB season.") -1139 json_data = get_cfbd_game_media_info( -1140 api_key=cfbd_key, -1141 season=2020, -1142 week=10 -1143 ) -1144 print(json_data) -1145 time.sleep(5) -1146 -1147 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. -1148 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") -1149 json_data = get_cfbd_game_media_info( -1150 api_key=cfbd_key, -1151 season=2020, -1152 team="Ohio State" -1153 ) -1154 print(json_data) -1155 time.sleep(5) -1156 -1157 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. -1158 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") -1159 json_data = get_cfbd_game_media_info( -1160 api_key=cfbd_key, -1161 season=2020, -1162 conference_abv="AAC" -1163 ) -1164 print(json_data) -1165 time.sleep(5) -1166 -1167 # Get all known radio broadcasters for games in the the 2020 CFB season. -1168 print("Get all known radio broadcasters for games in the the 2020 CFB season.") -1169 json_data = get_cfbd_game_media_info( -1170 api_key=cfbd_key, -1171 season=2020, -1172 media_type="radio" -1173 ) -1174 print(json_data) -1175 time.sleep(5) -1176 -1177 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. -1178 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") -1179 json_data = get_cfbd_game_media_info( -1180 api_key=cfbd_key, -1181 season=2020, -1182 ncaa_division="fcs" -1183 ) -1184 print(json_data) -1185 time.sleep(5) -1186 -1187 # You can also tell this function to just return the API call as -1188 # a Dictionary (read: JSON) object. -1189 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1190 json_data = get_cfbd_game_media_info( -1191 season=2020, -1192 api_key=cfbd_key, -1193 return_as_dict=True -1194 ) -1195 print(json_data) -1196 -1197 else: -1198 # Alternatively, if the CFBD API key exists in this python environment, -1199 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -1200 # you could just call these functions directly, without setting the API key -1201 # in the script. -1202 print("Using the user's API key suposedly loaded into this python environment for this example.") -1203 -1204 # Get a media information for the 2020 CFB season. -1205 print("Get a media information for the 2020 CFB season.") -1206 json_data = get_cfbd_game_media_info( -1207 season=2020 -1208 ) -1209 print(json_data) -1210 time.sleep(5) -1211 -1212 # Get a media information for postseason games in the 2020 CFB season. -1213 print("Get a media information for the 2020 CFB season.") -1214 json_data = get_cfbd_game_media_info( -1215 season=2020, -1216 season_type="postseason" -1217 ) -1218 print(json_data) -1219 time.sleep(5) -1220 -1221 # Get a media information for week 10 games in the 2020 CFB season. -1222 print("Get a media information for week 10 games in the 2020 CFB season.") -1223 json_data = get_cfbd_game_media_info( -1224 season=2020, -1225 week=10 -1226 ) -1227 print(json_data) -1228 time.sleep(5) -1229 -1230 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. -1231 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") -1232 json_data = get_cfbd_game_media_info( -1233 season=2020, -1234 team="Ohio State" -1235 ) -1236 print(json_data) -1237 time.sleep(5) -1238 -1239 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. -1240 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") -1241 json_data = get_cfbd_game_media_info( -1242 season=2020, -1243 conference_abv="AAC" -1244 ) -1245 print(json_data) -1246 time.sleep(5) -1247 -1248 # Get all known radio broadcasters for games in the the 2020 CFB season. -1249 print("Get all known radio broadcasters for games in the the 2020 CFB season.") -1250 json_data = get_cfbd_game_media_info( -1251 season=2020, -1252 media_type="radio" -1253 ) -1254 print(json_data) -1255 time.sleep(5) -1256 -1257 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. -1258 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") -1259 json_data = get_cfbd_game_media_info( -1260 season=2020, -1261 ncaa_division="fcs" -1262 ) -1263 print(json_data) -1264 time.sleep(5) +1112 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1113 +1114 if cfbd_key != "tigersAreAwsome": +1115 print("Using the user's API key declared in this script for this example.") +1116 +1117 # Get a media information for the 2020 CFB season. +1118 print("Get a media information for the 2020 CFB season.") +1119 json_data = get_cfbd_game_media_info( +1120 api_key=cfbd_key, +1121 season=2020 +1122 ) +1123 print(json_data) +1124 time.sleep(5) +1125 +1126 # Get a media information for postseason games in the 2020 CFB season. +1127 print("Get a media information for the 2020 CFB season.") +1128 json_data = get_cfbd_game_media_info( +1129 api_key=cfbd_key, +1130 season=2020, +1131 season_type="postseason" +1132 ) +1133 print(json_data) +1134 time.sleep(5) +1135 +1136 # Get a media information for week 10 games in the 2020 CFB season. +1137 print("Get a media information for week 10 games in the 2020 CFB season.") +1138 json_data = get_cfbd_game_media_info( +1139 api_key=cfbd_key, +1140 season=2020, +1141 week=10 +1142 ) +1143 print(json_data) +1144 time.sleep(5) +1145 +1146 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. +1147 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") +1148 json_data = get_cfbd_game_media_info( +1149 api_key=cfbd_key, +1150 season=2020, +1151 team="Ohio State" +1152 ) +1153 print(json_data) +1154 time.sleep(5) +1155 +1156 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. +1157 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") +1158 json_data = get_cfbd_game_media_info( +1159 api_key=cfbd_key, +1160 season=2020, +1161 conference_abv="AAC" +1162 ) +1163 print(json_data) +1164 time.sleep(5) +1165 +1166 # Get all known radio broadcasters for games in the the 2020 CFB season. +1167 print("Get all known radio broadcasters for games in the the 2020 CFB season.") +1168 json_data = get_cfbd_game_media_info( +1169 api_key=cfbd_key, +1170 season=2020, +1171 media_type="radio" +1172 ) +1173 print(json_data) +1174 time.sleep(5) +1175 +1176 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. +1177 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") +1178 json_data = get_cfbd_game_media_info( +1179 api_key=cfbd_key, +1180 season=2020, +1181 ncaa_division="fcs" +1182 ) +1183 print(json_data) +1184 time.sleep(5) +1185 +1186 # You can also tell this function to just return the API call as +1187 # a Dictionary (read: JSON) object. +1188 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1189 json_data = get_cfbd_game_media_info( +1190 season=2020, +1191 api_key=cfbd_key, +1192 return_as_dict=True +1193 ) +1194 print(json_data) +1195 +1196 else: +1197 # Alternatively, if the CFBD API key exists in this python environment, +1198 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1199 # you could just call these functions directly, without setting the API key +1200 # in the script. +1201 print("Using the user's API key suposedly loaded into this python environment for this example.") +1202 +1203 # Get a media information for the 2020 CFB season. +1204 print("Get a media information for the 2020 CFB season.") +1205 json_data = get_cfbd_game_media_info( +1206 season=2020 +1207 ) +1208 print(json_data) +1209 time.sleep(5) +1210 +1211 # Get a media information for postseason games in the 2020 CFB season. +1212 print("Get a media information for the 2020 CFB season.") +1213 json_data = get_cfbd_game_media_info( +1214 season=2020, +1215 season_type="postseason" +1216 ) +1217 print(json_data) +1218 time.sleep(5) +1219 +1220 # Get a media information for week 10 games in the 2020 CFB season. +1221 print("Get a media information for week 10 games in the 2020 CFB season.") +1222 json_data = get_cfbd_game_media_info( +1223 season=2020, +1224 week=10 +1225 ) +1226 print(json_data) +1227 time.sleep(5) +1228 +1229 # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season. +1230 print("Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.") +1231 json_data = get_cfbd_game_media_info( +1232 season=2020, +1233 team="Ohio State" +1234 ) +1235 print(json_data) +1236 time.sleep(5) +1237 +1238 # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season. +1239 print("Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.") +1240 json_data = get_cfbd_game_media_info( +1241 season=2020, +1242 conference_abv="AAC" +1243 ) +1244 print(json_data) +1245 time.sleep(5) +1246 +1247 # Get all known radio broadcasters for games in the the 2020 CFB season. +1248 print("Get all known radio broadcasters for games in the the 2020 CFB season.") +1249 json_data = get_cfbd_game_media_info( +1250 season=2020, +1251 media_type="radio" +1252 ) +1253 print(json_data) +1254 time.sleep(5) +1255 +1256 # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season. +1257 print("Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.") +1258 json_data = get_cfbd_game_media_info( +1259 season=2020, +1260 ncaa_division="fcs" +1261 ) +1262 print(json_data) +1263 time.sleep(5) +1264 1265 -1266 -1267 # You can also tell this function to just return the API call as -1268 # a Dictionary (read: JSON) object. -1269 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1270 json_data = get_cfbd_game_media_info( -1271 season=2020, -1272 return_as_dict=True -1273 ) -1274 print(json_data) -1275 -1276 ``` -1277 Returns -1278 ---------- -1279 A pandas `DataFrame` object with college football media information, -1280 or (if `return_as_dict` is set to `True`) -1281 a dictionary object with college football media information. -1282 -1283 """ -1284 -1285 now = datetime.now() -1286 cfb_games_df = pd.DataFrame() -1287 row_df = pd.DataFrame() -1288 url = "https://api.collegefootballdata.com/games/media" -1289 -1290 ######################################################################################################################################################################################################## -1291 -1292 if api_key != None: -1293 real_api_key = api_key -1294 del api_key -1295 else: -1296 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -1297 -1298 if real_api_key == "tigersAreAwsome": -1299 raise ValueError( -1300 "You actually need to change `cfbd_key` to your CFBD API key.") -1301 elif "Bearer " in real_api_key: -1302 pass -1303 elif "Bearer" in real_api_key: -1304 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -1305 else: -1306 real_api_key = "Bearer " + real_api_key -1307 -1308 if season == None: -1309 # This should never happen without user tampering, but if it does, -1310 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -1311 raise SystemError( -1312 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + -1313 " and the function got to this point in the code." + -1314 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + -1315 "https://github.com/armstjc/cfbd-json-py/issues" -1316 ) -1317 elif season > now.year: -1318 raise ValueError(f"`season` cannot be greater than {season}.") -1319 elif season < 1869: -1320 raise ValueError(f"`season` cannot be less than 1869.") -1321 -1322 if season_type != "both" and season_type != "regular" and season_type != "postseason": -1323 raise ValueError( -1324 "`season_type` must be set to \"both\", \"regular\", or \"postseason\" for this function to work.") -1325 -1326 if media_type != "all" and media_type != "tv" and media_type != "radio" and media_type != "web" and media_type != "ppv" and media_type != "mobile": -1327 raise ValueError( -1328 "`media_type` must be set to one of the following values for this function to work:" + -1329 "\n\t- `all`" + -1330 "\n\t- `tv`" + -1331 "\n\t- `radio`" + -1332 "\n\t- `web`" + -1333 "\n\t- `ppv`" + -1334 "\n\t- `mobile`" -1335 ) -1336 -1337 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ -1338 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": -1339 pass -1340 else: -1341 raise ValueError( -1342 "An invalid NCAA Division was inputted when calling this function." + -1343 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + -1344 f"\n\nYou entered: \n{ncaa_division}" -1345 ) -1346 -1347 # URL builder -1348 ######################################################################################################################################################################################################## -1349 -1350 # Required by API -1351 url += f"?year={season}" -1352 -1353 if week != None: -1354 url += f"&week={week}" -1355 -1356 if team != None: -1357 url += f"&team={team}" -1358 -1359 if conference_abv != None: -1360 url += f"&conference={conference_abv}" -1361 -1362 if season_type != None: -1363 url += f"&seasonType={season_type}" -1364 -1365 if media_type == "all": -1366 # If we don't care about what media type we want back, -1367 # we don't need to add anything to the URL. -1368 pass -1369 elif media_type != None: -1370 url += f"&mediaType={media_type}" -1371 -1372 if ncaa_division != None: -1373 url += f"&classification={ncaa_division}" -1374 -1375 headers = { -1376 'Authorization': f'{real_api_key}', -1377 'accept': 'application/json' -1378 } -1379 -1380 response = requests.get(url, headers=headers) -1381 time.sleep(0.1) -1382 -1383 if response.status_code == 200: -1384 pass -1385 elif response.status_code == 401: -1386 raise ConnectionRefusedError( -1387 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -1388 ) -1389 else: -1390 raise ConnectionError( -1391 f'Could not connect.\nHTTP Status code {response.status_code}' -1392 ) -1393 -1394 json_data = response.json() -1395 -1396 if return_as_dict == True: -1397 return json_data -1398 -1399 for game in tqdm(json_data): -1400 row_df = pd.DataFrame( -1401 {"season": season}, -1402 index=[0] -1403 ) -1404 row_df['week'] = game['week'] -1405 row_df['game_id'] = game['id'] -1406 row_df['season_type'] = game['seasonType'] -1407 row_df['game_start_time'] = game['startTime'] -1408 row_df['is_start_time_tbd'] = game['isStartTimeTBD'] -1409 row_df['home_team'] = game['homeTeam'] -1410 row_df['home_conference'] = game['homeConference'] -1411 row_df['away_team'] = game['awayTeam'] -1412 row_df['away_conference'] = game['awayConference'] -1413 row_df['media_type'] = game['mediaType'] -1414 row_df['outlet'] = game['outlet'] -1415 -1416 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) -1417 del row_df -1418 -1419 return cfb_games_df +1266 # You can also tell this function to just return the API call as +1267 # a Dictionary (read: JSON) object. +1268 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1269 json_data = get_cfbd_game_media_info( +1270 season=2020, +1271 return_as_dict=True +1272 ) +1273 print(json_data) +1274 +1275 ``` +1276 Returns +1277 ---------- +1278 A pandas `DataFrame` object with college football media information, +1279 or (if `return_as_dict` is set to `True`) +1280 a dictionary object with college football media information. +1281 +1282 """ +1283 +1284 now = datetime.now() +1285 cfb_games_df = pd.DataFrame() +1286 row_df = pd.DataFrame() +1287 url = "https://api.collegefootballdata.com/games/media" +1288 +1289 ######################################################################################################################################################################################################## +1290 +1291 if api_key != None: +1292 real_api_key = api_key +1293 del api_key +1294 else: +1295 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1296 +1297 if real_api_key == "tigersAreAwsome": +1298 raise ValueError( +1299 "You actually need to change `cfbd_key` to your CFBD API key.") +1300 elif "Bearer " in real_api_key: +1301 pass +1302 elif "Bearer" in real_api_key: +1303 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1304 else: +1305 real_api_key = "Bearer " + real_api_key +1306 +1307 if season == None: +1308 # This should never happen without user tampering, but if it does, +1309 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +1310 raise SystemError( +1311 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +1312 " and the function got to this point in the code." + +1313 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +1314 "https://github.com/armstjc/cfbd-json-py/issues" +1315 ) +1316 elif season > now.year: +1317 raise ValueError(f"`season` cannot be greater than {season}.") +1318 elif season < 1869: +1319 raise ValueError(f"`season` cannot be less than 1869.") +1320 +1321 if season_type != "both" and season_type != "regular" and season_type != "postseason": +1322 raise ValueError( +1323 "`season_type` must be set to \"both\", \"regular\", or \"postseason\" for this function to work.") +1324 +1325 if media_type != "all" and media_type != "tv" and media_type != "radio" and media_type != "web" and media_type != "ppv" and media_type != "mobile": +1326 raise ValueError( +1327 "`media_type` must be set to one of the following values for this function to work:" + +1328 "\n\t- `all`" + +1329 "\n\t- `tv`" + +1330 "\n\t- `radio`" + +1331 "\n\t- `web`" + +1332 "\n\t- `ppv`" + +1333 "\n\t- `mobile`" +1334 ) +1335 +1336 if ncaa_division.lower() == "fbs" or ncaa_division.lower() == "fcs" \ +1337 or ncaa_division.lower() == "ii" or ncaa_division.lower() == "iii": +1338 pass +1339 else: +1340 raise ValueError( +1341 "An invalid NCAA Division was inputted when calling this function." + +1342 "\nValid inputs are:\n-\"fbs\"\n-\"fcs\"\n-\"ii\"\n-\"iii\"" + +1343 f"\n\nYou entered: \n{ncaa_division}" +1344 ) +1345 +1346 # URL builder +1347 ######################################################################################################################################################################################################## +1348 +1349 # Required by API +1350 url += f"?year={season}" +1351 +1352 if week != None: +1353 url += f"&week={week}" +1354 +1355 if team != None: +1356 url += f"&team={team}" +1357 +1358 if conference_abv != None: +1359 url += f"&conference={conference_abv}" +1360 +1361 if season_type != None: +1362 url += f"&seasonType={season_type}" +1363 +1364 if media_type == "all": +1365 # If we don't care about what media type we want back, +1366 # we don't need to add anything to the URL. +1367 pass +1368 elif media_type != None: +1369 url += f"&mediaType={media_type}" +1370 +1371 if ncaa_division != None: +1372 url += f"&classification={ncaa_division}" +1373 +1374 headers = { +1375 'Authorization': f'{real_api_key}', +1376 'accept': 'application/json' +1377 } +1378 +1379 response = requests.get(url, headers=headers) +1380 +1381 +1382 if response.status_code == 200: +1383 pass +1384 elif response.status_code == 401: +1385 raise ConnectionRefusedError( +1386 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1387 ) +1388 else: +1389 raise ConnectionError( +1390 f'Could not connect.\nHTTP Status code {response.status_code}' +1391 ) +1392 +1393 json_data = response.json() +1394 +1395 if return_as_dict == True: +1396 return json_data +1397 +1398 for game in tqdm(json_data): +1399 row_df = pd.DataFrame( +1400 {"season": season}, +1401 index=[0] +1402 ) +1403 row_df['week'] = game['week'] +1404 row_df['game_id'] = game['id'] +1405 row_df['season_type'] = game['seasonType'] +1406 row_df['game_start_time'] = game['startTime'] +1407 row_df['is_start_time_tbd'] = game['isStartTimeTBD'] +1408 row_df['home_team'] = game['homeTeam'] +1409 row_df['home_conference'] = game['homeConference'] +1410 row_df['away_team'] = game['awayTeam'] +1411 row_df['away_conference'] = game['awayConference'] +1412 row_df['media_type'] = game['mediaType'] +1413 row_df['outlet'] = game['outlet'] +1414 +1415 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +1416 del row_df +1417 +1418 return cfb_games_dfParameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -5932,1452 +5932,1453 @@Returns
1422def get_cfbd_player_game_stats( -1423 season: int, -1424 api_key: str = None, -1425 api_key_dir: str = None, -1426 season_type: str = "regular", # "regular" or "postseason" -1427 week: int = None, -1428 team: str = None, -1429 conference_abv: str = None, -1430 # `week`, `team`, and/or `conference` -1431 # must be not null for this function to work. -1432 stat_category: str = None, -1433 game_id: int = None, -1434 return_as_dict: bool = False): -1435 """ -1436 Retrives player game stats for a given time frame. -1437 -1438 Parameters -1439 ---------- -1440 `season` (int, mandatory): -1441 Required argument. -1442 Specifies the season you want CFB media information from. -1443 This must be specified, otherwise this package, and by extension -1444 the CFBD API, will not accept the request to get CFB media information. -1445 -1446 `api_key` (str, optional): -1447 Semi-optional argument. -1448 If `api_key` is null, this function will attempt to load a CFBD API key -1449 from the python environment, or from a file on this computer. -1450 If `api_key` is not null, this function will automatically assume that the -1451 inputted `api_key` is a valid CFBD API key. -1452 -1453 `api_key_dir` (str, optional): -1454 Optional argument. -1455 If `api_key` is set to a string non-empty string, this variable is ignored. -1456 If `api_key_dir` is null, and `api_key` is null, -1457 this function will try to find a CFBD API key file in this user's home directory. -1458 If `api_key_dir` is set to a string, and `api_key` is null, -1459 this function will assume that `api_key_dir` is a directory, -1460 and will try to find a CFBD API key file in that directory. -1461 -1462 `season_type` (str, semi-optional): -1463 Semi-optional argument. -1464 By defualt, this will be set to "regular", for the CFB regular season. -1465 If you want CFB media information for non-regular season games, -1466 set `season_type` to "postseason". -1467 If `season_type` is set to anything but "regular" or "postseason", -1468 a `ValueError()` will be raised. -1469 -1470 **For the following three variables, -1471 at least one must be set to a non-null variable when calling this function.** -1472 -1473 `week` (int, optional): -1474 Optional argument. -1475 If `week` is set to an integer, this function will attempt -1476 to load CFB media information from games in that season, and in that week. -1477 -1478 `team` (str, optional): -1479 Optional argument. -1480 If you only want CFB media information for a team, -1481 regardless if they are the home/away team, -1482 set `team` to the name of the team you want CFB media information from. -1483 -1484 `conference_abv` (str, optional): -1485 Optional argument. -1486 If you only want media information from games -1487 involving teams a specific confrence, -1488 set `conference_abv` to the abbreviation -1489 of the conference you want game information from. -1490 -1491 `stat_category` (str, optional): -1492 Optional argument. -1493 If only want stats for a specific stat category, -1494 set this variable to that category. -1495 -1496 Valid inputs are: -1497 - `passing` -1498 - `rushing` -1499 - `receiving` -1500 - `fumbles` -1501 - `defensive` -1502 - `interceptions` -1503 - `punting` -1504 - `kicking` -1505 - `kickReturns` -1506 - `puntReturns` -1507 -1508 `game_id` (int, optional): -1509 Optional argument. -1510 If `game_id` is set to a game ID, `get_cfbd_player_game_stats()` will try to get -1511 player game stats just for that game ID. -1512 -1513 `return_as_dict` (bool, semi-optional): -1514 Semi-optional argument. -1515 If you want this function to return the data as a dictionary (read: JSON object), -1516 instead of a pandas `DataFrame` object, -1517 set `return_as_dict` to `True`. -1518 -1519 Usage -1520 ---------- -1521 ``` -1522 import time -1523 -1524 from cfbd_json_py.games import get_cfbd_player_game_stats +1421def get_cfbd_player_game_stats( +1422 season: int, +1423 api_key: str = None, +1424 api_key_dir: str = None, +1425 season_type: str = "regular", # "regular" or "postseason" +1426 week: int = None, +1427 team: str = None, +1428 conference_abv: str = None, +1429 # `week`, `team`, and/or `conference` +1430 # must be not null for this function to work. +1431 stat_category: str = None, +1432 game_id: int = None, +1433 return_as_dict: bool = False): +1434 """ +1435 Retrives player game stats for a given time frame. +1436 +1437 Parameters +1438 ---------- +1439 `season` (int, mandatory): +1440 Required argument. +1441 Specifies the season you want CFB media information from. +1442 This must be specified, otherwise this package, and by extension +1443 the CFBD API, will not accept the request to get CFB media information. +1444 +1445 `api_key` (str, optional): +1446 Semi-optional argument. +1447 If `api_key` is null, this function will attempt to load a CFBD API key +1448 from the python environment, or from a file on this computer. +1449 If `api_key` is not null, this function will automatically assume that the +1450 inputted `api_key` is a valid CFBD API key. +1451 +1452 `api_key_dir` (str, optional): +1453 Optional argument. +1454 If `api_key` is set to am empty string, this variable is ignored. +1455 If `api_key_dir` is null, and `api_key` is null, +1456 this function will try to find a CFBD API key file in this user's home directory. +1457 If `api_key_dir` is set to a string, and `api_key` is null, +1458 this function will assume that `api_key_dir` is a directory, +1459 and will try to find a CFBD API key file in that directory. +1460 +1461 `season_type` (str, semi-optional): +1462 Semi-optional argument. +1463 By defualt, this will be set to "regular", for the CFB regular season. +1464 If you want CFB media information for non-regular season games, +1465 set `season_type` to "postseason". +1466 If `season_type` is set to anything but "regular" or "postseason", +1467 a `ValueError()` will be raised. +1468 +1469 **For the following three variables, +1470 at least one must be set to a non-null variable when calling this function.** +1471 +1472 `week` (int, optional): +1473 Optional argument. +1474 If `week` is set to an integer, this function will attempt +1475 to load CFB media information from games in that season, and in that week. +1476 +1477 `team` (str, optional): +1478 Optional argument. +1479 If you only want CFB media information for a team, +1480 regardless if they are the home/away team, +1481 set `team` to the name of the team you want CFB media information from. +1482 +1483 `conference_abv` (str, optional): +1484 Optional argument. +1485 If you only want media information from games +1486 involving teams a specific confrence, +1487 set `conference_abv` to the abbreviation +1488 of the conference you want game information from. +1489 +1490 `stat_category` (str, optional): +1491 Optional argument. +1492 If only want stats for a specific stat category, +1493 set this variable to that category. +1494 +1495 Valid inputs are: +1496 - `passing` +1497 - `rushing` +1498 - `receiving` +1499 - `fumbles` +1500 - `defensive` +1501 - `interceptions` +1502 - `punting` +1503 - `kicking` +1504 - `kickReturns` +1505 - `puntReturns` +1506 +1507 `game_id` (int, optional): +1508 Optional argument. +1509 If `game_id` is set to a game ID, `get_cfbd_player_game_stats()` will try to get +1510 player game stats just for that game ID. +1511 +1512 `return_as_dict` (bool, semi-optional): +1513 Semi-optional argument. +1514 If you want this function to return the data as a dictionary (read: JSON object), +1515 instead of a pandas `DataFrame` object, +1516 set `return_as_dict` to `True`. +1517 +1518 Usage +1519 ---------- +1520 ``` +1521 import time +1522 +1523 from cfbd_json_py.games import get_cfbd_player_game_stats +1524 1525 -1526 -1527 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. -1528 -1529 if cfbd_key != "tigersAreAwsome": -1530 print("Using the user's API key declared in this script for this example.") -1531 -1532 # Get player game stats for week 10 of the 2020 CFB season. -1533 print("Get player game stats for week 10 of the 2020 CFB season.") -1534 json_data = get_cfbd_player_game_stats( -1535 api_key=cfbd_key, -1536 season=2020, -1537 week=10 -1538 ) -1539 print(json_data) -1540 time.sleep(5) -1541 -1542 # Get postseason player game stats for the 2020 CFB season. -1543 print("Get postseason player game stats for the 2020 CFB season.") -1544 json_data = get_cfbd_player_game_stats( -1545 api_key=cfbd_key, -1546 season=2020, -1547 season_type="postseason", -1548 week=1 -1549 ) -1550 print(json_data) -1551 time.sleep(5) -1552 -1553 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. -1554 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") -1555 json_data = get_cfbd_player_game_stats( -1556 api_key=cfbd_key, -1557 season=2018, -1558 team="Alabama" -1559 ) -1560 print(json_data) -1561 time.sleep(5) -1562 -1563 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. -1564 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") -1565 json_data = get_cfbd_player_game_stats( -1566 api_key=cfbd_key, -1567 season=2020, -1568 conference_abv="ACC" -1569 ) -1570 print(json_data) -1571 time.sleep(5) -1572 -1573 # Get get passing stats from players who played in week 7 of the 2017 CFB season. -1574 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") -1575 json_data = get_cfbd_player_game_stats( -1576 api_key=cfbd_key, -1577 season=2017, -1578 week=7, -1579 stat_category="pasing" -1580 ) -1581 print(json_data) -1582 time.sleep(5) -1583 -1584 # Get player game stats from the 2021 Virbo Citrus Bowl, -1585 # a bowl game that happened in the 2020 CFB season. -1586 print("Get player game stats from the 2021 Virbo Citrus Bowl, a bowl game that happened in the 2020 CFB season.") -1587 json_data = get_cfbd_player_game_stats( -1588 api_key=cfbd_key, -1589 season=2020, -1590 game_id=401256199 -1591 ) -1592 print(json_data) -1593 time.sleep(5) -1594 -1595 # You can also tell this function to just return the API call as -1596 # a Dictionary (read: JSON) object. -1597 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1598 json_data = get_cfbd_player_game_stats( -1599 season=2020, -1600 week=10, -1601 api_key=cfbd_key, -1602 return_as_dict=True -1603 ) -1604 print(json_data) -1605 -1606 else: -1607 # Alternatively, if the CFBD API key exists in this python environment, -1608 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), -1609 # you could just call these functions directly, without setting the API key -1610 # in the script. -1611 print("Using the user's API key suposedly loaded into this python environment for this example.") -1612 -1613 # Get player game stats for week 10 of the 2020 CFB season. -1614 print("Get player game stats for week 10 of the 2020 CFB season.") -1615 json_data = get_cfbd_player_game_stats( -1616 season=2020, -1617 week=10 -1618 ) -1619 print(json_data) -1620 time.sleep(5) -1621 -1622 # Get postseason player game stats for the 2020 CFB season. -1623 print("Get postseason player game stats for the 2020 CFB season.") -1624 json_data = get_cfbd_player_game_stats( -1625 season=2020, -1626 season_type="postseason", -1627 week=1 -1628 ) -1629 print(json_data) -1630 time.sleep(5) -1631 -1632 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. -1633 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") -1634 json_data = get_cfbd_player_game_stats( -1635 season=2018, -1636 team="Alabama" -1637 ) -1638 print(json_data) -1639 time.sleep(5) -1640 -1641 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. -1642 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") -1643 json_data = get_cfbd_player_game_stats( -1644 season=2020, -1645 conference_abv="ACC" -1646 ) -1647 print(json_data) -1648 time.sleep(5) -1649 -1650 # Get get passing stats from players who played in week 7 of the 2017 CFB season. -1651 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") -1652 json_data = get_cfbd_player_game_stats( -1653 season=2017, -1654 week=7, -1655 stat_category="passing" -1656 ) -1657 print(json_data) -1658 time.sleep(5) -1659 -1660 # Get player game stats from the 2021 Virbo Citrus Bowl, -1661 # a bowl game that happened in the 2020 CFB season, -1662 # between the Aubrun Tigers, and the Northwestern Wildcats. -1663 print("Get player game stats from the 2021 Virbo Citrus Bowl, "+ -1664 "a bowl game that happened in the 2020 CFB season between the Aubrun Tigers, and the Northwestern Wildcats.") -1665 json_data = get_cfbd_player_game_stats( -1666 season=2020, -1667 game_id=401256199 -1668 ) -1669 print(json_data) -1670 time.sleep(5) +1526 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1527 +1528 if cfbd_key != "tigersAreAwsome": +1529 print("Using the user's API key declared in this script for this example.") +1530 +1531 # Get player game stats for week 10 of the 2020 CFB season. +1532 print("Get player game stats for week 10 of the 2020 CFB season.") +1533 json_data = get_cfbd_player_game_stats( +1534 api_key=cfbd_key, +1535 season=2020, +1536 week=10 +1537 ) +1538 print(json_data) +1539 time.sleep(5) +1540 +1541 # Get postseason player game stats for the 2020 CFB season. +1542 print("Get postseason player game stats for the 2020 CFB season.") +1543 json_data = get_cfbd_player_game_stats( +1544 api_key=cfbd_key, +1545 season=2020, +1546 season_type="postseason", +1547 week=1 +1548 ) +1549 print(json_data) +1550 time.sleep(5) +1551 +1552 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. +1553 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") +1554 json_data = get_cfbd_player_game_stats( +1555 api_key=cfbd_key, +1556 season=2018, +1557 team="Alabama" +1558 ) +1559 print(json_data) +1560 time.sleep(5) +1561 +1562 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. +1563 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") +1564 json_data = get_cfbd_player_game_stats( +1565 api_key=cfbd_key, +1566 season=2020, +1567 conference_abv="ACC" +1568 ) +1569 print(json_data) +1570 time.sleep(5) +1571 +1572 # Get get passing stats from players who played in week 7 of the 2017 CFB season. +1573 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") +1574 json_data = get_cfbd_player_game_stats( +1575 api_key=cfbd_key, +1576 season=2017, +1577 week=7, +1578 stat_category="pasing" +1579 ) +1580 print(json_data) +1581 time.sleep(5) +1582 +1583 # Get player game stats from the 2021 Virbo Citrus Bowl, +1584 # a bowl game that happened in the 2020 CFB season. +1585 print("Get player game stats from the 2021 Virbo Citrus Bowl, a bowl game that happened in the 2020 CFB season.") +1586 json_data = get_cfbd_player_game_stats( +1587 api_key=cfbd_key, +1588 season=2020, +1589 game_id=401256199 +1590 ) +1591 print(json_data) +1592 time.sleep(5) +1593 +1594 # You can also tell this function to just return the API call as +1595 # a Dictionary (read: JSON) object. +1596 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1597 json_data = get_cfbd_player_game_stats( +1598 season=2020, +1599 week=10, +1600 api_key=cfbd_key, +1601 return_as_dict=True +1602 ) +1603 print(json_data) +1604 +1605 else: +1606 # Alternatively, if the CFBD API key exists in this python environment, +1607 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1608 # you could just call these functions directly, without setting the API key +1609 # in the script. +1610 print("Using the user's API key suposedly loaded into this python environment for this example.") +1611 +1612 # Get player game stats for week 10 of the 2020 CFB season. +1613 print("Get player game stats for week 10 of the 2020 CFB season.") +1614 json_data = get_cfbd_player_game_stats( +1615 season=2020, +1616 week=10 +1617 ) +1618 print(json_data) +1619 time.sleep(5) +1620 +1621 # Get postseason player game stats for the 2020 CFB season. +1622 print("Get postseason player game stats for the 2020 CFB season.") +1623 json_data = get_cfbd_player_game_stats( +1624 season=2020, +1625 season_type="postseason", +1626 week=1 +1627 ) +1628 print(json_data) +1629 time.sleep(5) +1630 +1631 # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season. +1632 print("Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.") +1633 json_data = get_cfbd_player_game_stats( +1634 season=2018, +1635 team="Alabama" +1636 ) +1637 print(json_data) +1638 time.sleep(5) +1639 +1640 # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season. +1641 print("Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.") +1642 json_data = get_cfbd_player_game_stats( +1643 season=2020, +1644 conference_abv="ACC" +1645 ) +1646 print(json_data) +1647 time.sleep(5) +1648 +1649 # Get get passing stats from players who played in week 7 of the 2017 CFB season. +1650 print("Get get passing stats from players who played in week 7 of the 2017 CFB season.") +1651 json_data = get_cfbd_player_game_stats( +1652 season=2017, +1653 week=7, +1654 stat_category="passing" +1655 ) +1656 print(json_data) +1657 time.sleep(5) +1658 +1659 # Get player game stats from the 2021 Virbo Citrus Bowl, +1660 # a bowl game that happened in the 2020 CFB season, +1661 # between the Aubrun Tigers, and the Northwestern Wildcats. +1662 print("Get player game stats from the 2021 Virbo Citrus Bowl, "+ +1663 "a bowl game that happened in the 2020 CFB season between the Aubrun Tigers, and the Northwestern Wildcats.") +1664 json_data = get_cfbd_player_game_stats( +1665 season=2020, +1666 game_id=401256199 +1667 ) +1668 print(json_data) +1669 time.sleep(5) +1670 1671 -1672 -1673 # You can also tell this function to just return the API call as -1674 # a Dictionary (read: JSON) object. -1675 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") -1676 json_data = get_cfbd_player_game_stats( -1677 season=2020, -1678 week=10, -1679 return_as_dict=True -1680 ) -1681 print(json_data) -1682 -1683 ``` -1684 Returns -1685 ---------- -1686 A pandas `DataFrame` object with player game stats data, -1687 or (if `return_as_dict` is set to `True`) -1688 a dictionary object with player game stats data. -1689 -1690 """ -1691 -1692 rebuilt_json = {} -1693 now = datetime.now() -1694 cfb_games_df = pd.DataFrame() -1695 row_df = pd.DataFrame() -1696 url = "https://api.collegefootballdata.com/games/players" -1697 stat_columns = [ -1698 'game_id', -1699 'team_name', -1700 'team_confrence', -1701 'player_id', -1702 'player_name', -1703 'home_away', -1704 # PASS -1705 'passing_C/ATT', -1706 'passing_COMP', -1707 'passing_ATT', -1708 'passing_YDS', -1709 'passing_AVG', -1710 'passing_TD', -1711 'passing_INT', -1712 'passing_QBR', -1713 # RUSH -1714 'rushing_CAR', -1715 'rushing_YDS', -1716 'rushing_AVG', -1717 'rushing_TD', -1718 'rushing_LONG', -1719 # REC -1720 'receiving_REC', -1721 'receiving_YDS', -1722 'receiving_AVG', -1723 'receiving_TD', -1724 'receiving_LONG', -1725 # FUM -1726 'fumbles_FUM', -1727 'fumbles_LOST', -1728 'fumbles_REC', -1729 # DEFENSE -1730 'defensive_TOT', -1731 'defensive_SOLO', -1732 'defensive_TFL', -1733 'defensive_QB HUR', -1734 'defensive_SACKS', -1735 'defensive_PD', -1736 'defensive_TD', -1737 # INT -1738 'interceptions_INT', -1739 'interceptions_YDS', -1740 'interceptions_TD', -1741 # PUNT -1742 'punting_NO', -1743 'punting_YDS', -1744 'punting_AVG', -1745 'punting_TB', -1746 'punting_In 20', -1747 'punting_LONG', -1748 # KICK -1749 'kicking_FG', -1750 'kicking_FGM', -1751 'kicking_FGA', -1752 'kicking_PCT', -1753 'kicking_LONG', -1754 'kicking_XP', -1755 'kicking_XPM', -1756 'kicking_XPA', -1757 'kicking_PTS', -1758 # KR -1759 'kickReturns_NO', -1760 'kickReturns_YDS', -1761 'kickReturns_AVG', -1762 'kickReturns_TD', -1763 'kickReturns_LONG', -1764 # PR -1765 'puntReturns_NO', -1766 'puntReturns_YDS', -1767 'puntReturns_AVG', -1768 'puntReturns_TD', -1769 'puntReturns_LONG' -1770 ] -1771 -1772 ######################################################################################################################################################################################################## -1773 -1774 if api_key != None: -1775 real_api_key = api_key -1776 del api_key -1777 else: -1778 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) -1779 -1780 if real_api_key == "tigersAreAwsome": -1781 raise ValueError( -1782 "You actually need to change `cfbd_key` to your CFBD API key.") -1783 elif "Bearer " in real_api_key: -1784 pass -1785 elif "Bearer" in real_api_key: -1786 real_api_key = real_api_key.replace('Bearer', 'Bearer ') -1787 else: -1788 real_api_key = "Bearer " + real_api_key -1789 -1790 if season == None: -1791 # This should never happen without user tampering, but if it does, -1792 # we need to raise an error, because the CFBD API will refuse this call without a valid season. -1793 raise SystemError( -1794 "I don't know how, I don't know why, " + -1795 "but you managed to call this function while `season` was `None` (NULL)," + -1796 " and the function got to this point in the code." + -1797 "\nIf you have a GitHub account, " + -1798 "please raise an issue on this python package's GitHub page:\n" + -1799 "https://github.com/armstjc/cfbd-json-py/issues" -1800 ) -1801 elif season > now.year: -1802 raise ValueError(f"`season` cannot be greater than {season}.") -1803 elif season < 1869: -1804 raise ValueError(f"`season` cannot be less than 1869.") -1805 -1806 if season_type != "regular" and season_type != "postseason": -1807 raise ValueError( -1808 "`season_type` must be set to either \"regular\" or " + -1809 "\"postseason\" for this function to work." -1810 ) -1811 -1812 # `week`, `team`, and/or `conference` -1813 # must be not null for this function to work. -1814 -1815 if week == None and team == None and conference_abv == None and game_id == None: -1816 raise ValueError( -1817 "To use `get_cfbd_player_game_stats()`," + -1818 " `week`, `team`, and/or `conference_abv` need to be set to a non-null value." -1819 ) -1820 -1821 filter_by_stat_category = False -1822 -1823 if stat_category == None: -1824 pass -1825 elif stat_category == "passing": -1826 filter_by_stat_category = True -1827 elif stat_category == "rushing": -1828 filter_by_stat_category = True -1829 elif stat_category == "receiving": -1830 filter_by_stat_category = True -1831 elif stat_category == "fumbles": -1832 filter_by_stat_category = True -1833 elif stat_category == "passing": -1834 filter_by_stat_category = True -1835 elif stat_category == "defensive": -1836 filter_by_stat_category = True -1837 elif stat_category == "interceptions": -1838 filter_by_stat_category = True -1839 elif stat_category == "punting": -1840 filter_by_stat_category = True -1841 elif stat_category == "kicking": -1842 filter_by_stat_category = True -1843 elif stat_category == "kickReturns": -1844 filter_by_stat_category = True -1845 elif stat_category == "puntReturns": -1846 filter_by_stat_category = True -1847 else: -1848 raise ValueError( -1849 "Invalid input for `stat_category`." + -1850 "\nValid inputs are:" + -1851 """ -1852 - `passing` -1853 - `rushing` -1854 - `receiving` -1855 - `fumbles` -1856 - `defensive` -1857 - `interceptions` -1858 - `punting` -1859 - `kicking` -1860 - `kickReturns` -1861 - `puntReturns` -1862 """ -1863 ) -1864 -1865 # URL builder -1866 ######################################################################################################################################################################################################## -1867 -1868 # Required by the API -1869 url += f"?year={season}" -1870 -1871 if game_id != None: -1872 url += f"&gameId={game_id}" -1873 -1874 if stat_category != None: -1875 url += f"&category={stat_category}" -1876 -1877 if week != None or team != None or conference_abv != None: -1878 logging.warning( -1879 "When calling `cfbd_json_py.games.get_cfbd_player_game_stats()`, " + -1880 "and setting `game_id` to a non-null value, " + -1881 "only `season`, `stat_category`, and `game_id` are considered " + -1882 "when calling the CFBD API." -1883 ) -1884 else: -1885 if season_type != None: -1886 url += f"&seasonType={season_type}" -1887 -1888 if week != None: -1889 url += f"&week={week}" -1890 -1891 if team != None: -1892 url += f"&team={team}" -1893 -1894 if conference_abv != None: -1895 url += f"&conference={conference_abv}" -1896 -1897 headers = { -1898 'Authorization': f'{real_api_key}', -1899 'accept': 'application/json' -1900 } -1901 -1902 response = requests.get(url, headers=headers) -1903 time.sleep(0.1) -1904 -1905 if response.status_code == 200: -1906 pass -1907 elif response.status_code == 401: -1908 raise ConnectionRefusedError( -1909 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' -1910 ) -1911 else: -1912 raise ConnectionError( -1913 f'Could not connect.\nHTTP Status code {response.status_code}' -1914 ) -1915 -1916 json_data = response.json() -1917 -1918 if return_as_dict == True: -1919 return json_data -1920 -1921 for game in tqdm(json_data): -1922 game_id = game['id'] -1923 -1924 for team in game['teams']: -1925 team_name = team['school'] -1926 team_confrence = team['conference'] -1927 home_away = team['homeAway'] -1928 -1929 for s_category in team['categories']: -1930 if s_category['name'] == "passing": -1931 for stat in s_category['types']: -1932 -1933 if stat['name'] == "C/ATT": # passing_C/ATT -1934 -1935 for i in stat['athletes']: -1936 player_id = int(i['id']) -1937 player_name = i['name'] -1938 player_stat = i['stat'] -1939 -1940 if rebuilt_json.get(player_id) == None: -1941 rebuilt_json[player_id] = {} -1942 -1943 rebuilt_json[player_id]['game_id'] = game_id -1944 rebuilt_json[player_id]['team_name'] = team_name -1945 rebuilt_json[player_id]['team_confrence'] = team_confrence -1946 rebuilt_json[player_id]['player_id'] = player_id -1947 rebuilt_json[player_id]['player_name'] = player_name -1948 rebuilt_json[player_id]['home_away'] = home_away -1949 rebuilt_json[player_id]['passing_C/ATT'] = player_stat -1950 -1951 elif stat['name'] == "YDS": # passing_YDS -1952 -1953 for i in stat['athletes']: -1954 player_id = int(i['id']) -1955 player_name = i['name'] -1956 player_stat = int(i['stat']) -1957 -1958 if rebuilt_json.get(player_id) == None: -1959 rebuilt_json[player_id] = {} -1960 -1961 rebuilt_json[player_id]['game_id'] = game_id -1962 rebuilt_json[player_id]['team_name'] = team_name -1963 rebuilt_json[player_id]['team_confrence'] = team_confrence -1964 rebuilt_json[player_id]['player_id'] = player_id -1965 rebuilt_json[player_id]['player_name'] = player_name -1966 rebuilt_json[player_id]['home_away'] = home_away -1967 rebuilt_json[player_id]['passing_YDS'] = player_stat -1968 -1969 elif stat['name'] == "AVG": # passing_AVG -1970 for i in stat['athletes']: -1971 player_id = int(i['id']) -1972 player_name = i['name'] -1973 player_stat = float(i['stat']) -1974 -1975 if rebuilt_json.get(player_id) == None: -1976 rebuilt_json[player_id] = {} -1977 -1978 rebuilt_json[player_id]['game_id'] = game_id -1979 rebuilt_json[player_id]['team_name'] = team_name -1980 rebuilt_json[player_id]['team_confrence'] = team_confrence -1981 rebuilt_json[player_id]['player_id'] = player_id -1982 rebuilt_json[player_id]['player_name'] = player_name -1983 rebuilt_json[player_id]['home_away'] = home_away -1984 rebuilt_json[player_id]['passing_AVG'] = player_stat -1985 -1986 elif stat['name'] == "TD": # passing_TD -1987 -1988 for i in stat['athletes']: -1989 player_id = int(i['id']) -1990 player_name = i['name'] -1991 player_stat = int(i['stat']) -1992 -1993 if rebuilt_json.get(player_id) == None: -1994 rebuilt_json[player_id] = {} -1995 -1996 rebuilt_json[player_id]['game_id'] = game_id -1997 rebuilt_json[player_id]['team_name'] = team_name -1998 rebuilt_json[player_id]['team_confrence'] = team_confrence -1999 rebuilt_json[player_id]['player_id'] = player_id -2000 rebuilt_json[player_id]['player_name'] = player_name -2001 rebuilt_json[player_id]['home_away'] = home_away -2002 rebuilt_json[player_id]['passing_TD'] = player_stat -2003 -2004 elif stat['name'] == "INT": # passing_INT -2005 -2006 for i in stat['athletes']: -2007 player_id = int(i['id']) -2008 player_name = i['name'] -2009 player_stat = int(i['stat']) -2010 -2011 if rebuilt_json.get(player_id) == None: -2012 rebuilt_json[player_id] = {} -2013 -2014 rebuilt_json[player_id]['game_id'] = game_id -2015 rebuilt_json[player_id]['team_name'] = team_name -2016 rebuilt_json[player_id]['team_confrence'] = team_confrence -2017 rebuilt_json[player_id]['player_id'] = player_id -2018 rebuilt_json[player_id]['player_name'] = player_name -2019 rebuilt_json[player_id]['home_away'] = home_away -2020 rebuilt_json[player_id]['passing_INT'] = player_stat -2021 -2022 elif stat['name'] == "QBR": # passing_QBR -2023 for i in stat['athletes']: -2024 player_id = int(i['id']) -2025 player_name = i['name'] -2026 try: -2027 player_stat = float(i['stat']) -2028 except: -2029 player_stat = None -2030 -2031 if rebuilt_json.get(player_id) == None: -2032 rebuilt_json[player_id] = {} -2033 -2034 rebuilt_json[player_id]['game_id'] = game_id -2035 rebuilt_json[player_id]['team_name'] = team_name -2036 rebuilt_json[player_id]['team_confrence'] = team_confrence -2037 rebuilt_json[player_id]['player_id'] = player_id -2038 rebuilt_json[player_id]['player_name'] = player_name -2039 rebuilt_json[player_id]['home_away'] = home_away -2040 rebuilt_json[player_id]['passing_QBR'] = player_stat -2041 -2042 else: -2043 raise IndexError( -2044 f"Unhandled stat: \t{stat['name']}") -2045 # passing_df = pd.DataFrame(s_category['types']) -2046 elif s_category['name'] == "rushing": -2047 for stat in s_category['types']: -2048 if stat['name'] == "CAR": # rushing_CAR -2049 for i in stat['athletes']: -2050 player_id = int(i['id']) -2051 player_name = i['name'] -2052 player_stat = int(i['stat']) -2053 -2054 if rebuilt_json.get(player_id) == None: -2055 rebuilt_json[player_id] = {} -2056 -2057 rebuilt_json[player_id]['game_id'] = game_id -2058 rebuilt_json[player_id]['team_name'] = team_name -2059 rebuilt_json[player_id]['team_confrence'] = team_confrence -2060 rebuilt_json[player_id]['player_id'] = player_id -2061 rebuilt_json[player_id]['player_name'] = player_name -2062 rebuilt_json[player_id]['home_away'] = home_away -2063 rebuilt_json[player_id]['rushing_CAR'] = player_stat -2064 -2065 elif stat['name'] == "YDS": # rushing_YDS -2066 for i in stat['athletes']: -2067 player_id = int(i['id']) -2068 player_name = i['name'] -2069 player_stat = int(i['stat']) -2070 -2071 if rebuilt_json.get(player_id) == None: -2072 rebuilt_json[player_id] = {} -2073 -2074 rebuilt_json[player_id]['game_id'] = game_id -2075 rebuilt_json[player_id]['team_name'] = team_name -2076 rebuilt_json[player_id]['team_confrence'] = team_confrence -2077 rebuilt_json[player_id]['player_id'] = player_id -2078 rebuilt_json[player_id]['player_name'] = player_name -2079 rebuilt_json[player_id]['home_away'] = home_away -2080 rebuilt_json[player_id]['rushing_YDS'] = player_stat -2081 -2082 elif stat['name'] == "AVG": # rushing_AVG -2083 for i in stat['athletes']: -2084 player_id = int(i['id']) -2085 player_name = i['name'] -2086 player_stat = float(i['stat']) -2087 -2088 if rebuilt_json.get(player_id) == None: -2089 rebuilt_json[player_id] = {} -2090 -2091 rebuilt_json[player_id]['game_id'] = game_id -2092 rebuilt_json[player_id]['team_name'] = team_name -2093 rebuilt_json[player_id]['team_confrence'] = team_confrence -2094 rebuilt_json[player_id]['player_id'] = player_id -2095 rebuilt_json[player_id]['player_name'] = player_name -2096 rebuilt_json[player_id]['home_away'] = home_away -2097 rebuilt_json[player_id]['rushing_AVG'] = player_stat -2098 -2099 elif stat['name'] == "TD": # rushing_TD -2100 for i in stat['athletes']: -2101 player_id = int(i['id']) -2102 player_name = i['name'] -2103 player_stat = int(i['stat']) -2104 -2105 if rebuilt_json.get(player_id) == None: -2106 rebuilt_json[player_id] = {} -2107 -2108 rebuilt_json[player_id]['game_id'] = game_id -2109 rebuilt_json[player_id]['team_name'] = team_name -2110 rebuilt_json[player_id]['team_confrence'] = team_confrence -2111 rebuilt_json[player_id]['player_id'] = player_id -2112 rebuilt_json[player_id]['player_name'] = player_name -2113 rebuilt_json[player_id]['home_away'] = home_away -2114 rebuilt_json[player_id]['rushing_TD'] = player_stat -2115 -2116 elif stat['name'] == "LONG": # rushing_LONG -2117 for i in stat['athletes']: -2118 player_id = int(i['id']) -2119 player_name = i['name'] -2120 player_stat = int(i['stat']) -2121 -2122 if rebuilt_json.get(player_id) == None: -2123 rebuilt_json[player_id] = {} -2124 -2125 rebuilt_json[player_id]['game_id'] = game_id -2126 rebuilt_json[player_id]['team_name'] = team_name -2127 rebuilt_json[player_id]['team_confrence'] = team_confrence -2128 rebuilt_json[player_id]['player_id'] = player_id -2129 rebuilt_json[player_id]['player_name'] = player_name -2130 rebuilt_json[player_id]['home_away'] = home_away -2131 rebuilt_json[player_id]['rushing_LONG'] = player_stat -2132 -2133 else: -2134 raise IndexError( -2135 f"Unhandled stat: \t{stat['name']}") -2136 -2137 elif s_category['name'] == "receiving": -2138 for stat in s_category['types']: -2139 if stat['name'] == "REC": # receiving_REC -2140 for i in stat['athletes']: -2141 player_id = int(i['id']) -2142 player_name = i['name'] -2143 player_stat = int(i['stat']) -2144 -2145 if rebuilt_json.get(player_id) == None: -2146 rebuilt_json[player_id] = {} -2147 -2148 rebuilt_json[player_id]['game_id'] = game_id -2149 rebuilt_json[player_id]['team_name'] = team_name -2150 rebuilt_json[player_id]['team_confrence'] = team_confrence -2151 rebuilt_json[player_id]['player_id'] = player_id -2152 rebuilt_json[player_id]['player_name'] = player_name -2153 rebuilt_json[player_id]['home_away'] = home_away -2154 rebuilt_json[player_id]['receiving_REC'] = player_stat -2155 -2156 elif stat['name'] == "YDS": # receiving_YDS -2157 for i in stat['athletes']: -2158 player_id = int(i['id']) -2159 player_name = i['name'] -2160 player_stat = int(i['stat']) -2161 -2162 if rebuilt_json.get(player_id) == None: -2163 rebuilt_json[player_id] = {} -2164 -2165 rebuilt_json[player_id]['game_id'] = game_id -2166 rebuilt_json[player_id]['team_name'] = team_name -2167 rebuilt_json[player_id]['team_confrence'] = team_confrence -2168 rebuilt_json[player_id]['player_id'] = player_id -2169 rebuilt_json[player_id]['player_name'] = player_name -2170 rebuilt_json[player_id]['home_away'] = home_away -2171 rebuilt_json[player_id]['receiving_YDS'] = player_stat -2172 -2173 elif stat['name'] == "AVG": # receiving_AVG -2174 for i in stat['athletes']: -2175 player_id = int(i['id']) -2176 player_name = i['name'] -2177 player_stat = float(i['stat']) -2178 -2179 if rebuilt_json.get(player_id) == None: -2180 rebuilt_json[player_id] = {} -2181 -2182 rebuilt_json[player_id]['game_id'] = game_id -2183 rebuilt_json[player_id]['team_name'] = team_name -2184 rebuilt_json[player_id]['team_confrence'] = team_confrence -2185 rebuilt_json[player_id]['player_id'] = player_id -2186 rebuilt_json[player_id]['player_name'] = player_name -2187 rebuilt_json[player_id]['home_away'] = home_away -2188 rebuilt_json[player_id]['receiving_AVG'] = player_stat -2189 -2190 elif stat['name'] == "TD": # receiving_TD -2191 for i in stat['athletes']: -2192 player_id = int(i['id']) -2193 player_name = i['name'] -2194 player_stat = int(i['stat']) -2195 -2196 if rebuilt_json.get(player_id) == None: -2197 rebuilt_json[player_id] = {} -2198 -2199 rebuilt_json[player_id]['game_id'] = game_id -2200 rebuilt_json[player_id]['team_name'] = team_name -2201 rebuilt_json[player_id]['team_confrence'] = team_confrence -2202 rebuilt_json[player_id]['player_id'] = player_id -2203 rebuilt_json[player_id]['player_name'] = player_name -2204 rebuilt_json[player_id]['home_away'] = home_away -2205 rebuilt_json[player_id]['receiving_TD'] = player_stat -2206 -2207 elif stat['name'] == "LONG": # receiving_LONG -2208 for i in stat['athletes']: -2209 player_id = int(i['id']) -2210 player_name = i['name'] -2211 player_stat = int(i['stat']) -2212 -2213 if rebuilt_json.get(player_id) == None: -2214 rebuilt_json[player_id] = {} -2215 -2216 rebuilt_json[player_id]['game_id'] = game_id -2217 rebuilt_json[player_id]['team_name'] = team_name -2218 rebuilt_json[player_id]['team_confrence'] = team_confrence -2219 rebuilt_json[player_id]['player_id'] = player_id -2220 rebuilt_json[player_id]['player_name'] = player_name -2221 rebuilt_json[player_id]['home_away'] = home_away -2222 rebuilt_json[player_id]['receiving_LONG'] = player_stat -2223 -2224 else: -2225 raise IndexError( -2226 f"Unhandled stat: \t{stat['name']}") -2227 -2228 elif s_category['name'] == "fumbles": -2229 for stat in s_category['types']: -2230 if stat['name'] == "FUM": # fumbles_FUM -2231 for i in stat['athletes']: -2232 player_id = int(i['id']) -2233 player_name = i['name'] -2234 player_stat = int(i['stat']) -2235 -2236 if rebuilt_json.get(player_id) == None: -2237 rebuilt_json[player_id] = {} -2238 -2239 rebuilt_json[player_id]['game_id'] = game_id -2240 rebuilt_json[player_id]['team_name'] = team_name -2241 rebuilt_json[player_id]['team_confrence'] = team_confrence -2242 rebuilt_json[player_id]['player_id'] = player_id -2243 rebuilt_json[player_id]['player_name'] = player_name -2244 rebuilt_json[player_id]['home_away'] = home_away -2245 rebuilt_json[player_id]['fumbles_FUM'] = player_stat -2246 -2247 elif stat['name'] == "LOST": # fumbles_LOST -2248 for i in stat['athletes']: -2249 player_id = int(i['id']) -2250 player_name = i['name'] -2251 player_stat = int(i['stat']) -2252 -2253 if rebuilt_json.get(player_id) == None: -2254 rebuilt_json[player_id] = {} -2255 -2256 rebuilt_json[player_id]['game_id'] = game_id -2257 rebuilt_json[player_id]['team_name'] = team_name -2258 rebuilt_json[player_id]['team_confrence'] = team_confrence -2259 rebuilt_json[player_id]['player_id'] = player_id -2260 rebuilt_json[player_id]['player_name'] = player_name -2261 rebuilt_json[player_id]['home_away'] = home_away -2262 rebuilt_json[player_id]['fumbles_LOST'] = player_stat -2263 -2264 elif stat['name'] == "REC": # fumbles_REC -2265 for i in stat['athletes']: -2266 player_id = int(i['id']) -2267 player_name = i['name'] -2268 player_stat = int(i['stat']) -2269 -2270 if rebuilt_json.get(player_id) == None: -2271 rebuilt_json[player_id] = {} -2272 -2273 rebuilt_json[player_id]['game_id'] = game_id -2274 rebuilt_json[player_id]['team_name'] = team_name -2275 rebuilt_json[player_id]['team_confrence'] = team_confrence -2276 rebuilt_json[player_id]['player_id'] = player_id -2277 rebuilt_json[player_id]['player_name'] = player_name -2278 rebuilt_json[player_id]['home_away'] = home_away -2279 rebuilt_json[player_id]['fumbles_REC'] = player_stat -2280 -2281 else: -2282 raise IndexError( -2283 f"Unhandled stat: \t{stat['name']}") -2284 -2285 elif s_category['name'] == "defensive": -2286 for stat in s_category['types']: -2287 if stat['name'] == "TOT": # defensive_TOT -2288 for i in stat['athletes']: -2289 player_id = int(i['id']) -2290 player_name = i['name'] -2291 player_stat = int(i['stat']) -2292 -2293 if rebuilt_json.get(player_id) == None: -2294 rebuilt_json[player_id] = {} -2295 -2296 rebuilt_json[player_id]['game_id'] = game_id -2297 rebuilt_json[player_id]['team_name'] = team_name -2298 rebuilt_json[player_id]['team_confrence'] = team_confrence -2299 rebuilt_json[player_id]['player_id'] = player_id -2300 rebuilt_json[player_id]['player_name'] = player_name -2301 rebuilt_json[player_id]['home_away'] = home_away -2302 rebuilt_json[player_id]['defensive_TOT'] = player_stat -2303 -2304 elif stat['name'] == "SOLO": # defensive_SOLO -2305 for i in stat['athletes']: -2306 player_id = int(i['id']) -2307 player_name = i['name'] -2308 player_stat = int(i['stat']) -2309 -2310 if rebuilt_json.get(player_id) == None: -2311 rebuilt_json[player_id] = {} -2312 -2313 rebuilt_json[player_id]['game_id'] = game_id -2314 rebuilt_json[player_id]['team_name'] = team_name -2315 rebuilt_json[player_id]['team_confrence'] = team_confrence -2316 rebuilt_json[player_id]['player_id'] = player_id -2317 rebuilt_json[player_id]['player_name'] = player_name -2318 rebuilt_json[player_id]['home_away'] = home_away -2319 rebuilt_json[player_id]['defensive_SOLO'] = player_stat -2320 -2321 elif stat['name'] == "TFL": # defensive_TFL -2322 for i in stat['athletes']: -2323 player_id = int(i['id']) -2324 player_name = i['name'] -2325 player_stat = float(i['stat']) -2326 -2327 if rebuilt_json.get(player_id) == None: -2328 rebuilt_json[player_id] = {} -2329 -2330 rebuilt_json[player_id]['game_id'] = game_id -2331 rebuilt_json[player_id]['team_name'] = team_name -2332 rebuilt_json[player_id]['team_confrence'] = team_confrence -2333 rebuilt_json[player_id]['player_id'] = player_id -2334 rebuilt_json[player_id]['player_name'] = player_name -2335 rebuilt_json[player_id]['home_away'] = home_away -2336 rebuilt_json[player_id]['defensive_TFL'] = player_stat -2337 -2338 elif stat['name'] == "QB HUR": # defensive_QB HUR -2339 for i in stat['athletes']: -2340 player_id = int(i['id']) -2341 player_name = i['name'] -2342 player_stat = int(i['stat']) -2343 -2344 if rebuilt_json.get(player_id) == None: -2345 rebuilt_json[player_id] = {} -2346 -2347 rebuilt_json[player_id]['game_id'] = game_id -2348 rebuilt_json[player_id]['team_name'] = team_name -2349 rebuilt_json[player_id]['team_confrence'] = team_confrence -2350 rebuilt_json[player_id]['player_id'] = player_id -2351 rebuilt_json[player_id]['player_name'] = player_name -2352 rebuilt_json[player_id]['home_away'] = home_away -2353 rebuilt_json[player_id]['defensive_QB HUR'] = player_stat -2354 -2355 elif stat['name'] == "SACKS": # defensive_SACKS -2356 for i in stat['athletes']: -2357 player_id = int(i['id']) -2358 player_name = i['name'] -2359 player_stat = float(i['stat']) -2360 -2361 if rebuilt_json.get(player_id) == None: -2362 rebuilt_json[player_id] = {} -2363 -2364 rebuilt_json[player_id]['game_id'] = game_id -2365 rebuilt_json[player_id]['team_name'] = team_name -2366 rebuilt_json[player_id]['team_confrence'] = team_confrence -2367 rebuilt_json[player_id]['player_id'] = player_id -2368 rebuilt_json[player_id]['player_name'] = player_name -2369 rebuilt_json[player_id]['home_away'] = home_away -2370 rebuilt_json[player_id]['defensive_SACKS'] = player_stat -2371 -2372 elif stat['name'] == "PD": # defensive_PD -2373 for i in stat['athletes']: -2374 player_id = int(i['id']) -2375 player_name = i['name'] -2376 player_stat = int(i['stat']) -2377 -2378 if rebuilt_json.get(player_id) == None: -2379 rebuilt_json[player_id] = {} -2380 -2381 rebuilt_json[player_id]['game_id'] = game_id -2382 rebuilt_json[player_id]['team_name'] = team_name -2383 rebuilt_json[player_id]['team_confrence'] = team_confrence -2384 rebuilt_json[player_id]['player_id'] = player_id -2385 rebuilt_json[player_id]['player_name'] = player_name -2386 rebuilt_json[player_id]['home_away'] = home_away -2387 rebuilt_json[player_id]['defensive_PD'] = player_stat -2388 -2389 elif stat['name'] == "TD": # defensive_TD -2390 for i in stat['athletes']: -2391 player_id = int(i['id']) -2392 player_name = i['name'] -2393 player_stat = int(i['stat']) -2394 -2395 if rebuilt_json.get(player_id) == None: -2396 rebuilt_json[player_id] = {} -2397 -2398 rebuilt_json[player_id]['game_id'] = game_id -2399 rebuilt_json[player_id]['team_name'] = team_name -2400 rebuilt_json[player_id]['team_confrence'] = team_confrence -2401 rebuilt_json[player_id]['player_id'] = player_id -2402 rebuilt_json[player_id]['player_name'] = player_name -2403 rebuilt_json[player_id]['home_away'] = home_away -2404 rebuilt_json[player_id]['defensive_TD'] = player_stat -2405 -2406 else: -2407 raise IndexError( -2408 f"Unhandled stat: \t{stat['name']}") -2409 -2410 elif s_category['name'] == "interceptions": -2411 for stat in s_category['types']: -2412 if stat['name'] == "INT": # interceptions_INT -2413 for i in stat['athletes']: -2414 player_id = int(i['id']) -2415 player_name = i['name'] -2416 player_stat = int(i['stat']) -2417 -2418 if rebuilt_json.get(player_id) == None: -2419 rebuilt_json[player_id] = {} -2420 -2421 rebuilt_json[player_id]['game_id'] = game_id -2422 rebuilt_json[player_id]['team_name'] = team_name -2423 rebuilt_json[player_id]['team_confrence'] = team_confrence -2424 rebuilt_json[player_id]['player_id'] = player_id -2425 rebuilt_json[player_id]['player_name'] = player_name -2426 rebuilt_json[player_id]['home_away'] = home_away -2427 rebuilt_json[player_id]['interceptions_INT'] = player_stat -2428 -2429 elif stat['name'] == "YDS": # interceptions_YDS -2430 for i in stat['athletes']: -2431 player_id = int(i['id']) -2432 player_name = i['name'] -2433 player_stat = int(i['stat']) -2434 -2435 if rebuilt_json.get(player_id) == None: -2436 rebuilt_json[player_id] = {} -2437 -2438 rebuilt_json[player_id]['game_id'] = game_id -2439 rebuilt_json[player_id]['team_name'] = team_name -2440 rebuilt_json[player_id]['team_confrence'] = team_confrence -2441 rebuilt_json[player_id]['player_id'] = player_id -2442 rebuilt_json[player_id]['player_name'] = player_name -2443 rebuilt_json[player_id]['home_away'] = home_away -2444 rebuilt_json[player_id]['interceptions_YDS'] = player_stat -2445 -2446 elif stat['name'] == "TD": # interceptions_TD -2447 for i in stat['athletes']: -2448 player_id = int(i['id']) -2449 player_name = i['name'] -2450 player_stat = int(i['stat']) -2451 -2452 if rebuilt_json.get(player_id) == None: -2453 rebuilt_json[player_id] = {} -2454 -2455 rebuilt_json[player_id]['game_id'] = game_id -2456 rebuilt_json[player_id]['team_name'] = team_name -2457 rebuilt_json[player_id]['team_confrence'] = team_confrence -2458 rebuilt_json[player_id]['player_id'] = player_id -2459 rebuilt_json[player_id]['player_name'] = player_name -2460 rebuilt_json[player_id]['home_away'] = home_away -2461 rebuilt_json[player_id]['interceptions_TD'] = player_stat -2462 -2463 else: -2464 raise IndexError( -2465 f"Unhandled stat: \t{stat['name']}") -2466 -2467 elif s_category['name'] == "punting": -2468 for stat in s_category['types']: -2469 if stat['name'] == "NO": # punting_NO -2470 for i in stat['athletes']: -2471 player_id = int(i['id']) -2472 player_name = i['name'] -2473 player_stat = int(i['stat']) -2474 -2475 if rebuilt_json.get(player_id) == None: -2476 rebuilt_json[player_id] = {} -2477 -2478 rebuilt_json[player_id]['game_id'] = game_id -2479 rebuilt_json[player_id]['team_name'] = team_name -2480 rebuilt_json[player_id]['team_confrence'] = team_confrence -2481 rebuilt_json[player_id]['player_id'] = player_id -2482 rebuilt_json[player_id]['player_name'] = player_name -2483 rebuilt_json[player_id]['home_away'] = home_away -2484 rebuilt_json[player_id]['punting_NO'] = player_stat -2485 -2486 elif stat['name'] == "YDS": # punting_YDS -2487 for i in stat['athletes']: -2488 player_id = int(i['id']) -2489 player_name = i['name'] -2490 player_stat = int(i['stat']) -2491 -2492 if rebuilt_json.get(player_id) == None: -2493 rebuilt_json[player_id] = {} -2494 -2495 rebuilt_json[player_id]['game_id'] = game_id -2496 rebuilt_json[player_id]['team_name'] = team_name -2497 rebuilt_json[player_id]['team_confrence'] = team_confrence -2498 rebuilt_json[player_id]['player_id'] = player_id -2499 rebuilt_json[player_id]['player_name'] = player_name -2500 rebuilt_json[player_id]['home_away'] = home_away -2501 rebuilt_json[player_id]['punting_YDS'] = player_stat -2502 -2503 elif stat['name'] == "AVG": # punting_AVG -2504 for i in stat['athletes']: -2505 player_id = int(i['id']) -2506 player_name = i['name'] -2507 player_stat = float(i['stat']) -2508 -2509 if rebuilt_json.get(player_id) == None: -2510 rebuilt_json[player_id] = {} -2511 -2512 rebuilt_json[player_id]['game_id'] = game_id -2513 rebuilt_json[player_id]['team_name'] = team_name -2514 rebuilt_json[player_id]['team_confrence'] = team_confrence -2515 rebuilt_json[player_id]['player_id'] = player_id -2516 rebuilt_json[player_id]['player_name'] = player_name -2517 rebuilt_json[player_id]['home_away'] = home_away -2518 rebuilt_json[player_id]['punting_AVG'] = player_stat -2519 -2520 elif stat['name'] == "TB": # punting_TB -2521 for i in stat['athletes']: -2522 player_id = int(i['id']) -2523 player_name = i['name'] -2524 player_stat = int(i['stat']) -2525 -2526 if rebuilt_json.get(player_id) == None: -2527 rebuilt_json[player_id] = {} -2528 -2529 rebuilt_json[player_id]['game_id'] = game_id -2530 rebuilt_json[player_id]['team_name'] = team_name -2531 rebuilt_json[player_id]['team_confrence'] = team_confrence -2532 rebuilt_json[player_id]['player_id'] = player_id -2533 rebuilt_json[player_id]['player_name'] = player_name -2534 rebuilt_json[player_id]['home_away'] = home_away -2535 rebuilt_json[player_id]['punting_TB'] = player_stat -2536 -2537 elif stat['name'] == "In 20": # punting_In 20 -2538 for i in stat['athletes']: -2539 player_id = int(i['id']) -2540 player_name = i['name'] -2541 player_stat = int(i['stat']) -2542 -2543 if rebuilt_json.get(player_id) == None: -2544 rebuilt_json[player_id] = {} -2545 -2546 rebuilt_json[player_id]['game_id'] = game_id -2547 rebuilt_json[player_id]['team_name'] = team_name -2548 rebuilt_json[player_id]['team_confrence'] = team_confrence -2549 rebuilt_json[player_id]['player_id'] = player_id -2550 rebuilt_json[player_id]['player_name'] = player_name -2551 rebuilt_json[player_id]['home_away'] = home_away -2552 rebuilt_json[player_id]['punting_In 20'] = player_stat -2553 -2554 elif stat['name'] == "LONG": # punting_LONG -2555 for i in stat['athletes']: -2556 player_id = int(i['id']) -2557 player_name = i['name'] -2558 player_stat = int(i['stat']) -2559 -2560 if rebuilt_json.get(player_id) == None: -2561 rebuilt_json[player_id] = {} -2562 -2563 rebuilt_json[player_id]['game_id'] = game_id -2564 rebuilt_json[player_id]['team_name'] = team_name -2565 rebuilt_json[player_id]['team_confrence'] = team_confrence -2566 rebuilt_json[player_id]['player_id'] = player_id -2567 rebuilt_json[player_id]['player_name'] = player_name -2568 rebuilt_json[player_id]['home_away'] = home_away -2569 rebuilt_json[player_id]['punting_LONG'] = player_stat -2570 -2571 else: -2572 raise IndexError( -2573 f"Unhandled stat: \t{stat['name']}") -2574 -2575 elif s_category['name'] == "kicking": -2576 for stat in s_category['types']: -2577 if stat['name'] == "FG": # kicking_FG -2578 for i in stat['athletes']: -2579 player_id = int(i['id']) -2580 player_name = i['name'] -2581 player_stat = i['stat'] -2582 -2583 if rebuilt_json.get(player_id) == None: -2584 rebuilt_json[player_id] = {} -2585 -2586 rebuilt_json[player_id]['game_id'] = game_id -2587 rebuilt_json[player_id]['team_name'] = team_name -2588 rebuilt_json[player_id]['team_confrence'] = team_confrence -2589 rebuilt_json[player_id]['player_id'] = player_id -2590 rebuilt_json[player_id]['player_name'] = player_name -2591 rebuilt_json[player_id]['home_away'] = home_away -2592 rebuilt_json[player_id]['kicking_FG'] = player_stat -2593 -2594 elif stat['name'] == "TOT": # kicking_FG, special case -2595 for i in stat['athletes']: -2596 player_id = int(i['id']) -2597 player_name = i['name'] -2598 player_stat = i['stat'] -2599 -2600 if rebuilt_json.get(player_id) == None: -2601 rebuilt_json[player_id] = {} -2602 -2603 rebuilt_json[player_id]['game_id'] = game_id -2604 rebuilt_json[player_id]['team_name'] = team_name -2605 rebuilt_json[player_id]['team_confrence'] = team_confrence -2606 rebuilt_json[player_id]['player_id'] = player_id -2607 rebuilt_json[player_id]['player_name'] = player_name -2608 rebuilt_json[player_id]['home_away'] = home_away -2609 rebuilt_json[player_id]['kicking_FG'] = player_stat -2610 -2611 elif stat['name'] == "PCT": # kicking_PCT -2612 for i in stat['athletes']: -2613 player_id = int(i['id']) -2614 player_name = i['name'] -2615 player_stat = float(i['stat']) -2616 -2617 if rebuilt_json.get(player_id) == None: -2618 rebuilt_json[player_id] = {} -2619 -2620 rebuilt_json[player_id]['game_id'] = game_id -2621 rebuilt_json[player_id]['team_name'] = team_name -2622 rebuilt_json[player_id]['team_confrence'] = team_confrence -2623 rebuilt_json[player_id]['player_id'] = player_id -2624 rebuilt_json[player_id]['player_name'] = player_name -2625 rebuilt_json[player_id]['home_away'] = home_away -2626 rebuilt_json[player_id]['kicking_PCT'] = player_stat -2627 -2628 elif stat['name'] == "LONG": # kicking_LONG -2629 for i in stat['athletes']: -2630 player_id = int(i['id']) -2631 player_name = i['name'] -2632 player_stat = int(i['stat']) -2633 -2634 if rebuilt_json.get(player_id) == None: -2635 rebuilt_json[player_id] = {} -2636 -2637 rebuilt_json[player_id]['game_id'] = game_id -2638 rebuilt_json[player_id]['team_name'] = team_name -2639 rebuilt_json[player_id]['team_confrence'] = team_confrence -2640 rebuilt_json[player_id]['player_id'] = player_id -2641 rebuilt_json[player_id]['player_name'] = player_name -2642 rebuilt_json[player_id]['home_away'] = home_away -2643 rebuilt_json[player_id]['kicking_LONG'] = player_stat -2644 -2645 elif stat['name'] == "XP": # kicking_XP -2646 for i in stat['athletes']: -2647 player_id = int(i['id']) -2648 player_name = i['name'] -2649 player_stat = i['stat'] -2650 -2651 if rebuilt_json.get(player_id) == None: -2652 rebuilt_json[player_id] = {} -2653 -2654 rebuilt_json[player_id]['game_id'] = game_id -2655 rebuilt_json[player_id]['team_name'] = team_name -2656 rebuilt_json[player_id]['team_confrence'] = team_confrence -2657 rebuilt_json[player_id]['player_id'] = player_id -2658 rebuilt_json[player_id]['player_name'] = player_name -2659 rebuilt_json[player_id]['home_away'] = home_away -2660 rebuilt_json[player_id]['kicking_XP'] = player_stat -2661 -2662 elif stat['name'] == "PTS": # kicking_PTS -2663 for i in stat['athletes']: -2664 player_id = int(i['id']) -2665 player_name = i['name'] -2666 player_stat = int(i['stat']) -2667 -2668 if rebuilt_json.get(player_id) == None: -2669 rebuilt_json[player_id] = {} -2670 -2671 rebuilt_json[player_id]['game_id'] = game_id -2672 rebuilt_json[player_id]['team_name'] = team_name -2673 rebuilt_json[player_id]['team_confrence'] = team_confrence -2674 rebuilt_json[player_id]['player_id'] = player_id -2675 rebuilt_json[player_id]['player_name'] = player_name -2676 rebuilt_json[player_id]['home_away'] = home_away -2677 rebuilt_json[player_id]['kicking_PTS'] = player_stat -2678 -2679 else: -2680 raise IndexError( -2681 f"Unhandled stat: \t{stat['name']}") -2682 -2683 elif s_category['name'] == "kickReturns": -2684 for stat in s_category['types']: -2685 if stat['name'] == "NO": # kickReturns_NO -2686 for i in stat['athletes']: -2687 player_id = int(i['id']) -2688 player_name = i['name'] -2689 player_stat = int(i['stat']) -2690 -2691 if rebuilt_json.get(player_id) == None: -2692 rebuilt_json[player_id] = {} -2693 -2694 rebuilt_json[player_id]['game_id'] = game_id -2695 rebuilt_json[player_id]['team_name'] = team_name -2696 rebuilt_json[player_id]['team_confrence'] = team_confrence -2697 rebuilt_json[player_id]['player_id'] = player_id -2698 rebuilt_json[player_id]['player_name'] = player_name -2699 rebuilt_json[player_id]['home_away'] = home_away -2700 rebuilt_json[player_id]['kickReturns_NO'] = player_stat -2701 -2702 elif stat['name'] == "YDS": # kickReturns_YDS -2703 for i in stat['athletes']: -2704 player_id = int(i['id']) -2705 player_name = i['name'] -2706 player_stat = int(i['stat']) -2707 -2708 if rebuilt_json.get(player_id) == None: -2709 rebuilt_json[player_id] = {} -2710 -2711 rebuilt_json[player_id]['game_id'] = game_id -2712 rebuilt_json[player_id]['team_name'] = team_name -2713 rebuilt_json[player_id]['team_confrence'] = team_confrence -2714 rebuilt_json[player_id]['player_id'] = player_id -2715 rebuilt_json[player_id]['player_name'] = player_name -2716 rebuilt_json[player_id]['home_away'] = home_away -2717 rebuilt_json[player_id]['kickReturns_YDS'] = player_stat -2718 -2719 elif stat['name'] == "AVG": # kickReturns_AVG -2720 for i in stat['athletes']: -2721 player_id = int(i['id']) -2722 player_name = i['name'] -2723 player_stat = float(i['stat']) -2724 -2725 if rebuilt_json.get(player_id) == None: -2726 rebuilt_json[player_id] = {} -2727 -2728 rebuilt_json[player_id]['game_id'] = game_id -2729 rebuilt_json[player_id]['team_name'] = team_name -2730 rebuilt_json[player_id]['team_confrence'] = team_confrence -2731 rebuilt_json[player_id]['player_id'] = player_id -2732 rebuilt_json[player_id]['player_name'] = player_name -2733 rebuilt_json[player_id]['home_away'] = home_away -2734 rebuilt_json[player_id]['kickReturns_AVG'] = player_stat -2735 -2736 elif stat['name'] == "TD": # kickReturns_TD -2737 for i in stat['athletes']: -2738 player_id = int(i['id']) -2739 player_name = i['name'] -2740 player_stat = int(i['stat']) -2741 -2742 if rebuilt_json.get(player_id) == None: -2743 rebuilt_json[player_id] = {} -2744 -2745 rebuilt_json[player_id]['game_id'] = game_id -2746 rebuilt_json[player_id]['team_name'] = team_name -2747 rebuilt_json[player_id]['team_confrence'] = team_confrence -2748 rebuilt_json[player_id]['player_id'] = player_id -2749 rebuilt_json[player_id]['player_name'] = player_name -2750 rebuilt_json[player_id]['home_away'] = home_away -2751 rebuilt_json[player_id]['kickReturns_TD'] = player_stat -2752 -2753 elif stat['name'] == "LONG": # kickReturns_LONG -2754 for i in stat['athletes']: -2755 player_id = int(i['id']) -2756 player_name = i['name'] -2757 player_stat = int(i['stat']) -2758 -2759 if rebuilt_json.get(player_id) == None: -2760 rebuilt_json[player_id] = {} -2761 -2762 rebuilt_json[player_id]['game_id'] = game_id -2763 rebuilt_json[player_id]['team_name'] = team_name -2764 rebuilt_json[player_id]['team_confrence'] = team_confrence -2765 rebuilt_json[player_id]['player_id'] = player_id -2766 rebuilt_json[player_id]['player_name'] = player_name -2767 rebuilt_json[player_id]['home_away'] = home_away -2768 rebuilt_json[player_id]['kickReturns_LONG'] = player_stat -2769 -2770 else: -2771 raise IndexError( -2772 f"Unhandled stat: \t{stat['name']}") -2773 -2774 elif s_category['name'] == "puntReturns": -2775 for stat in s_category['types']: -2776 if stat['name'] == "NO": # puntReturns_NO -2777 for i in stat['athletes']: -2778 player_id = int(i['id']) -2779 player_name = i['name'] -2780 player_stat = int(i['stat']) -2781 -2782 if rebuilt_json.get(player_id) == None: -2783 rebuilt_json[player_id] = {} -2784 -2785 rebuilt_json[player_id]['game_id'] = game_id -2786 rebuilt_json[player_id]['team_name'] = team_name -2787 rebuilt_json[player_id]['team_confrence'] = team_confrence -2788 rebuilt_json[player_id]['player_id'] = player_id -2789 rebuilt_json[player_id]['player_name'] = player_name -2790 rebuilt_json[player_id]['home_away'] = home_away -2791 rebuilt_json[player_id]['puntReturns_NO'] = player_stat -2792 -2793 elif stat['name'] == "YDS": # puntReturns_YDS -2794 for i in stat['athletes']: -2795 player_id = int(i['id']) -2796 player_name = i['name'] -2797 player_stat = int(i['stat']) -2798 -2799 if rebuilt_json.get(player_id) == None: -2800 rebuilt_json[player_id] = {} -2801 -2802 rebuilt_json[player_id]['game_id'] = game_id -2803 rebuilt_json[player_id]['team_name'] = team_name -2804 rebuilt_json[player_id]['team_confrence'] = team_confrence -2805 rebuilt_json[player_id]['player_id'] = player_id -2806 rebuilt_json[player_id]['player_name'] = player_name -2807 rebuilt_json[player_id]['home_away'] = home_away -2808 rebuilt_json[player_id]['puntReturns_YDS'] = player_stat -2809 -2810 elif stat['name'] == "AVG": # puntReturns_AVG -2811 for i in stat['athletes']: -2812 player_id = int(i['id']) -2813 player_name = i['name'] -2814 player_stat = float(i['stat']) -2815 -2816 if rebuilt_json.get(player_id) == None: -2817 rebuilt_json[player_id] = {} -2818 -2819 rebuilt_json[player_id]['game_id'] = game_id -2820 rebuilt_json[player_id]['team_name'] = team_name -2821 rebuilt_json[player_id]['team_confrence'] = team_confrence -2822 rebuilt_json[player_id]['player_id'] = player_id -2823 rebuilt_json[player_id]['player_name'] = player_name -2824 rebuilt_json[player_id]['home_away'] = home_away -2825 rebuilt_json[player_id]['puntReturns_AVG'] = player_stat -2826 -2827 elif stat['name'] == "TD": # puntReturns_TD -2828 for i in stat['athletes']: -2829 player_id = int(i['id']) -2830 player_name = i['name'] -2831 player_stat = int(i['stat']) -2832 -2833 if rebuilt_json.get(player_id) == None: -2834 rebuilt_json[player_id] = {} -2835 -2836 rebuilt_json[player_id]['game_id'] = game_id -2837 rebuilt_json[player_id]['team_name'] = team_name -2838 rebuilt_json[player_id]['team_confrence'] = team_confrence -2839 rebuilt_json[player_id]['player_id'] = player_id -2840 rebuilt_json[player_id]['player_name'] = player_name -2841 rebuilt_json[player_id]['home_away'] = home_away -2842 rebuilt_json[player_id]['puntReturns_TD'] = player_stat -2843 -2844 elif stat['name'] == "LONG": # puntReturns_LONG -2845 for i in stat['athletes']: -2846 player_id = int(i['id']) -2847 player_name = i['name'] -2848 player_stat = int(i['stat']) -2849 -2850 if rebuilt_json.get(player_id) == None: -2851 rebuilt_json[player_id] = {} -2852 -2853 rebuilt_json[player_id]['game_id'] = game_id -2854 rebuilt_json[player_id]['team_name'] = team_name -2855 rebuilt_json[player_id]['team_confrence'] = team_confrence -2856 rebuilt_json[player_id]['player_id'] = player_id -2857 rebuilt_json[player_id]['player_name'] = player_name -2858 rebuilt_json[player_id]['home_away'] = home_away -2859 rebuilt_json[player_id]['puntReturns_LONG'] = player_stat -2860 -2861 else: -2862 raise IndexError( -2863 f"Unhandled stat: \t{stat['name']}") -2864 -2865 else: -2866 raise IndexError(f"Unhandled stat category: \t{ -2867 s_category['name']}") +1672 # You can also tell this function to just return the API call as +1673 # a Dictionary (read: JSON) object. +1674 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1675 json_data = get_cfbd_player_game_stats( +1676 season=2020, +1677 week=10, +1678 return_as_dict=True +1679 ) +1680 print(json_data) +1681 +1682 ``` +1683 Returns +1684 ---------- +1685 A pandas `DataFrame` object with player game stats data, +1686 or (if `return_as_dict` is set to `True`) +1687 a dictionary object with player game stats data. +1688 +1689 """ +1690 +1691 rebuilt_json = {} +1692 now = datetime.now() +1693 cfb_games_df = pd.DataFrame() +1694 row_df = pd.DataFrame() +1695 url = "https://api.collegefootballdata.com/games/players" +1696 stat_columns = [ +1697 'game_id', +1698 'team_name', +1699 'team_confrence', +1700 'player_id', +1701 'player_name', +1702 'home_away', +1703 # PASS +1704 'passing_C/ATT', +1705 'passing_COMP', +1706 'passing_ATT', +1707 'passing_YDS', +1708 'passing_AVG', +1709 'passing_TD', +1710 'passing_INT', +1711 'passing_QBR', +1712 # RUSH +1713 'rushing_CAR', +1714 'rushing_YDS', +1715 'rushing_AVG', +1716 'rushing_TD', +1717 'rushing_LONG', +1718 # REC +1719 'receiving_REC', +1720 'receiving_YDS', +1721 'receiving_AVG', +1722 'receiving_TD', +1723 'receiving_LONG', +1724 # FUM +1725 'fumbles_FUM', +1726 'fumbles_LOST', +1727 'fumbles_REC', +1728 # DEFENSE +1729 'defensive_TOT', +1730 'defensive_SOLO', +1731 'defensive_TFL', +1732 'defensive_QB HUR', +1733 'defensive_SACKS', +1734 'defensive_PD', +1735 'defensive_TD', +1736 # INT +1737 'interceptions_INT', +1738 'interceptions_YDS', +1739 'interceptions_TD', +1740 # PUNT +1741 'punting_NO', +1742 'punting_YDS', +1743 'punting_AVG', +1744 'punting_TB', +1745 'punting_In 20', +1746 'punting_LONG', +1747 # KICK +1748 'kicking_FG', +1749 'kicking_FGM', +1750 'kicking_FGA', +1751 'kicking_PCT', +1752 'kicking_LONG', +1753 'kicking_XP', +1754 'kicking_XPM', +1755 'kicking_XPA', +1756 'kicking_PTS', +1757 # KR +1758 'kickReturns_NO', +1759 'kickReturns_YDS', +1760 'kickReturns_AVG', +1761 'kickReturns_TD', +1762 'kickReturns_LONG', +1763 # PR +1764 'puntReturns_NO', +1765 'puntReturns_YDS', +1766 'puntReturns_AVG', +1767 'puntReturns_TD', +1768 'puntReturns_LONG' +1769 ] +1770 +1771 ######################################################################################################################################################################################################## +1772 +1773 if api_key != None: +1774 real_api_key = api_key +1775 del api_key +1776 else: +1777 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1778 +1779 if real_api_key == "tigersAreAwsome": +1780 raise ValueError( +1781 "You actually need to change `cfbd_key` to your CFBD API key.") +1782 elif "Bearer " in real_api_key: +1783 pass +1784 elif "Bearer" in real_api_key: +1785 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1786 else: +1787 real_api_key = "Bearer " + real_api_key +1788 +1789 if season == None: +1790 # This should never happen without user tampering, but if it does, +1791 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +1792 raise SystemError( +1793 "I don't know how, I don't know why, " + +1794 "but you managed to call this function while `season` was `None` (NULL)," + +1795 " and the function got to this point in the code." + +1796 "\nIf you have a GitHub account, " + +1797 "please raise an issue on this python package's GitHub page:\n" + +1798 "https://github.com/armstjc/cfbd-json-py/issues" +1799 ) +1800 elif season > now.year: +1801 raise ValueError(f"`season` cannot be greater than {season}.") +1802 elif season < 1869: +1803 raise ValueError(f"`season` cannot be less than 1869.") +1804 +1805 if season_type != "regular" and season_type != "postseason": +1806 raise ValueError( +1807 "`season_type` must be set to either \"regular\" or " + +1808 "\"postseason\" for this function to work." +1809 ) +1810 +1811 # `week`, `team`, and/or `conference` +1812 # must be not null for this function to work. +1813 +1814 if week == None and team == None and conference_abv == None and game_id == None: +1815 raise ValueError( +1816 "To use `get_cfbd_player_game_stats()`," + +1817 " `week`, `team`, and/or `conference_abv` need to be set to a non-null value." +1818 ) +1819 +1820 filter_by_stat_category = False +1821 +1822 if stat_category == None: +1823 pass +1824 elif stat_category == "passing": +1825 filter_by_stat_category = True +1826 elif stat_category == "rushing": +1827 filter_by_stat_category = True +1828 elif stat_category == "receiving": +1829 filter_by_stat_category = True +1830 elif stat_category == "fumbles": +1831 filter_by_stat_category = True +1832 elif stat_category == "passing": +1833 filter_by_stat_category = True +1834 elif stat_category == "defensive": +1835 filter_by_stat_category = True +1836 elif stat_category == "interceptions": +1837 filter_by_stat_category = True +1838 elif stat_category == "punting": +1839 filter_by_stat_category = True +1840 elif stat_category == "kicking": +1841 filter_by_stat_category = True +1842 elif stat_category == "kickReturns": +1843 filter_by_stat_category = True +1844 elif stat_category == "puntReturns": +1845 filter_by_stat_category = True +1846 else: +1847 raise ValueError( +1848 "Invalid input for `stat_category`." + +1849 "\nValid inputs are:" + +1850 """ +1851 - `passing` +1852 - `rushing` +1853 - `receiving` +1854 - `fumbles` +1855 - `defensive` +1856 - `interceptions` +1857 - `punting` +1858 - `kicking` +1859 - `kickReturns` +1860 - `puntReturns` +1861 """ +1862 ) +1863 +1864 # URL builder +1865 ######################################################################################################################################################################################################## +1866 +1867 # Required by the API +1868 url += f"?year={season}" +1869 +1870 if game_id != None: +1871 url += f"&gameId={game_id}" +1872 +1873 if stat_category != None: +1874 url += f"&category={stat_category}" +1875 +1876 if week != None or team != None or conference_abv != None: +1877 logging.warning( +1878 "When calling `cfbd_json_py.games.get_cfbd_player_game_stats()`, " + +1879 "and setting `game_id` to a non-null value, " + +1880 "only `season`, `stat_category`, and `game_id` are considered " + +1881 "when calling the CFBD API." +1882 ) +1883 else: +1884 if season_type != None: +1885 url += f"&seasonType={season_type}" +1886 +1887 if week != None: +1888 url += f"&week={week}" +1889 +1890 if team != None: +1891 url += f"&team={team}" +1892 +1893 if conference_abv != None: +1894 url += f"&conference={conference_abv}" +1895 +1896 headers = { +1897 'Authorization': f'{real_api_key}', +1898 'accept': 'application/json' +1899 } +1900 +1901 response = requests.get(url, headers=headers) +1902 +1903 +1904 if response.status_code == 200: +1905 pass +1906 elif response.status_code == 401: +1907 raise ConnectionRefusedError( +1908 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1909 ) +1910 else: +1911 raise ConnectionError( +1912 f'Could not connect.\nHTTP Status code {response.status_code}' +1913 ) +1914 +1915 json_data = response.json() +1916 +1917 if return_as_dict == True: +1918 return json_data +1919 +1920 for game in tqdm(json_data): +1921 game_id = game['id'] +1922 +1923 for team in game['teams']: +1924 team_name = team['school'] +1925 team_confrence = team['conference'] +1926 home_away = team['homeAway'] +1927 +1928 for s_category in team['categories']: +1929 if s_category['name'] == "passing": +1930 for stat in s_category['types']: +1931 +1932 if stat['name'] == "C/ATT": # passing_C/ATT +1933 +1934 for i in stat['athletes']: +1935 player_id = int(i['id']) +1936 player_name = i['name'] +1937 player_stat = i['stat'] +1938 +1939 if rebuilt_json.get(player_id) == None: +1940 rebuilt_json[player_id] = {} +1941 +1942 rebuilt_json[player_id]['game_id'] = game_id +1943 rebuilt_json[player_id]['team_name'] = team_name +1944 rebuilt_json[player_id]['team_confrence'] = team_confrence +1945 rebuilt_json[player_id]['player_id'] = player_id +1946 rebuilt_json[player_id]['player_name'] = player_name +1947 rebuilt_json[player_id]['home_away'] = home_away +1948 rebuilt_json[player_id]['passing_C/ATT'] = player_stat +1949 +1950 elif stat['name'] == "YDS": # passing_YDS +1951 +1952 for i in stat['athletes']: +1953 player_id = int(i['id']) +1954 player_name = i['name'] +1955 player_stat = int(i['stat']) +1956 +1957 if rebuilt_json.get(player_id) == None: +1958 rebuilt_json[player_id] = {} +1959 +1960 rebuilt_json[player_id]['game_id'] = game_id +1961 rebuilt_json[player_id]['team_name'] = team_name +1962 rebuilt_json[player_id]['team_confrence'] = team_confrence +1963 rebuilt_json[player_id]['player_id'] = player_id +1964 rebuilt_json[player_id]['player_name'] = player_name +1965 rebuilt_json[player_id]['home_away'] = home_away +1966 rebuilt_json[player_id]['passing_YDS'] = player_stat +1967 +1968 elif stat['name'] == "AVG": # passing_AVG +1969 for i in stat['athletes']: +1970 player_id = int(i['id']) +1971 player_name = i['name'] +1972 player_stat = float(i['stat']) +1973 +1974 if rebuilt_json.get(player_id) == None: +1975 rebuilt_json[player_id] = {} +1976 +1977 rebuilt_json[player_id]['game_id'] = game_id +1978 rebuilt_json[player_id]['team_name'] = team_name +1979 rebuilt_json[player_id]['team_confrence'] = team_confrence +1980 rebuilt_json[player_id]['player_id'] = player_id +1981 rebuilt_json[player_id]['player_name'] = player_name +1982 rebuilt_json[player_id]['home_away'] = home_away +1983 rebuilt_json[player_id]['passing_AVG'] = player_stat +1984 +1985 elif stat['name'] == "TD": # passing_TD +1986 +1987 for i in stat['athletes']: +1988 player_id = int(i['id']) +1989 player_name = i['name'] +1990 player_stat = int(i['stat']) +1991 +1992 if rebuilt_json.get(player_id) == None: +1993 rebuilt_json[player_id] = {} +1994 +1995 rebuilt_json[player_id]['game_id'] = game_id +1996 rebuilt_json[player_id]['team_name'] = team_name +1997 rebuilt_json[player_id]['team_confrence'] = team_confrence +1998 rebuilt_json[player_id]['player_id'] = player_id +1999 rebuilt_json[player_id]['player_name'] = player_name +2000 rebuilt_json[player_id]['home_away'] = home_away +2001 rebuilt_json[player_id]['passing_TD'] = player_stat +2002 +2003 elif stat['name'] == "INT": # passing_INT +2004 +2005 for i in stat['athletes']: +2006 player_id = int(i['id']) +2007 player_name = i['name'] +2008 player_stat = int(i['stat']) +2009 +2010 if rebuilt_json.get(player_id) == None: +2011 rebuilt_json[player_id] = {} +2012 +2013 rebuilt_json[player_id]['game_id'] = game_id +2014 rebuilt_json[player_id]['team_name'] = team_name +2015 rebuilt_json[player_id]['team_confrence'] = team_confrence +2016 rebuilt_json[player_id]['player_id'] = player_id +2017 rebuilt_json[player_id]['player_name'] = player_name +2018 rebuilt_json[player_id]['home_away'] = home_away +2019 rebuilt_json[player_id]['passing_INT'] = player_stat +2020 +2021 elif stat['name'] == "QBR": # passing_QBR +2022 for i in stat['athletes']: +2023 player_id = int(i['id']) +2024 player_name = i['name'] +2025 try: +2026 player_stat = float(i['stat']) +2027 except: +2028 player_stat = None +2029 +2030 if rebuilt_json.get(player_id) == None: +2031 rebuilt_json[player_id] = {} +2032 +2033 rebuilt_json[player_id]['game_id'] = game_id +2034 rebuilt_json[player_id]['team_name'] = team_name +2035 rebuilt_json[player_id]['team_confrence'] = team_confrence +2036 rebuilt_json[player_id]['player_id'] = player_id +2037 rebuilt_json[player_id]['player_name'] = player_name +2038 rebuilt_json[player_id]['home_away'] = home_away +2039 rebuilt_json[player_id]['passing_QBR'] = player_stat +2040 +2041 else: +2042 raise IndexError( +2043 f"Unhandled stat: \t{stat['name']}") +2044 # passing_df = pd.DataFrame(s_category['types']) +2045 elif s_category['name'] == "rushing": +2046 for stat in s_category['types']: +2047 if stat['name'] == "CAR": # rushing_CAR +2048 for i in stat['athletes']: +2049 player_id = int(i['id']) +2050 player_name = i['name'] +2051 player_stat = int(i['stat']) +2052 +2053 if rebuilt_json.get(player_id) == None: +2054 rebuilt_json[player_id] = {} +2055 +2056 rebuilt_json[player_id]['game_id'] = game_id +2057 rebuilt_json[player_id]['team_name'] = team_name +2058 rebuilt_json[player_id]['team_confrence'] = team_confrence +2059 rebuilt_json[player_id]['player_id'] = player_id +2060 rebuilt_json[player_id]['player_name'] = player_name +2061 rebuilt_json[player_id]['home_away'] = home_away +2062 rebuilt_json[player_id]['rushing_CAR'] = player_stat +2063 +2064 elif stat['name'] == "YDS": # rushing_YDS +2065 for i in stat['athletes']: +2066 player_id = int(i['id']) +2067 player_name = i['name'] +2068 player_stat = int(i['stat']) +2069 +2070 if rebuilt_json.get(player_id) == None: +2071 rebuilt_json[player_id] = {} +2072 +2073 rebuilt_json[player_id]['game_id'] = game_id +2074 rebuilt_json[player_id]['team_name'] = team_name +2075 rebuilt_json[player_id]['team_confrence'] = team_confrence +2076 rebuilt_json[player_id]['player_id'] = player_id +2077 rebuilt_json[player_id]['player_name'] = player_name +2078 rebuilt_json[player_id]['home_away'] = home_away +2079 rebuilt_json[player_id]['rushing_YDS'] = player_stat +2080 +2081 elif stat['name'] == "AVG": # rushing_AVG +2082 for i in stat['athletes']: +2083 player_id = int(i['id']) +2084 player_name = i['name'] +2085 player_stat = float(i['stat']) +2086 +2087 if rebuilt_json.get(player_id) == None: +2088 rebuilt_json[player_id] = {} +2089 +2090 rebuilt_json[player_id]['game_id'] = game_id +2091 rebuilt_json[player_id]['team_name'] = team_name +2092 rebuilt_json[player_id]['team_confrence'] = team_confrence +2093 rebuilt_json[player_id]['player_id'] = player_id +2094 rebuilt_json[player_id]['player_name'] = player_name +2095 rebuilt_json[player_id]['home_away'] = home_away +2096 rebuilt_json[player_id]['rushing_AVG'] = player_stat +2097 +2098 elif stat['name'] == "TD": # rushing_TD +2099 for i in stat['athletes']: +2100 player_id = int(i['id']) +2101 player_name = i['name'] +2102 player_stat = int(i['stat']) +2103 +2104 if rebuilt_json.get(player_id) == None: +2105 rebuilt_json[player_id] = {} +2106 +2107 rebuilt_json[player_id]['game_id'] = game_id +2108 rebuilt_json[player_id]['team_name'] = team_name +2109 rebuilt_json[player_id]['team_confrence'] = team_confrence +2110 rebuilt_json[player_id]['player_id'] = player_id +2111 rebuilt_json[player_id]['player_name'] = player_name +2112 rebuilt_json[player_id]['home_away'] = home_away +2113 rebuilt_json[player_id]['rushing_TD'] = player_stat +2114 +2115 elif stat['name'] == "LONG": # rushing_LONG +2116 for i in stat['athletes']: +2117 player_id = int(i['id']) +2118 player_name = i['name'] +2119 player_stat = int(i['stat']) +2120 +2121 if rebuilt_json.get(player_id) == None: +2122 rebuilt_json[player_id] = {} +2123 +2124 rebuilt_json[player_id]['game_id'] = game_id +2125 rebuilt_json[player_id]['team_name'] = team_name +2126 rebuilt_json[player_id]['team_confrence'] = team_confrence +2127 rebuilt_json[player_id]['player_id'] = player_id +2128 rebuilt_json[player_id]['player_name'] = player_name +2129 rebuilt_json[player_id]['home_away'] = home_away +2130 rebuilt_json[player_id]['rushing_LONG'] = player_stat +2131 +2132 else: +2133 raise IndexError( +2134 f"Unhandled stat: \t{stat['name']}") +2135 +2136 elif s_category['name'] == "receiving": +2137 for stat in s_category['types']: +2138 if stat['name'] == "REC": # receiving_REC +2139 for i in stat['athletes']: +2140 player_id = int(i['id']) +2141 player_name = i['name'] +2142 player_stat = int(i['stat']) +2143 +2144 if rebuilt_json.get(player_id) == None: +2145 rebuilt_json[player_id] = {} +2146 +2147 rebuilt_json[player_id]['game_id'] = game_id +2148 rebuilt_json[player_id]['team_name'] = team_name +2149 rebuilt_json[player_id]['team_confrence'] = team_confrence +2150 rebuilt_json[player_id]['player_id'] = player_id +2151 rebuilt_json[player_id]['player_name'] = player_name +2152 rebuilt_json[player_id]['home_away'] = home_away +2153 rebuilt_json[player_id]['receiving_REC'] = player_stat +2154 +2155 elif stat['name'] == "YDS": # receiving_YDS +2156 for i in stat['athletes']: +2157 player_id = int(i['id']) +2158 player_name = i['name'] +2159 player_stat = int(i['stat']) +2160 +2161 if rebuilt_json.get(player_id) == None: +2162 rebuilt_json[player_id] = {} +2163 +2164 rebuilt_json[player_id]['game_id'] = game_id +2165 rebuilt_json[player_id]['team_name'] = team_name +2166 rebuilt_json[player_id]['team_confrence'] = team_confrence +2167 rebuilt_json[player_id]['player_id'] = player_id +2168 rebuilt_json[player_id]['player_name'] = player_name +2169 rebuilt_json[player_id]['home_away'] = home_away +2170 rebuilt_json[player_id]['receiving_YDS'] = player_stat +2171 +2172 elif stat['name'] == "AVG": # receiving_AVG +2173 for i in stat['athletes']: +2174 player_id = int(i['id']) +2175 player_name = i['name'] +2176 player_stat = float(i['stat']) +2177 +2178 if rebuilt_json.get(player_id) == None: +2179 rebuilt_json[player_id] = {} +2180 +2181 rebuilt_json[player_id]['game_id'] = game_id +2182 rebuilt_json[player_id]['team_name'] = team_name +2183 rebuilt_json[player_id]['team_confrence'] = team_confrence +2184 rebuilt_json[player_id]['player_id'] = player_id +2185 rebuilt_json[player_id]['player_name'] = player_name +2186 rebuilt_json[player_id]['home_away'] = home_away +2187 rebuilt_json[player_id]['receiving_AVG'] = player_stat +2188 +2189 elif stat['name'] == "TD": # receiving_TD +2190 for i in stat['athletes']: +2191 player_id = int(i['id']) +2192 player_name = i['name'] +2193 player_stat = int(i['stat']) +2194 +2195 if rebuilt_json.get(player_id) == None: +2196 rebuilt_json[player_id] = {} +2197 +2198 rebuilt_json[player_id]['game_id'] = game_id +2199 rebuilt_json[player_id]['team_name'] = team_name +2200 rebuilt_json[player_id]['team_confrence'] = team_confrence +2201 rebuilt_json[player_id]['player_id'] = player_id +2202 rebuilt_json[player_id]['player_name'] = player_name +2203 rebuilt_json[player_id]['home_away'] = home_away +2204 rebuilt_json[player_id]['receiving_TD'] = player_stat +2205 +2206 elif stat['name'] == "LONG": # receiving_LONG +2207 for i in stat['athletes']: +2208 player_id = int(i['id']) +2209 player_name = i['name'] +2210 player_stat = int(i['stat']) +2211 +2212 if rebuilt_json.get(player_id) == None: +2213 rebuilt_json[player_id] = {} +2214 +2215 rebuilt_json[player_id]['game_id'] = game_id +2216 rebuilt_json[player_id]['team_name'] = team_name +2217 rebuilt_json[player_id]['team_confrence'] = team_confrence +2218 rebuilt_json[player_id]['player_id'] = player_id +2219 rebuilt_json[player_id]['player_name'] = player_name +2220 rebuilt_json[player_id]['home_away'] = home_away +2221 rebuilt_json[player_id]['receiving_LONG'] = player_stat +2222 +2223 else: +2224 raise IndexError( +2225 f"Unhandled stat: \t{stat['name']}") +2226 +2227 elif s_category['name'] == "fumbles": +2228 for stat in s_category['types']: +2229 if stat['name'] == "FUM": # fumbles_FUM +2230 for i in stat['athletes']: +2231 player_id = int(i['id']) +2232 player_name = i['name'] +2233 player_stat = int(i['stat']) +2234 +2235 if rebuilt_json.get(player_id) == None: +2236 rebuilt_json[player_id] = {} +2237 +2238 rebuilt_json[player_id]['game_id'] = game_id +2239 rebuilt_json[player_id]['team_name'] = team_name +2240 rebuilt_json[player_id]['team_confrence'] = team_confrence +2241 rebuilt_json[player_id]['player_id'] = player_id +2242 rebuilt_json[player_id]['player_name'] = player_name +2243 rebuilt_json[player_id]['home_away'] = home_away +2244 rebuilt_json[player_id]['fumbles_FUM'] = player_stat +2245 +2246 elif stat['name'] == "LOST": # fumbles_LOST +2247 for i in stat['athletes']: +2248 player_id = int(i['id']) +2249 player_name = i['name'] +2250 player_stat = int(i['stat']) +2251 +2252 if rebuilt_json.get(player_id) == None: +2253 rebuilt_json[player_id] = {} +2254 +2255 rebuilt_json[player_id]['game_id'] = game_id +2256 rebuilt_json[player_id]['team_name'] = team_name +2257 rebuilt_json[player_id]['team_confrence'] = team_confrence +2258 rebuilt_json[player_id]['player_id'] = player_id +2259 rebuilt_json[player_id]['player_name'] = player_name +2260 rebuilt_json[player_id]['home_away'] = home_away +2261 rebuilt_json[player_id]['fumbles_LOST'] = player_stat +2262 +2263 elif stat['name'] == "REC": # fumbles_REC +2264 for i in stat['athletes']: +2265 player_id = int(i['id']) +2266 player_name = i['name'] +2267 player_stat = int(i['stat']) +2268 +2269 if rebuilt_json.get(player_id) == None: +2270 rebuilt_json[player_id] = {} +2271 +2272 rebuilt_json[player_id]['game_id'] = game_id +2273 rebuilt_json[player_id]['team_name'] = team_name +2274 rebuilt_json[player_id]['team_confrence'] = team_confrence +2275 rebuilt_json[player_id]['player_id'] = player_id +2276 rebuilt_json[player_id]['player_name'] = player_name +2277 rebuilt_json[player_id]['home_away'] = home_away +2278 rebuilt_json[player_id]['fumbles_REC'] = player_stat +2279 +2280 else: +2281 raise IndexError( +2282 f"Unhandled stat: \t{stat['name']}") +2283 +2284 elif s_category['name'] == "defensive": +2285 for stat in s_category['types']: +2286 if stat['name'] == "TOT": # defensive_TOT +2287 for i in stat['athletes']: +2288 player_id = int(i['id']) +2289 player_name = i['name'] +2290 player_stat = int(i['stat']) +2291 +2292 if rebuilt_json.get(player_id) == None: +2293 rebuilt_json[player_id] = {} +2294 +2295 rebuilt_json[player_id]['game_id'] = game_id +2296 rebuilt_json[player_id]['team_name'] = team_name +2297 rebuilt_json[player_id]['team_confrence'] = team_confrence +2298 rebuilt_json[player_id]['player_id'] = player_id +2299 rebuilt_json[player_id]['player_name'] = player_name +2300 rebuilt_json[player_id]['home_away'] = home_away +2301 rebuilt_json[player_id]['defensive_TOT'] = player_stat +2302 +2303 elif stat['name'] == "SOLO": # defensive_SOLO +2304 for i in stat['athletes']: +2305 player_id = int(i['id']) +2306 player_name = i['name'] +2307 player_stat = int(i['stat']) +2308 +2309 if rebuilt_json.get(player_id) == None: +2310 rebuilt_json[player_id] = {} +2311 +2312 rebuilt_json[player_id]['game_id'] = game_id +2313 rebuilt_json[player_id]['team_name'] = team_name +2314 rebuilt_json[player_id]['team_confrence'] = team_confrence +2315 rebuilt_json[player_id]['player_id'] = player_id +2316 rebuilt_json[player_id]['player_name'] = player_name +2317 rebuilt_json[player_id]['home_away'] = home_away +2318 rebuilt_json[player_id]['defensive_SOLO'] = player_stat +2319 +2320 elif stat['name'] == "TFL": # defensive_TFL +2321 for i in stat['athletes']: +2322 player_id = int(i['id']) +2323 player_name = i['name'] +2324 player_stat = float(i['stat']) +2325 +2326 if rebuilt_json.get(player_id) == None: +2327 rebuilt_json[player_id] = {} +2328 +2329 rebuilt_json[player_id]['game_id'] = game_id +2330 rebuilt_json[player_id]['team_name'] = team_name +2331 rebuilt_json[player_id]['team_confrence'] = team_confrence +2332 rebuilt_json[player_id]['player_id'] = player_id +2333 rebuilt_json[player_id]['player_name'] = player_name +2334 rebuilt_json[player_id]['home_away'] = home_away +2335 rebuilt_json[player_id]['defensive_TFL'] = player_stat +2336 +2337 elif stat['name'] == "QB HUR": # defensive_QB HUR +2338 for i in stat['athletes']: +2339 player_id = int(i['id']) +2340 player_name = i['name'] +2341 player_stat = int(i['stat']) +2342 +2343 if rebuilt_json.get(player_id) == None: +2344 rebuilt_json[player_id] = {} +2345 +2346 rebuilt_json[player_id]['game_id'] = game_id +2347 rebuilt_json[player_id]['team_name'] = team_name +2348 rebuilt_json[player_id]['team_confrence'] = team_confrence +2349 rebuilt_json[player_id]['player_id'] = player_id +2350 rebuilt_json[player_id]['player_name'] = player_name +2351 rebuilt_json[player_id]['home_away'] = home_away +2352 rebuilt_json[player_id]['defensive_QB HUR'] = player_stat +2353 +2354 elif stat['name'] == "SACKS": # defensive_SACKS +2355 for i in stat['athletes']: +2356 player_id = int(i['id']) +2357 player_name = i['name'] +2358 player_stat = float(i['stat']) +2359 +2360 if rebuilt_json.get(player_id) == None: +2361 rebuilt_json[player_id] = {} +2362 +2363 rebuilt_json[player_id]['game_id'] = game_id +2364 rebuilt_json[player_id]['team_name'] = team_name +2365 rebuilt_json[player_id]['team_confrence'] = team_confrence +2366 rebuilt_json[player_id]['player_id'] = player_id +2367 rebuilt_json[player_id]['player_name'] = player_name +2368 rebuilt_json[player_id]['home_away'] = home_away +2369 rebuilt_json[player_id]['defensive_SACKS'] = player_stat +2370 +2371 elif stat['name'] == "PD": # defensive_PD +2372 for i in stat['athletes']: +2373 player_id = int(i['id']) +2374 player_name = i['name'] +2375 player_stat = int(i['stat']) +2376 +2377 if rebuilt_json.get(player_id) == None: +2378 rebuilt_json[player_id] = {} +2379 +2380 rebuilt_json[player_id]['game_id'] = game_id +2381 rebuilt_json[player_id]['team_name'] = team_name +2382 rebuilt_json[player_id]['team_confrence'] = team_confrence +2383 rebuilt_json[player_id]['player_id'] = player_id +2384 rebuilt_json[player_id]['player_name'] = player_name +2385 rebuilt_json[player_id]['home_away'] = home_away +2386 rebuilt_json[player_id]['defensive_PD'] = player_stat +2387 +2388 elif stat['name'] == "TD": # defensive_TD +2389 for i in stat['athletes']: +2390 player_id = int(i['id']) +2391 player_name = i['name'] +2392 player_stat = int(i['stat']) +2393 +2394 if rebuilt_json.get(player_id) == None: +2395 rebuilt_json[player_id] = {} +2396 +2397 rebuilt_json[player_id]['game_id'] = game_id +2398 rebuilt_json[player_id]['team_name'] = team_name +2399 rebuilt_json[player_id]['team_confrence'] = team_confrence +2400 rebuilt_json[player_id]['player_id'] = player_id +2401 rebuilt_json[player_id]['player_name'] = player_name +2402 rebuilt_json[player_id]['home_away'] = home_away +2403 rebuilt_json[player_id]['defensive_TD'] = player_stat +2404 +2405 else: +2406 raise IndexError( +2407 f"Unhandled stat: \t{stat['name']}") +2408 +2409 elif s_category['name'] == "interceptions": +2410 for stat in s_category['types']: +2411 if stat['name'] == "INT": # interceptions_INT +2412 for i in stat['athletes']: +2413 player_id = int(i['id']) +2414 player_name = i['name'] +2415 player_stat = int(i['stat']) +2416 +2417 if rebuilt_json.get(player_id) == None: +2418 rebuilt_json[player_id] = {} +2419 +2420 rebuilt_json[player_id]['game_id'] = game_id +2421 rebuilt_json[player_id]['team_name'] = team_name +2422 rebuilt_json[player_id]['team_confrence'] = team_confrence +2423 rebuilt_json[player_id]['player_id'] = player_id +2424 rebuilt_json[player_id]['player_name'] = player_name +2425 rebuilt_json[player_id]['home_away'] = home_away +2426 rebuilt_json[player_id]['interceptions_INT'] = player_stat +2427 +2428 elif stat['name'] == "YDS": # interceptions_YDS +2429 for i in stat['athletes']: +2430 player_id = int(i['id']) +2431 player_name = i['name'] +2432 player_stat = int(i['stat']) +2433 +2434 if rebuilt_json.get(player_id) == None: +2435 rebuilt_json[player_id] = {} +2436 +2437 rebuilt_json[player_id]['game_id'] = game_id +2438 rebuilt_json[player_id]['team_name'] = team_name +2439 rebuilt_json[player_id]['team_confrence'] = team_confrence +2440 rebuilt_json[player_id]['player_id'] = player_id +2441 rebuilt_json[player_id]['player_name'] = player_name +2442 rebuilt_json[player_id]['home_away'] = home_away +2443 rebuilt_json[player_id]['interceptions_YDS'] = player_stat +2444 +2445 elif stat['name'] == "TD": # interceptions_TD +2446 for i in stat['athletes']: +2447 player_id = int(i['id']) +2448 player_name = i['name'] +2449 player_stat = int(i['stat']) +2450 +2451 if rebuilt_json.get(player_id) == None: +2452 rebuilt_json[player_id] = {} +2453 +2454 rebuilt_json[player_id]['game_id'] = game_id +2455 rebuilt_json[player_id]['team_name'] = team_name +2456 rebuilt_json[player_id]['team_confrence'] = team_confrence +2457 rebuilt_json[player_id]['player_id'] = player_id +2458 rebuilt_json[player_id]['player_name'] = player_name +2459 rebuilt_json[player_id]['home_away'] = home_away +2460 rebuilt_json[player_id]['interceptions_TD'] = player_stat +2461 +2462 else: +2463 raise IndexError( +2464 f"Unhandled stat: \t{stat['name']}") +2465 +2466 elif s_category['name'] == "punting": +2467 for stat in s_category['types']: +2468 if stat['name'] == "NO": # punting_NO +2469 for i in stat['athletes']: +2470 player_id = int(i['id']) +2471 player_name = i['name'] +2472 player_stat = int(i['stat']) +2473 +2474 if rebuilt_json.get(player_id) == None: +2475 rebuilt_json[player_id] = {} +2476 +2477 rebuilt_json[player_id]['game_id'] = game_id +2478 rebuilt_json[player_id]['team_name'] = team_name +2479 rebuilt_json[player_id]['team_confrence'] = team_confrence +2480 rebuilt_json[player_id]['player_id'] = player_id +2481 rebuilt_json[player_id]['player_name'] = player_name +2482 rebuilt_json[player_id]['home_away'] = home_away +2483 rebuilt_json[player_id]['punting_NO'] = player_stat +2484 +2485 elif stat['name'] == "YDS": # punting_YDS +2486 for i in stat['athletes']: +2487 player_id = int(i['id']) +2488 player_name = i['name'] +2489 player_stat = int(i['stat']) +2490 +2491 if rebuilt_json.get(player_id) == None: +2492 rebuilt_json[player_id] = {} +2493 +2494 rebuilt_json[player_id]['game_id'] = game_id +2495 rebuilt_json[player_id]['team_name'] = team_name +2496 rebuilt_json[player_id]['team_confrence'] = team_confrence +2497 rebuilt_json[player_id]['player_id'] = player_id +2498 rebuilt_json[player_id]['player_name'] = player_name +2499 rebuilt_json[player_id]['home_away'] = home_away +2500 rebuilt_json[player_id]['punting_YDS'] = player_stat +2501 +2502 elif stat['name'] == "AVG": # punting_AVG +2503 for i in stat['athletes']: +2504 player_id = int(i['id']) +2505 player_name = i['name'] +2506 player_stat = float(i['stat']) +2507 +2508 if rebuilt_json.get(player_id) == None: +2509 rebuilt_json[player_id] = {} +2510 +2511 rebuilt_json[player_id]['game_id'] = game_id +2512 rebuilt_json[player_id]['team_name'] = team_name +2513 rebuilt_json[player_id]['team_confrence'] = team_confrence +2514 rebuilt_json[player_id]['player_id'] = player_id +2515 rebuilt_json[player_id]['player_name'] = player_name +2516 rebuilt_json[player_id]['home_away'] = home_away +2517 rebuilt_json[player_id]['punting_AVG'] = player_stat +2518 +2519 elif stat['name'] == "TB": # punting_TB +2520 for i in stat['athletes']: +2521 player_id = int(i['id']) +2522 player_name = i['name'] +2523 player_stat = int(i['stat']) +2524 +2525 if rebuilt_json.get(player_id) == None: +2526 rebuilt_json[player_id] = {} +2527 +2528 rebuilt_json[player_id]['game_id'] = game_id +2529 rebuilt_json[player_id]['team_name'] = team_name +2530 rebuilt_json[player_id]['team_confrence'] = team_confrence +2531 rebuilt_json[player_id]['player_id'] = player_id +2532 rebuilt_json[player_id]['player_name'] = player_name +2533 rebuilt_json[player_id]['home_away'] = home_away +2534 rebuilt_json[player_id]['punting_TB'] = player_stat +2535 +2536 elif stat['name'] == "In 20": # punting_In 20 +2537 for i in stat['athletes']: +2538 player_id = int(i['id']) +2539 player_name = i['name'] +2540 player_stat = int(i['stat']) +2541 +2542 if rebuilt_json.get(player_id) == None: +2543 rebuilt_json[player_id] = {} +2544 +2545 rebuilt_json[player_id]['game_id'] = game_id +2546 rebuilt_json[player_id]['team_name'] = team_name +2547 rebuilt_json[player_id]['team_confrence'] = team_confrence +2548 rebuilt_json[player_id]['player_id'] = player_id +2549 rebuilt_json[player_id]['player_name'] = player_name +2550 rebuilt_json[player_id]['home_away'] = home_away +2551 rebuilt_json[player_id]['punting_In 20'] = player_stat +2552 +2553 elif stat['name'] == "LONG": # punting_LONG +2554 for i in stat['athletes']: +2555 player_id = int(i['id']) +2556 player_name = i['name'] +2557 player_stat = int(i['stat']) +2558 +2559 if rebuilt_json.get(player_id) == None: +2560 rebuilt_json[player_id] = {} +2561 +2562 rebuilt_json[player_id]['game_id'] = game_id +2563 rebuilt_json[player_id]['team_name'] = team_name +2564 rebuilt_json[player_id]['team_confrence'] = team_confrence +2565 rebuilt_json[player_id]['player_id'] = player_id +2566 rebuilt_json[player_id]['player_name'] = player_name +2567 rebuilt_json[player_id]['home_away'] = home_away +2568 rebuilt_json[player_id]['punting_LONG'] = player_stat +2569 +2570 else: +2571 raise IndexError( +2572 f"Unhandled stat: \t{stat['name']}") +2573 +2574 elif s_category['name'] == "kicking": +2575 for stat in s_category['types']: +2576 if stat['name'] == "FG": # kicking_FG +2577 for i in stat['athletes']: +2578 player_id = int(i['id']) +2579 player_name = i['name'] +2580 player_stat = i['stat'] +2581 +2582 if rebuilt_json.get(player_id) == None: +2583 rebuilt_json[player_id] = {} +2584 +2585 rebuilt_json[player_id]['game_id'] = game_id +2586 rebuilt_json[player_id]['team_name'] = team_name +2587 rebuilt_json[player_id]['team_confrence'] = team_confrence +2588 rebuilt_json[player_id]['player_id'] = player_id +2589 rebuilt_json[player_id]['player_name'] = player_name +2590 rebuilt_json[player_id]['home_away'] = home_away +2591 rebuilt_json[player_id]['kicking_FG'] = player_stat +2592 +2593 elif stat['name'] == "TOT": # kicking_FG, special case +2594 for i in stat['athletes']: +2595 player_id = int(i['id']) +2596 player_name = i['name'] +2597 player_stat = i['stat'] +2598 +2599 if rebuilt_json.get(player_id) == None: +2600 rebuilt_json[player_id] = {} +2601 +2602 rebuilt_json[player_id]['game_id'] = game_id +2603 rebuilt_json[player_id]['team_name'] = team_name +2604 rebuilt_json[player_id]['team_confrence'] = team_confrence +2605 rebuilt_json[player_id]['player_id'] = player_id +2606 rebuilt_json[player_id]['player_name'] = player_name +2607 rebuilt_json[player_id]['home_away'] = home_away +2608 rebuilt_json[player_id]['kicking_FG'] = player_stat +2609 +2610 elif stat['name'] == "PCT": # kicking_PCT +2611 for i in stat['athletes']: +2612 player_id = int(i['id']) +2613 player_name = i['name'] +2614 player_stat = float(i['stat']) +2615 +2616 if rebuilt_json.get(player_id) == None: +2617 rebuilt_json[player_id] = {} +2618 +2619 rebuilt_json[player_id]['game_id'] = game_id +2620 rebuilt_json[player_id]['team_name'] = team_name +2621 rebuilt_json[player_id]['team_confrence'] = team_confrence +2622 rebuilt_json[player_id]['player_id'] = player_id +2623 rebuilt_json[player_id]['player_name'] = player_name +2624 rebuilt_json[player_id]['home_away'] = home_away +2625 rebuilt_json[player_id]['kicking_PCT'] = player_stat +2626 +2627 elif stat['name'] == "LONG": # kicking_LONG +2628 for i in stat['athletes']: +2629 player_id = int(i['id']) +2630 player_name = i['name'] +2631 player_stat = int(i['stat']) +2632 +2633 if rebuilt_json.get(player_id) == None: +2634 rebuilt_json[player_id] = {} +2635 +2636 rebuilt_json[player_id]['game_id'] = game_id +2637 rebuilt_json[player_id]['team_name'] = team_name +2638 rebuilt_json[player_id]['team_confrence'] = team_confrence +2639 rebuilt_json[player_id]['player_id'] = player_id +2640 rebuilt_json[player_id]['player_name'] = player_name +2641 rebuilt_json[player_id]['home_away'] = home_away +2642 rebuilt_json[player_id]['kicking_LONG'] = player_stat +2643 +2644 elif stat['name'] == "XP": # kicking_XP +2645 for i in stat['athletes']: +2646 player_id = int(i['id']) +2647 player_name = i['name'] +2648 player_stat = i['stat'] +2649 +2650 if rebuilt_json.get(player_id) == None: +2651 rebuilt_json[player_id] = {} +2652 +2653 rebuilt_json[player_id]['game_id'] = game_id +2654 rebuilt_json[player_id]['team_name'] = team_name +2655 rebuilt_json[player_id]['team_confrence'] = team_confrence +2656 rebuilt_json[player_id]['player_id'] = player_id +2657 rebuilt_json[player_id]['player_name'] = player_name +2658 rebuilt_json[player_id]['home_away'] = home_away +2659 rebuilt_json[player_id]['kicking_XP'] = player_stat +2660 +2661 elif stat['name'] == "PTS": # kicking_PTS +2662 for i in stat['athletes']: +2663 player_id = int(i['id']) +2664 player_name = i['name'] +2665 player_stat = int(i['stat']) +2666 +2667 if rebuilt_json.get(player_id) == None: +2668 rebuilt_json[player_id] = {} +2669 +2670 rebuilt_json[player_id]['game_id'] = game_id +2671 rebuilt_json[player_id]['team_name'] = team_name +2672 rebuilt_json[player_id]['team_confrence'] = team_confrence +2673 rebuilt_json[player_id]['player_id'] = player_id +2674 rebuilt_json[player_id]['player_name'] = player_name +2675 rebuilt_json[player_id]['home_away'] = home_away +2676 rebuilt_json[player_id]['kicking_PTS'] = player_stat +2677 +2678 else: +2679 raise IndexError( +2680 f"Unhandled stat: \t{stat['name']}") +2681 +2682 elif s_category['name'] == "kickReturns": +2683 for stat in s_category['types']: +2684 if stat['name'] == "NO": # kickReturns_NO +2685 for i in stat['athletes']: +2686 player_id = int(i['id']) +2687 player_name = i['name'] +2688 player_stat = int(i['stat']) +2689 +2690 if rebuilt_json.get(player_id) == None: +2691 rebuilt_json[player_id] = {} +2692 +2693 rebuilt_json[player_id]['game_id'] = game_id +2694 rebuilt_json[player_id]['team_name'] = team_name +2695 rebuilt_json[player_id]['team_confrence'] = team_confrence +2696 rebuilt_json[player_id]['player_id'] = player_id +2697 rebuilt_json[player_id]['player_name'] = player_name +2698 rebuilt_json[player_id]['home_away'] = home_away +2699 rebuilt_json[player_id]['kickReturns_NO'] = player_stat +2700 +2701 elif stat['name'] == "YDS": # kickReturns_YDS +2702 for i in stat['athletes']: +2703 player_id = int(i['id']) +2704 player_name = i['name'] +2705 player_stat = int(i['stat']) +2706 +2707 if rebuilt_json.get(player_id) == None: +2708 rebuilt_json[player_id] = {} +2709 +2710 rebuilt_json[player_id]['game_id'] = game_id +2711 rebuilt_json[player_id]['team_name'] = team_name +2712 rebuilt_json[player_id]['team_confrence'] = team_confrence +2713 rebuilt_json[player_id]['player_id'] = player_id +2714 rebuilt_json[player_id]['player_name'] = player_name +2715 rebuilt_json[player_id]['home_away'] = home_away +2716 rebuilt_json[player_id]['kickReturns_YDS'] = player_stat +2717 +2718 elif stat['name'] == "AVG": # kickReturns_AVG +2719 for i in stat['athletes']: +2720 player_id = int(i['id']) +2721 player_name = i['name'] +2722 player_stat = float(i['stat']) +2723 +2724 if rebuilt_json.get(player_id) == None: +2725 rebuilt_json[player_id] = {} +2726 +2727 rebuilt_json[player_id]['game_id'] = game_id +2728 rebuilt_json[player_id]['team_name'] = team_name +2729 rebuilt_json[player_id]['team_confrence'] = team_confrence +2730 rebuilt_json[player_id]['player_id'] = player_id +2731 rebuilt_json[player_id]['player_name'] = player_name +2732 rebuilt_json[player_id]['home_away'] = home_away +2733 rebuilt_json[player_id]['kickReturns_AVG'] = player_stat +2734 +2735 elif stat['name'] == "TD": # kickReturns_TD +2736 for i in stat['athletes']: +2737 player_id = int(i['id']) +2738 player_name = i['name'] +2739 player_stat = int(i['stat']) +2740 +2741 if rebuilt_json.get(player_id) == None: +2742 rebuilt_json[player_id] = {} +2743 +2744 rebuilt_json[player_id]['game_id'] = game_id +2745 rebuilt_json[player_id]['team_name'] = team_name +2746 rebuilt_json[player_id]['team_confrence'] = team_confrence +2747 rebuilt_json[player_id]['player_id'] = player_id +2748 rebuilt_json[player_id]['player_name'] = player_name +2749 rebuilt_json[player_id]['home_away'] = home_away +2750 rebuilt_json[player_id]['kickReturns_TD'] = player_stat +2751 +2752 elif stat['name'] == "LONG": # kickReturns_LONG +2753 for i in stat['athletes']: +2754 player_id = int(i['id']) +2755 player_name = i['name'] +2756 player_stat = int(i['stat']) +2757 +2758 if rebuilt_json.get(player_id) == None: +2759 rebuilt_json[player_id] = {} +2760 +2761 rebuilt_json[player_id]['game_id'] = game_id +2762 rebuilt_json[player_id]['team_name'] = team_name +2763 rebuilt_json[player_id]['team_confrence'] = team_confrence +2764 rebuilt_json[player_id]['player_id'] = player_id +2765 rebuilt_json[player_id]['player_name'] = player_name +2766 rebuilt_json[player_id]['home_away'] = home_away +2767 rebuilt_json[player_id]['kickReturns_LONG'] = player_stat +2768 +2769 else: +2770 raise IndexError( +2771 f"Unhandled stat: \t{stat['name']}") +2772 +2773 elif s_category['name'] == "puntReturns": +2774 for stat in s_category['types']: +2775 if stat['name'] == "NO": # puntReturns_NO +2776 for i in stat['athletes']: +2777 player_id = int(i['id']) +2778 player_name = i['name'] +2779 player_stat = int(i['stat']) +2780 +2781 if rebuilt_json.get(player_id) == None: +2782 rebuilt_json[player_id] = {} +2783 +2784 rebuilt_json[player_id]['game_id'] = game_id +2785 rebuilt_json[player_id]['team_name'] = team_name +2786 rebuilt_json[player_id]['team_confrence'] = team_confrence +2787 rebuilt_json[player_id]['player_id'] = player_id +2788 rebuilt_json[player_id]['player_name'] = player_name +2789 rebuilt_json[player_id]['home_away'] = home_away +2790 rebuilt_json[player_id]['puntReturns_NO'] = player_stat +2791 +2792 elif stat['name'] == "YDS": # puntReturns_YDS +2793 for i in stat['athletes']: +2794 player_id = int(i['id']) +2795 player_name = i['name'] +2796 player_stat = int(i['stat']) +2797 +2798 if rebuilt_json.get(player_id) == None: +2799 rebuilt_json[player_id] = {} +2800 +2801 rebuilt_json[player_id]['game_id'] = game_id +2802 rebuilt_json[player_id]['team_name'] = team_name +2803 rebuilt_json[player_id]['team_confrence'] = team_confrence +2804 rebuilt_json[player_id]['player_id'] = player_id +2805 rebuilt_json[player_id]['player_name'] = player_name +2806 rebuilt_json[player_id]['home_away'] = home_away +2807 rebuilt_json[player_id]['puntReturns_YDS'] = player_stat +2808 +2809 elif stat['name'] == "AVG": # puntReturns_AVG +2810 for i in stat['athletes']: +2811 player_id = int(i['id']) +2812 player_name = i['name'] +2813 player_stat = float(i['stat']) +2814 +2815 if rebuilt_json.get(player_id) == None: +2816 rebuilt_json[player_id] = {} +2817 +2818 rebuilt_json[player_id]['game_id'] = game_id +2819 rebuilt_json[player_id]['team_name'] = team_name +2820 rebuilt_json[player_id]['team_confrence'] = team_confrence +2821 rebuilt_json[player_id]['player_id'] = player_id +2822 rebuilt_json[player_id]['player_name'] = player_name +2823 rebuilt_json[player_id]['home_away'] = home_away +2824 rebuilt_json[player_id]['puntReturns_AVG'] = player_stat +2825 +2826 elif stat['name'] == "TD": # puntReturns_TD +2827 for i in stat['athletes']: +2828 player_id = int(i['id']) +2829 player_name = i['name'] +2830 player_stat = int(i['stat']) +2831 +2832 if rebuilt_json.get(player_id) == None: +2833 rebuilt_json[player_id] = {} +2834 +2835 rebuilt_json[player_id]['game_id'] = game_id +2836 rebuilt_json[player_id]['team_name'] = team_name +2837 rebuilt_json[player_id]['team_confrence'] = team_confrence +2838 rebuilt_json[player_id]['player_id'] = player_id +2839 rebuilt_json[player_id]['player_name'] = player_name +2840 rebuilt_json[player_id]['home_away'] = home_away +2841 rebuilt_json[player_id]['puntReturns_TD'] = player_stat +2842 +2843 elif stat['name'] == "LONG": # puntReturns_LONG +2844 for i in stat['athletes']: +2845 player_id = int(i['id']) +2846 player_name = i['name'] +2847 player_stat = int(i['stat']) +2848 +2849 if rebuilt_json.get(player_id) == None: +2850 rebuilt_json[player_id] = {} +2851 +2852 rebuilt_json[player_id]['game_id'] = game_id +2853 rebuilt_json[player_id]['team_name'] = team_name +2854 rebuilt_json[player_id]['team_confrence'] = team_confrence +2855 rebuilt_json[player_id]['player_id'] = player_id +2856 rebuilt_json[player_id]['player_name'] = player_name +2857 rebuilt_json[player_id]['home_away'] = home_away +2858 rebuilt_json[player_id]['puntReturns_LONG'] = player_stat +2859 +2860 else: +2861 raise IndexError( +2862 f"Unhandled stat: \t{stat['name']}") +2863 +2864 else: +2865 raise IndexError( +2866 f"Unhandled stat category: \t{s_category['name']}" +2867 ) 2868 2869 for key, value in tqdm(rebuilt_json.items()): 2870 # print(key) @@ -7776,7 +7777,7 @@Parameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, @@ -8046,7 +8047,7 @@Returns
3263 3264 `api_key_dir` (str, optional): 3265 Optional argument. -3266 If `api_key` is set to a string non-empty string, this variable is ignored. +3266 If `api_key` is set to am empty string, this variable is ignored. 3267 If `api_key_dir` is null, and `api_key` is null, 3268 this function will try to find a CFBD API key file in this user's home directory. 3269 If `api_key_dir` is set to a string, and `api_key` is null, @@ -8164,7 +8165,7 @@Returns
3381 } 3382 3383 response = requests.get(url, headers=headers) -3384 time.sleep(0.1) +3384 3385 3386 if response.status_code == 200: 3387 pass @@ -8292,7 +8293,7 @@Parameters
api_key_dir
(str, optional): Optional argument. - Ifapi_key
is set to a string non-empty string, this variable is ignored. + Ifapi_key
is set to am empty string, this variable is ignored. Ifapi_key_dir
is null, andapi_key
is null, this function will try to find a CFBD API key file in this user's home directory. Ifapi_key_dir
is set to a string, andapi_key
is null, diff --git a/docs/cfbd_json_py/metrics.html b/docs/cfbd_json_py/metrics.html index 42e2a2e..e9096a0 100644 --- a/docs/cfbd_json_py/metrics.html +++ b/docs/cfbd_json_py/metrics.html @@ -34,16 +34,16 @@API Documentation
get_cfbd_predicted_ppa_from_down_distance- - get_cfbd_team_ppa_data + get_cfbd_team_season_ppa_data
- - get_cfbd_game_ppa_data + get_cfbd_team_game_ppa_data
- - get_cfbd_game_player_ppa_data + get_cfbd_player_game_ppa_data
- - get_cfbd_season_player_ppa_data + get_cfbd_player_season_ppa_data
- get_cfbd_game_win_probability_data @@ -72,137 +72,2461 @@
-
1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/06/2023 07:53 PM EDT - 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) - 4# File Name: metrics.py - 5# Purpose: Houses functions pertaining to various CFB stats within the CFBD API. - 6#################################################################################################### - 7 - 8def get_cfbd_predicted_ppa_from_down_distance( - 9 down: int, - 10 distance: int, - 11 api_key: str = None, - 12 api_key_dir: str = None): - 13 """ - 14 """ - 15 - 16 raise NotImplementedError( - 17 'This function has yet to be implemented by this version.' - 18 ) - 19 - 20 - 21def get_cfbd_team_ppa_data( - 22 api_key: str = None, - 23 api_key_dir: str = None, - 24 season: int = None, - 25 team: str = None, - 26 # `year` and/or `team` must be not null for this function to work. - 27 conference_abv: str = None, - 28 exclude_garbage_time: bool = False, - 29 - 30 return_as_dict: bool = False): - 31 """ - 32 - 33 """ - 34 - 35 raise NotImplementedError( - 36 'This function has yet to be implemented by this version.' - 37 ) - 38 - 39 - 40def get_cfbd_game_ppa_data( - 41 season: int, - 42 api_key: str = None, - 43 api_key_dir: str = None, - 44 week: int = None, - 45 team: str = None, - 46 conference_abv: str = None, - 47 exclude_garbage_time: bool = False, - 48 season_type: str = "regular", # "regular" or "postseason" - 49 - 50 return_as_dict: bool = False): - 51 """ - 52 - 53 """ - 54 - 55 raise NotImplementedError( - 56 'This function has yet to be implemented by this version.' - 57 ) - 58 - 59 - 60def get_cfbd_game_player_ppa_data( - 61 season: int, - 62 api_key: str = None, - 63 api_key_dir: str = None, - 64 week: int = None, - 65 team: str = None, - 66 # A week or team must be specified - 67 position: str = None, - 68 player_id: int = None, - 69 play_threshold: int = None, - 70 exclude_garbage_time: bool = False, - 71 season_type: str = "regular", # "regular" or "postseason" - 72 - 73 return_as_dict: bool = False): - 74 """ - 75 - 76 """ - 77 - 78 raise NotImplementedError( - 79 'This function has yet to be implemented by this version.' - 80 ) - 81 - 82 - 83def get_cfbd_season_player_ppa_data( - 84 season: int, - 85 api_key: str = None, - 86 api_key_dir: str = None, - 87 team: str = None, - 88 conference_abv: str = None, - 89 position: str = None, - 90 player_id: int = None, - 91 play_threshold: int = None, - 92 exclude_garbage_time: bool = False, - 93 - 94 return_as_dict: bool = False): - 95 """ - 96 - 97 """ - 98 raise NotImplementedError( - 99 'This function has yet to be implemented by this version.' -100 ) -101 -102 -103def get_cfbd_game_win_probability_data( -104 game_id: int, -105 api_key: str = None, -106 api_key_dir: str = None, -107 -108 return_as_dict: bool = False): -109 """ -110 -111 """ -112 raise NotImplementedError( -113 'This function has yet to be implemented by this version.' -114 ) -115 -116 -117def get_cfbd_pregame_win_probability_data( -118 season: int, -119 api_key: str = None, -120 api_key_dir: str = None, -121 week: int = None, -122 team: str = None, -123 season_type: str = "regular", # "regular" or "postseason" -124 -125 return_as_dict: bool = False): -126 """ -127 -128 """ -129 raise NotImplementedError( -130 'This function has yet to be implemented by this version.' -131 ) +@@ -212,169 +2536,3059 @@1# Creation Date: 08/30/2023 01:13 EDT + 2# Last Updated Date: 10/23/2023 11:09 PM EDT + 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) + 4# File Name: metrics.py + 5# Purpose: Houses functions pertaining to various CFB stats within the CFBD API. + 6#################################################################################################### + 7 + 8from datetime import datetime + 9import logging + 10import pandas as pd + 11import requests + 12from tqdm import tqdm + 13 + 14from cfbd_json_py.utls import get_cfbd_api_token + 15 + 16 + 17def get_cfbd_predicted_ppa_from_down_distance( + 18 down: int, + 19 distance: int, + 20 api_key: str = None, + 21 api_key_dir: str = None, + 22 return_as_dict: bool = False): + 23 """ + 24 Given a down and distance, + 25 this function will attempt to get the predicted + 26 PPA value for that down and distance, + 27 at every yard line possible for that down and distance. + 28 + 29 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + 30 + 31 For this endpoint, + 32 [`yardLine`] is the number of yards from 1 (offense has the ball on their side, + 33 at their 1 yard line), to 99 + 34 (offense with the ball with a X and goal situation on the opponent's 1 yard line. + 35 + 36 Parameters + 37 ---------- + 38 `down` (int, mandatory): + 39 Mandatory argument. + 40 This is the down (a number between 1 and 4 in normal situations) + 41 for this play you want PPA for. + 42 + 43 `distance` (int, mandatory): + 44 Mandatory argument. + 45 This variable should be set to the number of yards between + 46 the line of scrimage (LOS), and the first down line on the field. + 47 + 48 `api_key` (str, optional): + 49 Semi-optional argument. + 50 If `api_key` is null, this function will attempt to load a CFBD API key + 51 from the python environment, or from a file on this computer. + 52 If `api_key` is not null, this function will automatically assume that the + 53 inputted `api_key` is a valid CFBD API key. + 54 + 55 `api_key_dir` (str, optional): + 56 Optional argument. + 57 If `api_key` is set to am empty string, this variable is ignored. + 58 If `api_key_dir` is null, and `api_key` is null, + 59 this function will try to find a CFBD API key file in this user's home directory. + 60 If `api_key_dir` is set to a string, and `api_key` is null, + 61 this function will assume that `api_key_dir` is a directory, + 62 and will try to find a CFBD API key file in that directory. + 63 + 64 `return_as_dict` (bool, semi-optional): + 65 Semi-optional argument. + 66 If you want this function to return the data as a dictionary (read: JSON object), + 67 instead of a pandas `DataFrame` object, + 68 set `return_as_dict` to `True`. + 69 + 70 Usage + 71 ---------- + 72 ``` + 73 import time + 74 + 75 from cfbd_json_py.metrics import get_cfbd_predicted_ppa_from_down_distance + 76 + 77 + 78 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 79 + 80 if cfbd_key != "tigersAreAwsome": + 81 print("Using the user's API key declared in this script for this example.") + 82 + 83 # Get the predicted PPA for a 1st and 10 play, + 84 # in every possible situation. + 85 print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + 86 json_data = get_cfbd_predicted_ppa_from_down_distance( + 87 down=1, + 88 distance=10, + 89 api_key=cfbd_key + 90 ) + 91 print(json_data) + 92 time.sleep(5) + 93 + 94 + 95 # You can also tell this function to just return the API call as + 96 # a Dictionary (read: JSON) object. + 97 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 98 json_data = get_cfbd_predicted_ppa_from_down_distance( + 99 down=1, + 100 distance=10, + 101 api_key=cfbd_key, + 102 return_as_dict=True + 103 ) + 104 print(json_data) + 105 + 106 else: + 107 # Alternatively, if the CFBD API key exists in this python environment, + 108 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 109 # you could just call these functions directly, without setting the API key + 110 # in the script. + 111 print("Using the user's API key suposedly loaded into this python environment for this example.") + 112 + 113 + 114 # Get the predicted PPA for a 1st and 10 play, + 115 # in every possible situation. + 116 print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + 117 json_data = get_cfbd_predicted_ppa_from_down_distance( + 118 down=1, + 119 distance=10 + 120 ) + 121 print(json_data) + 122 time.sleep(5) + 123 + 124 + 125 # You can also tell this function to just return the API call as + 126 # a Dictionary (read: JSON) object. + 127 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 128 json_data = get_cfbd_predicted_ppa_from_down_distance( + 129 down=1, + 130 distance=10, + 131 return_as_dict=True + 132 ) + 133 print(json_data) + 134 + 135 ``` + 136 Returns + 137 ---------- + 138 A pandas `DataFrame` object with a calculated PPA from a dwon and distance, + 139 or (if `return_as_dict` is set to `True`) + 140 a dictionary object with a calculated PPA from a dwon and distance. + 141 + 142 + 143 """ + 144 + 145 # now = datetime.now() + 146 ppa_df = pd.DataFrame() + 147 row_df = pd.DataFrame() + 148 url = "https://api.collegefootballdata.com/ppa/predicted" + 149 + 150 ######################################################################################################################################################################################################## + 151 + 152 if api_key != None: + 153 real_api_key = api_key + 154 del api_key + 155 else: + 156 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + 157 + 158 if real_api_key == "tigersAreAwsome": + 159 raise ValueError( + 160 "You actually need to change `cfbd_key` to your CFBD API key.") + 161 elif "Bearer " in real_api_key: + 162 pass + 163 elif "Bearer" in real_api_key: + 164 real_api_key = real_api_key.replace('Bearer', 'Bearer ') + 165 else: + 166 real_api_key = "Bearer " + real_api_key + 167 + 168 if down >= 1 and down <= 4: + 169 # This is normal, so pass. + 170 pass + 171 elif down == 5: + 172 # Due to a Missouri-Colorado game in the 90s + 173 # being won by Colorado on a mythical "5th down", + 174 # we cannot reject this down outright, + 175 # but we have to convey to the person calling this + 176 # function that setting `down = 5` + 177 # is not something they should be doing. + 178 logging.warn( + 179 "There is a very limited number of \"5th down\" situations " + + 180 "in American Football history. " + + 181 "Do not expect anything back when calling this function, " + + 182 "and setting`down` to `5`." + 183 ) + 184 else: + 185 raise ValueError( + 186 "Invalid `down` inputted! Valid inputs are:\n" + + 187 "\n\t- `1`" + + 188 "\n\t- `2`" + + 189 "\n\t- `3`" + + 190 "\n\t- `4`" + + 191 f"\nYou entered: \t`{down}`" + 192 + 193 + 194 ) + 195 + 196 if distance == 0: + 197 raise ValueError( + 198 "If you want \"X and inches\" predicted PPA data, " + + 199 "set `down` to `1` when calling this function." + 200 ) + 201 elif distance >= 100 and distance <= 110: + 202 raise ValueError( + 203 "The CFBD API cannot calculate predicted PPA for " + + 204 "U-Sports (Canada) football." + 205 ) + 206 elif distance >= 1 and distance <= 99: + 207 # While numbers beyond 30 are rare, + 208 # there are some situations IRL that caused the distance + 209 # in "down and distance" to exceed 90 + 210 # (most famously a 2017 game between + 211 # Mississippi State and Louisiana Tech). + 212 pass + 213 + 214 # URL builder + 215 ######################################################################################################################################################################################################## + 216 + 217 # Required by API + 218 url += f"?down={down}&distance={distance}" + 219 + 220 headers = { + 221 'Authorization': f'{real_api_key}', + 222 'accept': 'application/json' + 223 } + 224 + 225 response = requests.get(url, headers=headers) + 226 + 227 if response.status_code == 200: + 228 pass + 229 elif response.status_code == 401: + 230 raise ConnectionRefusedError( + 231 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + 232 ) + 233 else: + 234 raise ConnectionError( + 235 f'Could not connect.\nHTTP Status code {response.status_code}' + 236 ) + 237 + 238 json_data = response.json() + 239 + 240 if return_as_dict == True: + 241 return json_data + 242 + 243 for dnd in json_data: + 244 row_df = pd.DataFrame( + 245 { + 246 "down": down, + 247 "distance": distance, + 248 + 249 }, + 250 index=[0] + 251 ) + 252 row_df['predicted_points'] = dnd['predictedPoints'] + 253 row_df['yard_line'] = dnd['yardLine'] + 254 ppa_df = pd.concat([ppa_df, row_df], ignore_index=True) + 255 + 256 return ppa_df + 257 + 258 + 259def get_cfbd_team_season_ppa_data( + 260 api_key: str = None, + 261 api_key_dir: str = None, + 262 season: int = None, + 263 team: str = None, + 264 # `year` and/or `team` must be not null for this function to work. + 265 conference_abv: str = None, + 266 exclude_garbage_time: bool = False, + 267 return_as_dict: bool = False): + 268 """ + 269 Allows you to get team PPA data, + 270 over an entire season, + 271 with or without garbage time plays, + 272 for a specificed team and/or time period. + 273 + 274 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + 275 + 276 Parameters + 277 ---------- + 278 `api_key` (str, optional): + 279 Semi-optional argument. + 280 If `api_key` is null, this function will attempt to load a CFBD API key + 281 from the python environment, or from a file on this computer. + 282 If `api_key` is not null, this function will automatically assume that the + 283 inputted `api_key` is a valid CFBD API key. + 284 + 285 `api_key_dir` (str, optional): + 286 Optional argument. + 287 If `api_key` is set to am empty string, this variable is ignored. + 288 If `api_key_dir` is null, and `api_key` is null, + 289 this function will try to find a CFBD API key file in this user's home directory. + 290 If `api_key_dir` is set to a string, and `api_key` is null, + 291 this function will assume that `api_key_dir` is a directory, + 292 and will try to find a CFBD API key file in that directory. + 293 + 294 `season` (int, optional): + 295 Semi-optional argument. + 296 Specifies the season you want team PPA data from. + 297 You MUST set `season` or `team` to a non-null value for + 298 this function to work. If you don't, a `ValueError()` + 299 will be raised. + 300 + 301 `team` (str, optional): + 302 Semi-ptional argument. + 303 If you only want team PPA data for a specific team, + 304 set `team` to the name of the team you want team PPA data from. + 305 You MUST set `season` or `team` to a non-null value for + 306 this function to work. If you don't, a `ValueError()` + 307 will be raised. + 308 + 309 `conference_abv` (str, optional): + 310 Optional argument. + 311 If you only want team PPA data from games + 312 involving teams from a specific confrence, + 313 set `conference_abv` to the abbreviation + 314 of the conference you want team PPA data from. + 315 For a list of confrences, + 316 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` + 317 function. + 318 + 319 `exclude_garbage_time` (bool, optional): + 320 Optional argument. + 321 If you want to filter out plays where the result of the game is largely decided, + 322 set `exclude_garbage_time = True`. + 323 Default behavior is that this variable is set to + 324 `False` when this function is called. + 325 + 326 `return_as_dict` (bool, semi-optional): + 327 Semi-optional argument. + 328 If you want this function to return the data as a dictionary (read: JSON object), + 329 instead of a pandas `DataFrame` object, + 330 set `return_as_dict` to `True`. + 331 + 332 Usage + 333 ---------- + 334 ``` + 335 import time + 336 + 337 from cfbd_json_py.metrics import get_cfbd_team_ppa_data + 338 + 339 + 340 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 341 + 342 if cfbd_key != "tigersAreAwsome": + 343 print("Using the user's API key declared in this script for this example.") + 344 + 345 # Get team season PPA data for the 2020 CFB season. + 346 print("Get team PPA data for the 2020 CFB season.") + 347 json_data = get_cfbd_team_ppa_data( + 348 api_key=cfbd_key, + 349 season=2020 + 350 ) + 351 print(json_data) + 352 time.sleep(5) + 353 + 354 # Get team season PPA data for the 2020 Ohio State Buckeyes. + 355 print("Get team season PPA data for the 2020 Ohio State Buckeyes.") + 356 json_data = get_cfbd_team_ppa_data( + 357 api_key=cfbd_key, + 358 season=2020, + 359 team="Ohio State" + 360 ) + 361 print(json_data) + 362 time.sleep(5) + 363 + 364 # Get team season PPA data for the 2020 Ohio State Buckeyes, + 365 # but exclude garbage time plays when making the PPA calculations. + 366 print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") + 367 json_data = get_cfbd_team_ppa_data( + 368 api_key=cfbd_key, + 369 season=2020, + 370 team="Ohio State", + 371 exclude_garbage_time=True + 372 ) + 373 print(json_data) + 374 time.sleep(5) + 375 + 376 # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. + 377 print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") + 378 json_data = get_cfbd_team_ppa_data( + 379 api_key=cfbd_key, + 380 season=2020, + 381 conference_abv="B1G" + 382 ) + 383 print(json_data) + 384 time.sleep(5) + 385 + 386 # You can also tell this function to just return the API call as + 387 # a Dictionary (read: JSON) object. + 388 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 389 json_data = get_cfbd_team_ppa_data( + 390 api_key=cfbd_key, + 391 season=2020, + 392 conference_abv="B1G", + 393 return_as_dict=True + 394 ) + 395 print(json_data) + 396 + 397 else: + 398 # Alternatively, if the CFBD API key exists in this python environment, + 399 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 400 # you could just call these functions directly, without setting the API key + 401 # in the script. + 402 print("Using the user's API key suposedly loaded into this python environment for this example.") + 403 + 404 # Get team season PPA data for the 2020 CFB season. + 405 print("Get team PPA data for the 2020 CFB season.") + 406 json_data = get_cfbd_team_ppa_data( + 407 season=2020 + 408 ) + 409 print(json_data) + 410 time.sleep(5) + 411 + 412 # Get team season PPA data for the 2020 Ohio State Buckeyes. + 413 print("Get team season PPA data for the 2020 Ohio State Buckeyes.") + 414 json_data = get_cfbd_team_ppa_data( + 415 season=2020, + 416 team="Ohio State" + 417 ) + 418 print(json_data) + 419 time.sleep(5) + 420 + 421 # Get team season PPA data for the 2020 Ohio State Buckeyes, + 422 # but exclude garbage time plays when making the PPA calculations. + 423 print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") + 424 json_data = get_cfbd_team_ppa_data( + 425 season=2020, + 426 team="Ohio State", + 427 exclude_garbage_time=True + 428 ) + 429 print(json_data) + 430 time.sleep(5) + 431 + 432 # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. + 433 print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") + 434 json_data = get_cfbd_team_ppa_data( + 435 season=2020, + 436 conference_abv="B1G" + 437 ) + 438 print(json_data) + 439 time.sleep(5) + 440 + 441 # You can also tell this function to just return the API call as + 442 # a Dictionary (read: JSON) object. + 443 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 444 json_data = get_cfbd_team_ppa_data( + 445 season=2020, + 446 conference_abv="B1G", + 447 return_as_dict=True + 448 ) + 449 print(json_data) + 450 + 451 ``` + 452 Returns + 453 ---------- + 454 A pandas `DataFrame` object with team season PPA data, + 455 or (if `return_as_dict` is set to `True`) + 456 a dictionary object with a team season PPA data. + 457 + 458 """ + 459 + 460 now = datetime.now() + 461 ppa_df = pd.DataFrame() + 462 row_df = pd.DataFrame() + 463 url = "https://api.collegefootballdata.com/ppa/teams" + 464 + 465 ######################################################################################################################################################################################################## + 466 + 467 if api_key != None: + 468 real_api_key = api_key + 469 del api_key + 470 else: + 471 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + 472 + 473 if real_api_key == "tigersAreAwsome": + 474 raise ValueError( + 475 "You actually need to change `cfbd_key` to your CFBD API key.") + 476 elif "Bearer " in real_api_key: + 477 pass + 478 elif "Bearer" in real_api_key: + 479 real_api_key = real_api_key.replace('Bearer', 'Bearer ') + 480 else: + 481 real_api_key = "Bearer " + real_api_key + 482 + 483 if season == None and team == None: + 484 raise ValueError( + 485 "To use this function, `season` and/or `team` must be set to a " + + 486 "non-null variable." + 487 ) + 488 + 489 if season == None: + 490 # Rare, but in this endpoint, + 491 # you don't need to input the season. + 492 pass + 493 elif season > now.year: + 494 raise ValueError(f"`season` cannot be greater than {season}.") + 495 elif season < 1869: + 496 raise ValueError(f"`season` cannot be less than 1869.") + 497 + 498 gt_str = "" + 499 if exclude_garbage_time == True: + 500 gt_str = "true" + 501 elif exclude_garbage_time == False: + 502 gt_str = "false" + 503 + 504 # URL builder + 505 ######################################################################################################################################################################################################## + 506 url_elements = 0 + 507 + 508 if season != None and url_elements == 0: + 509 url += f"?year={season}" + 510 url_elements += 1 + 511 elif season != None: + 512 url += f"&year={season}" + 513 url_elements += 1 + 514 + 515 if team != None and url_elements == 0: + 516 url += f"?team={team}" + 517 url_elements += 1 + 518 elif team != None: + 519 url += f"&team={team}" + 520 url_elements += 1 + 521 + 522 if conference_abv != None and url_elements == 0: + 523 url += f"?conference={conference_abv}" + 524 url_elements += 1 + 525 elif conference_abv != None: + 526 url += f"&conference={conference_abv}" + 527 url_elements += 1 + 528 + 529 if exclude_garbage_time != None and url_elements == 0: + 530 url += f"?excludeGarbageTime={gt_str}" + 531 url_elements += 1 + 532 elif exclude_garbage_time != None: + 533 url += f"&excludeGarbageTime={gt_str}" + 534 url_elements += 1 + 535 + 536 headers = { + 537 'Authorization': f'{real_api_key}', + 538 'accept': 'application/json' + 539 } + 540 + 541 response = requests.get(url, headers=headers) + 542 + 543 if response.status_code == 200: + 544 pass + 545 elif response.status_code == 401: + 546 raise ConnectionRefusedError( + 547 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + 548 ) + 549 else: + 550 raise ConnectionError( + 551 f'Could not connect.\nHTTP Status code {response.status_code}' + 552 ) + 553 + 554 json_data = response.json() + 555 + 556 if return_as_dict == True: + 557 return json_data + 558 + 559 for team in tqdm(json_data): + 560 t_season = team['season'] + 561 t_conference = team['conference'] + 562 t_name = team['team'] + 563 + 564 row_df = pd.DataFrame( + 565 { + 566 "season": t_season, + 567 "team_name": t_name, + 568 "team_conference": t_conference + 569 }, + 570 index=[0] + 571 ) + 572 + 573 # Team offense + 574 row_df['offensive_ppa_overall'] = team['offense']['overall'] + 575 row_df['offensive_ppa_passing'] = team['offense']['passing'] + 576 row_df['offensive_ppa_rushing'] = team['offense']['rushing'] + 577 row_df['offensive_ppa_first_down'] = team['offense']['firstDown'] + 578 row_df['offensive_ppa_second_down'] = team['offense']['secondDown'] + 579 row_df['offensive_ppa_third_down'] = team['offense']['thirdDown'] + 580 row_df['offensive_ppa_cumulative'] = team['offense']['cumulative']['total'] + 581 row_df['offensive_ppa_cumulative_passing'] = team['offense']['cumulative']['passing'] + 582 row_df['offensive_ppa_cumulative_rushing'] = team['offense']['cumulative']['rushing'] + 583 + 584 # Team defense + 585 row_df['defensive_ppa_overall'] = team['defense']['overall'] + 586 row_df['defensive_ppa_passing'] = team['defense']['passing'] + 587 row_df['defensive_ppa_rushing'] = team['defense']['rushing'] + 588 row_df['defensive_ppa_first_down'] = team['defense']['firstDown'] + 589 row_df['defensive_ppa_second_down'] = team['defense']['secondDown'] + 590 row_df['defensive_ppa_third_down'] = team['defense']['thirdDown'] + 591 row_df['defensive_ppa_cumulative'] = team['defense']['cumulative']['total'] + 592 row_df['defensive_ppa_cumulative_passing'] = team['defense']['cumulative']['passing'] + 593 row_df['defensive_ppa_cumulative_rushing'] = team['defense']['cumulative']['rushing'] + 594 + 595 ppa_df = pd.concat([ppa_df, row_df], ignore_index=True) + 596 + 597 del t_season, t_conference, t_name + 598 del row_df + 599 + 600 return ppa_df + 601 + 602 + 603def get_cfbd_team_game_ppa_data( + 604 season: int, + 605 api_key: str = None, + 606 api_key_dir: str = None, + 607 week: int = None, + 608 team: str = None, + 609 conference_abv: str = None, + 610 exclude_garbage_time: bool = False, + 611 season_type: str = "regular", # "regular" or "postseason" + 612 return_as_dict: bool = False): + 613 """ + 614 Allows you to get team PPA data, + 615 at a game level, + 616 with or without garbage time plays, + 617 for a specificed team and/or time period. + 618 + 619 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + 620 + 621 Parameters + 622 ---------- + 623 `season` (int, mandatory): + 624 Required argument. + 625 Specifies the season you want team game PPA data information from. + 626 This must be specified, otherwise this package, and by extension + 627 the CFBD API, will not accept the request to get team game PPA data information. + 628 + 629 `api_key` (str, optional): + 630 Semi-optional argument. + 631 If `api_key` is null, this function will attempt to load a CFBD API key + 632 from the python environment, or from a file on this computer. + 633 If `api_key` is not null, this function will automatically assume that the + 634 inputted `api_key` is a valid CFBD API key. + 635 + 636 `api_key_dir` (str, optional): + 637 Optional argument. + 638 If `api_key` is set to am empty string, this variable is ignored. + 639 If `api_key_dir` is null, and `api_key` is null, + 640 this function will try to find a CFBD API key file in this user's home directory. + 641 If `api_key_dir` is set to a string, and `api_key` is null, + 642 this function will assume that `api_key_dir` is a directory, + 643 and will try to find a CFBD API key file in that directory. + 644 + 645 `week` (int, optional): + 646 Optional argument. + 647 If `week` is set to an integer, this function will attempt + 648 to load team game PPA data from games in that season, and in that week. + 649 + 650 `team` (str, optional): + 651 Optional argument. + 652 If you only want team game PPA data for a team, + 653 regardless if they are the home/away team, + 654 set `team` to the name of the team you want team game PPA data from. + 655 + 656 `conference_abv` (str, optional): + 657 Optional argument. + 658 If you only want team game PPA data from games + 659 involving teams a specific confrence, + 660 set `conference_abv` to the abbreviation + 661 of the conference you want team game PPA data from. + 662 + 663 `exclude_garbage_time` (bool, optional): + 664 Optional argument. + 665 If you want to filter out plays where the result of the game is largely decided, + 666 set `exclude_garbage_time = True`. + 667 Default behavior is that this variable is set to + 668 `False` when this function is called. + 669 + 670 `season_type` (str, semi-optional): + 671 Semi-optional argument. + 672 By defualt, this will be set to "regular", for the CFB regular season. + 673 If you want team game PPA data for non-regular season games, + 674 set `season_type` to "postseason". + 675 If `season_type` is set to anything but "regular" or "postseason", + 676 a `ValueError()` will be raised. + 677 + 678 `return_as_dict` (bool, semi-optional): + 679 Semi-optional argument. + 680 If you want this function to return the data as a dictionary (read: JSON object), + 681 instead of a pandas `DataFrame` object, + 682 set `return_as_dict` to `True`. + 683 + 684 Usage + 685 ---------- + 686 ``` + 687 import time + 688 + 689 from cfbd_json_py.metrics import get_cfbd_team_game_ppa_data + 690 + 691 + 692 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 693 + 694 if cfbd_key != "tigersAreAwsome": + 695 print("Using the user's API key declared in this script for this example.") + 696 + 697 # Get team PPA data for individual games within the 2020 CFB season. + 698 print("Get team PPA data for individual games within the 2020 CFB season.") + 699 json_data = get_cfbd_team_game_ppa_data( + 700 api_key=cfbd_key, + 701 season=2020 + 702 ) + 703 print(json_data) + 704 time.sleep(5) + 705 + 706 # Get team PPA data for week 10 games within the 2020 CFB season. + 707 print("Get team PPA data for week 10 games within the 2020 CFB season.") + 708 json_data = get_cfbd_team_game_ppa_data( + 709 api_key=cfbd_key, + 710 season=2020, + 711 week=10 + 712 ) + 713 print(json_data) + 714 time.sleep(5) + 715 + 716 # Get team PPA data for + 717 # University of Cincinnati football games within the 2020 CFB season. + 718 print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") + 719 json_data = get_cfbd_team_game_ppa_data( + 720 api_key=cfbd_key, + 721 season=2020, + 722 team="Cincinnati" + 723 ) + 724 print(json_data) + 725 time.sleep(5) + 726 + 727 # Get team PPA data for Southeastern Conference (SEC) + 728 # games within the 2020 CFB season. + 729 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") + 730 json_data = get_cfbd_team_game_ppa_data( + 731 api_key=cfbd_key, + 732 season=2020, + 733 conference_abv="SEC" + 734 ) + 735 print(json_data) + 736 time.sleep(5) + 737 + 738 # Get team PPA data for Southeastern Conference (SEC) + 739 # games within the 2020 CFB season, but exclude plays that occur in garbage time. + 740 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") + 741 json_data = get_cfbd_team_game_ppa_data( + 742 api_key=cfbd_key, + 743 season=2020, + 744 conference_abv="SEC", + 745 exclude_garbage_time=True + 746 ) + 747 print(json_data) + 748 time.sleep(5) + 749 + 750 # Get team PPA data for postseason games in the 2020 CFB season. + 751 print("Get team PPA data for postseason games in the 2020 CFB season.") + 752 json_data = get_cfbd_team_game_ppa_data( + 753 api_key=cfbd_key, + 754 season=2020, + 755 season_type="postseason" + 756 ) + 757 print(json_data) + 758 time.sleep(5) + 759 + 760 # You can also tell this function to just return the API call as + 761 # a Dictionary (read: JSON) object. + 762 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 763 json_data = get_cfbd_team_game_ppa_data( + 764 api_key=cfbd_key, + 765 season=2020, + 766 team="Cincinnati", + 767 return_as_dict=True + 768 ) + 769 print(json_data) + 770 + 771 else: + 772 # Alternatively, if the CFBD API key exists in this python environment, + 773 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + 774 # you could just call these functions directly, without setting the API key + 775 # in the script. + 776 print("Using the user's API key suposedly loaded into this python environment for this example.") + 777 + 778 # Get team PPA data for individual games within the 2020 CFB season. + 779 print("Get team PPA data for individual games within the 2020 CFB season.") + 780 json_data = get_cfbd_team_game_ppa_data( + 781 season=2020 + 782 ) + 783 print(json_data) + 784 time.sleep(5) + 785 + 786 # Get team PPA data for week 10 games within the 2020 CFB season. + 787 print("Get team PPA data for week 10 games within the 2020 CFB season.") + 788 json_data = get_cfbd_team_game_ppa_data( + 789 season=2020, + 790 week=10 + 791 ) + 792 print(json_data) + 793 time.sleep(5) + 794 + 795 # Get team PPA data for + 796 # University of Cincinnati football games within the 2020 CFB season. + 797 print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") + 798 json_data = get_cfbd_team_game_ppa_data( + 799 season=2020, + 800 team="Cincinnati" + 801 ) + 802 print(json_data) + 803 time.sleep(5) + 804 + 805 # Get team PPA data for Southeastern Conference (SEC) + 806 # games within the 2020 CFB season. + 807 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") + 808 json_data = get_cfbd_team_game_ppa_data( + 809 season=2020, + 810 conference_abv="SEC" + 811 ) + 812 print(json_data) + 813 time.sleep(5) + 814 + 815 # Get team PPA data for Southeastern Conference (SEC) + 816 # games within the 2020 CFB season, but exclude plays that occur in garbage time. + 817 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") + 818 json_data = get_cfbd_team_game_ppa_data( + 819 season=2020, + 820 conference_abv="SEC", + 821 exclude_garbage_time=True + 822 ) + 823 print(json_data) + 824 time.sleep(5) + 825 + 826 # Get team PPA data for postseason games in the 2020 CFB season. + 827 print("Get team PPA data for postseason games in the 2020 CFB season.") + 828 json_data = get_cfbd_team_game_ppa_data( + 829 season=2020, + 830 season_type="postseason" + 831 ) + 832 print(json_data) + 833 time.sleep(5) + 834 + 835 # You can also tell this function to just return the API call as + 836 # a Dictionary (read: JSON) object. + 837 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 838 json_data = get_cfbd_team_game_ppa_data( + 839 season=2020, + 840 team="Cincinnati", + 841 return_as_dict=True + 842 ) + 843 print(json_data) + 844 + 845 ``` + 846 Returns + 847 ---------- + 848 A pandas `DataFrame` object with team PPA data, + 849 or (if `return_as_dict` is set to `True`) + 850 a dictionary object with team PPA data. + 851 + 852 """ + 853 + 854 now = datetime.now() + 855 cfb_games_df = pd.DataFrame() + 856 row_df = pd.DataFrame() + 857 url = "https://api.collegefootballdata.com/ppa/games" + 858 + 859 ######################################################################################################################################################################################################## + 860 + 861 if api_key != None: + 862 real_api_key = api_key + 863 del api_key + 864 else: + 865 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) + 866 + 867 if real_api_key == "tigersAreAwsome": + 868 raise ValueError( + 869 "You actually need to change `cfbd_key` to your CFBD API key.") + 870 elif "Bearer " in real_api_key: + 871 pass + 872 elif "Bearer" in real_api_key: + 873 real_api_key = real_api_key.replace('Bearer', 'Bearer ') + 874 else: + 875 real_api_key = "Bearer " + real_api_key + 876 + 877 if season == None: + 878 # This should never happen without user tampering, but if it does, + 879 # we need to raise an error, because the CFBD API will refuse this call without a valid season. + 880 raise SystemError( + 881 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + + 882 " and the function got to this point in the code." + + 883 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + + 884 "https://github.com/armstjc/cfbd-json-py/issues" + 885 ) + 886 elif season > now.year: + 887 raise ValueError(f"`season` cannot be greater than {season}.") + 888 elif season < 1869: + 889 raise ValueError(f"`season` cannot be less than 1869.") + 890 + 891 if season_type != "regular" and season_type != "postseason": + 892 raise ValueError( + 893 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + 894 + 895 if week != None and week < 0: + 896 raise ValueError( + 897 "`week` must be a positive number." + 898 ) + 899 + 900 if season_type != "regular" and season_type != "postseason": + 901 raise ValueError( + 902 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") + 903 + 904 gt_str = "" + 905 if exclude_garbage_time == True: + 906 gt_str = "true" + 907 elif exclude_garbage_time == False: + 908 gt_str = "false" + 909 + 910 # URL builder + 911 ######################################################################################################################################################################################################## + 912 + 913 # Required by API + 914 url += f"?seasonType={season_type}" + 915 url += f"&year={season}" + 916 + 917 if week != None: + 918 url += f"&week={week}" + 919 + 920 if team != None: + 921 url += f"&team={team}" + 922 + 923 if conference_abv != None: + 924 url += f"&conference={conference_abv}" + 925 + 926 if exclude_garbage_time != None: + 927 url += f"&excludeGarbageTime={gt_str}" + 928 + 929 headers = { + 930 'Authorization': f'{real_api_key}', + 931 'accept': 'application/json' + 932 } + 933 response = requests.get(url, headers=headers) + 934 + 935 if response.status_code == 200: + 936 pass + 937 elif response.status_code == 401: + 938 raise ConnectionRefusedError( + 939 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' + 940 ) + 941 else: + 942 raise ConnectionError( + 943 f'Could not connect.\nHTTP Status code {response.status_code}' + 944 ) + 945 + 946 json_data = response.json() + 947 + 948 if return_as_dict == True: + 949 return json_data + 950 + 951 for game in tqdm(json_data): + 952 g_season = game['season'] + 953 g_gid = game['gameId'] + 954 g_week = game['week'] + 955 g_tm = game['team'] + 956 g_conf = game['conference'] + 957 g_opp = game['opponent'] + 958 + 959 row_df = pd.DataFrame( + 960 { + 961 "season": g_season, + 962 "game_id": g_gid, + 963 "week": g_week, + 964 "team": g_tm, + 965 "conference": g_conf, + 966 "opponent": g_opp + 967 }, + 968 index=[0] + 969 ) + 970 + 971 # Team Offense + 972 row_df['ppa_offense_overall'] = game['offense']['overall'] + 973 row_df['ppa_offense_passing'] = game['offense']['passing'] + 974 row_df['ppa_offense_rushing'] = game['offense']['rushing'] + 975 row_df['ppa_offense_first_down'] = game['offense']['firstDown'] + 976 row_df['ppa_offense_second_down'] = game['offense']['secondDown'] + 977 row_df['ppa_offense_third_down'] = game['offense']['thirdDown'] + 978 + 979 # Team Defense + 980 row_df['ppa_defense_overall'] = game['defense']['overall'] + 981 row_df['ppa_defense_passing'] = game['defense']['passing'] + 982 row_df['ppa_defense_rushing'] = game['defense']['rushing'] + 983 row_df['ppa_defense_first_down'] = game['defense']['firstDown'] + 984 row_df['ppa_defense_second_down'] = game['defense']['secondDown'] + 985 row_df['ppa_defense_third_down'] = game['defense']['thirdDown'] + 986 + 987 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) + 988 + 989 del row_df + 990 del g_gid, g_season, g_week,\ + 991 g_conf, g_tm, g_opp + 992 + 993 return cfb_games_df + 994 + 995 + 996def get_cfbd_player_game_ppa_data( + 997 api_key: str = None, + 998 api_key_dir: str = None, + 999 season: int = None, +1000 week: int = None, +1001 team: str = None, +1002 # A week or team must be specified +1003 position: str = None, +1004 player_id: int = None, +1005 play_threshold: int = None, +1006 exclude_garbage_time: bool = False, +1007 season_type: str = "regular", # "regular" or "postseason" +1008 return_as_dict: bool = False): +1009 """ +1010 Allows you to get player PPA data, +1011 at a game level, +1012 with or without garbage time plays, +1013 for a specificed time period and/or team. +1014 +1015 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). +1016 +1017 Parameters +1018 ---------- +1019 +1020 `api_key` (str, optional): +1021 Semi-optional argument. +1022 If `api_key` is null, this function will attempt to load a CFBD API key +1023 from the python environment, or from a file on this computer. +1024 If `api_key` is not null, this function will automatically assume that the +1025 inputted `api_key` is a valid CFBD API key. +1026 +1027 `api_key_dir` (str, optional): +1028 Optional argument. +1029 If `api_key` is set to am empty string, this variable is ignored. +1030 If `api_key_dir` is null, and `api_key` is null, +1031 this function will try to find a CFBD API key file in this user's home directory. +1032 If `api_key_dir` is set to a string, and `api_key` is null, +1033 this function will assume that `api_key_dir` is a directory, +1034 and will try to find a CFBD API key file in that directory. +1035 +1036 `season` (int, semi-optional): +1037 Semi-Optional argument. +1038 Specifies the season you want player game PPA data information from. +1039 This must be specified, otherwise this package, and by extension +1040 the CFBD API, will not accept the request to get player game PPA data information. +1041 +1042 `week` (int, semi-optional): +1043 Semi-Optional argument. +1044 If `week` is set to an integer, this function will attempt +1045 to load player game PPA data from games in that season, and in that week. +1046 `week` and/or `team` must be set to a non-null value for this function +1047 to work. +1048 +1049 `team` (str, semi-optional): +1050 Semi-Optional argument. +1051 If you only want player game PPA data for players of a specific team, +1052 regardless if they are the home/away team, +1053 set `team` to the name of the team you want player game PPA data from. +1054 `week` and/or `team` must be set to a non-null value for this function +1055 to work. +1056 +1057 `position` (str, optional): +1058 Optional argument. +1059 If you only want player game PPA data for players of a specific position, +1060 set `position` to the position you want player game PPA data from. +1061 +1062 `player_id` (int, optional): +1063 Optional argument. +1064 If you only want PPA data for a specific player ID, +1065 set this variable to the player ID of the player you want PPA data from. +1066 +1067 `play_threshold` +1068 Optional argument. +1069 If you only want PPA data for players +1070 who touched the ball for *X* number of plays in a game, +1071 set `play_threshold = x`, where `x` is +1072 your specified minimum number of plays. +1073 +1074 `exclude_garbage_time` (bool, optional): +1075 Optional argument. +1076 If you want to filter out plays where the result of the game is largely decided, +1077 set `exclude_garbage_time = True`. +1078 Default behavior is that this variable is set to +1079 `False` when this function is called. +1080 +1081 `season_type` (str, semi-optional): +1082 Semi-optional argument. +1083 By defualt, this will be set to "regular", for the CFB regular season. +1084 If you want player game PPA data for non-regular season games, +1085 set `season_type` to "postseason". +1086 If `season_type` is set to anything but "regular" or "postseason", +1087 a `ValueError()` will be raised. +1088 +1089 `return_as_dict` (bool, semi-optional): +1090 Semi-optional argument. +1091 If you want this function to return the data as a dictionary (read: JSON object), +1092 instead of a pandas `DataFrame` object, +1093 set `return_as_dict` to `True`. +1094 +1095 Usage +1096 ---------- +1097 ``` +1098 import time +1099 +1100 from cfbd_json_py.metrics import get_cfbd_player_game_ppa_data +1101 +1102 +1103 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1104 +1105 if cfbd_key != "tigersAreAwsome": +1106 print("Using the user's API key declared in this script for this example.") +1107 +1108 # Get player game PPA data for week 10 of the 2020 CFB season. +1109 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1110 json_data = get_cfbd_player_game_ppa_data( +1111 api_key=cfbd_key, +1112 season=2020, +1113 week=10 +1114 ) +1115 print(json_data) +1116 time.sleep(5) +1117 +1118 # Get player game PPA data for players of the +1119 # 2020 University of Cincinnati Football team. +1120 print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") +1121 json_data = get_cfbd_player_game_ppa_data( +1122 api_key=cfbd_key, +1123 season=2020, +1124 team="Cincinnati" +1125 ) +1126 print(json_data) +1127 time.sleep(5) +1128 +1129 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. +1130 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1131 json_data = get_cfbd_player_game_ppa_data( +1132 api_key=cfbd_key, +1133 season=2020, +1134 week=10, +1135 position="QB" +1136 ) +1137 print(json_data) +1138 time.sleep(5) +1139 +1140 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, +1141 # but exclude plays in garbage time. +1142 print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") +1143 json_data = get_cfbd_player_game_ppa_data( +1144 api_key=cfbd_key, +1145 season=2020, +1146 week=10, +1147 position="QB", +1148 exclude_garbage_time=True +1149 ) +1150 print(json_data) +1151 time.sleep(5) +1152 +1153 # Get player game PPA data for week 10 of the 2020 CFB season, +1154 # where a player touched the ball for at least 25 plays. +1155 print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") +1156 json_data = get_cfbd_player_game_ppa_data( +1157 api_key=cfbd_key, +1158 season=2020, +1159 week=10, +1160 play_threshold=25 +1161 ) +1162 print(json_data) +1163 time.sleep(5) +1164 +1165 # Get player game PPA data the 2020 Alabama Crimson Tide Football team, +1166 # during their postseason. +1167 print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") +1168 json_data = get_cfbd_player_game_ppa_data( +1169 api_key=cfbd_key, +1170 season=2020, +1171 team="Alabama", +1172 season_type="postseason" +1173 ) +1174 print(json_data) +1175 time.sleep(5) +1176 +1177 # You can also tell this function to just return the API call as +1178 # a Dictionary (read: JSON) object. +1179 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1180 json_data = get_cfbd_player_game_ppa_data( +1181 api_key=cfbd_key, +1182 season=2020, +1183 week=10, +1184 return_as_dict=True +1185 ) +1186 print(json_data) +1187 +1188 else: +1189 # Alternatively, if the CFBD API key exists in this python environment, +1190 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1191 # you could just call these functions directly, without setting the API key +1192 # in the script. +1193 print("Using the user's API key suposedly loaded into this python environment for this example.") +1194 +1195 # Get player game PPA data for week 10 of the 2020 CFB season. +1196 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1197 json_data = get_cfbd_player_game_ppa_data( +1198 season=2020, +1199 week=10 +1200 ) +1201 print(json_data) +1202 time.sleep(5) +1203 +1204 # Get player game PPA data for players of the +1205 # 2020 University of Cincinnati Football team. +1206 print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") +1207 json_data = get_cfbd_player_game_ppa_data( +1208 season=2020, +1209 team="Cincinnati" +1210 ) +1211 print(json_data) +1212 time.sleep(5) +1213 +1214 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. +1215 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1216 json_data = get_cfbd_player_game_ppa_data( +1217 season=2020, +1218 week=10, +1219 position="QB" +1220 ) +1221 print(json_data) +1222 time.sleep(5) +1223 +1224 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, +1225 # but exclude plays in garbage time. +1226 print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") +1227 json_data = get_cfbd_player_game_ppa_data( +1228 season=2020, +1229 week=10, +1230 position="QB", +1231 exclude_garbage_time=True +1232 ) +1233 print(json_data) +1234 time.sleep(5) +1235 +1236 # Get player game PPA data for week 10 of the 2020 CFB season, +1237 # where a player touched the ball for at least 25 plays. +1238 print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") +1239 json_data = get_cfbd_player_game_ppa_data( +1240 season=2020, +1241 week=10, +1242 play_threshold=25 +1243 ) +1244 print(json_data) +1245 time.sleep(5) +1246 +1247 # Get player game PPA data the 2020 Alabama Crimson Tide Football team, +1248 # during their postseason. +1249 print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") +1250 json_data = get_cfbd_player_game_ppa_data( +1251 season=2020, +1252 team="Alabama", +1253 season_type="postseason" +1254 ) +1255 print(json_data) +1256 time.sleep(5) +1257 +1258 # You can also tell this function to just return the API call as +1259 # a Dictionary (read: JSON) object. +1260 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1261 json_data = get_cfbd_player_game_ppa_data( +1262 season=2020, +1263 week=10, +1264 return_as_dict=True +1265 ) +1266 print(json_data) +1267 +1268 ``` +1269 Returns +1270 ---------- +1271 A pandas `DataFrame` object with player PPA data, +1272 or (if `return_as_dict` is set to `True`) +1273 a dictionary object with player PPA data. +1274 +1275 """ +1276 +1277 now = datetime.now() +1278 cfb_games_df = pd.DataFrame() +1279 row_df = pd.DataFrame() +1280 url = "https://api.collegefootballdata.com/ppa/players/games" +1281 +1282 ######################################################################################################################################################################################################## +1283 +1284 if api_key != None: +1285 real_api_key = api_key +1286 del api_key +1287 else: +1288 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1289 +1290 if real_api_key == "tigersAreAwsome": +1291 raise ValueError( +1292 "You actually need to change `cfbd_key` to your CFBD API key.") +1293 elif "Bearer " in real_api_key: +1294 pass +1295 elif "Bearer" in real_api_key: +1296 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1297 else: +1298 real_api_key = "Bearer " + real_api_key +1299 +1300 if season == None: +1301 # This should never happen without user tampering, but if it does, +1302 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +1303 raise SystemError( +1304 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +1305 " and the function got to this point in the code." + +1306 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +1307 "https://github.com/armstjc/cfbd-json-py/issues" +1308 ) +1309 elif season > now.year: +1310 raise ValueError(f"`season` cannot be greater than {season}.") +1311 elif season < 1869: +1312 raise ValueError(f"`season` cannot be less than 1869.") +1313 +1314 if week == None and team == None: +1315 raise ValueError( +1316 "To call this function, you must set `week` and/or `team` " + +1317 "to a non-null value." +1318 ) +1319 +1320 if season_type != "regular" and season_type != "postseason": +1321 raise ValueError( +1322 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +1323 +1324 if week != None and week < 0: +1325 raise ValueError( +1326 "`week` must be a positive number." +1327 ) +1328 +1329 if season_type != "regular" and season_type != "postseason": +1330 raise ValueError( +1331 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +1332 +1333 if play_threshold != None and play_threshold < 0: +1334 raise ValueError( +1335 "`play_threshold` must be an integer at or greater than 0." +1336 ) +1337 +1338 gt_str = "" +1339 if exclude_garbage_time == True: +1340 gt_str = "true" +1341 elif exclude_garbage_time == False: +1342 gt_str = "false" +1343 +1344 # URL builder +1345 ######################################################################################################################################################################################################## +1346 url_elements = 0 +1347 +1348 if season != None and url_elements == 0: +1349 url += f"?year={season}" +1350 url_elements += 1 +1351 elif season != None: +1352 url += f"&year={season}" +1353 url_elements += 1 +1354 +1355 if week != None and url_elements == 0: +1356 url += f"?week={week}" +1357 url_elements += 1 +1358 elif week != None: +1359 url += f"&week={week}" +1360 url_elements += 1 +1361 +1362 if team != None and url_elements == 0: +1363 url += f"?team={team}" +1364 url_elements += 1 +1365 elif team != None: +1366 url += f"&team={team}" +1367 url_elements += 1 +1368 +1369 if position != None and url_elements == 0: +1370 url += f"?position={position}" +1371 url_elements += 1 +1372 elif position != None: +1373 url += f"&position={position}" +1374 url_elements += 1 +1375 +1376 if player_id != None and url_elements == 0: +1377 url += f"?playerId={player_id}" +1378 url_elements += 1 +1379 elif player_id != None: +1380 url += f"&playerId={player_id}" +1381 url_elements += 1 +1382 +1383 if play_threshold != None and url_elements == 0: +1384 url += f"?threshold={play_threshold}" +1385 url_elements += 1 +1386 elif play_threshold != None: +1387 url += f"&threshold={play_threshold}" +1388 url_elements += 1 +1389 +1390 if exclude_garbage_time != None and url_elements == 0: +1391 url += f"?excludeGarbageTime={gt_str}" +1392 url_elements += 1 +1393 elif exclude_garbage_time != None: +1394 url += f"&excludeGarbageTime={gt_str}" +1395 url_elements += 1 +1396 +1397 if season_type != None and url_elements == 0: +1398 url += f"?seasonType={season_type}" +1399 url_elements += 1 +1400 elif season_type != None: +1401 url += f"&seasonType={season_type}" +1402 url_elements += 1 +1403 +1404 headers = { +1405 'Authorization': f'{real_api_key}', +1406 'accept': 'application/json' +1407 } +1408 response = requests.get(url, headers=headers) +1409 +1410 if response.status_code == 200: +1411 pass +1412 elif response.status_code == 401: +1413 raise ConnectionRefusedError( +1414 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1415 ) +1416 else: +1417 raise ConnectionError( +1418 f'Could not connect.\nHTTP Status code {response.status_code}' +1419 ) +1420 +1421 json_data = response.json() +1422 +1423 if return_as_dict == True: +1424 return json_data +1425 +1426 for player in tqdm(json_data): +1427 p_season = player['season'] +1428 row_df = pd.DataFrame( +1429 { +1430 "season": p_season +1431 }, +1432 index=[0] +1433 ) +1434 +1435 row_df['week'] = player['week'] +1436 row_df['player_name'] = player['name'] +1437 row_df['player_position'] = player['position'] +1438 row_df['team'] = player['team'] +1439 row_df['opponent'] = player['opponent'] +1440 +1441 row_df['avg_ppa_all'] = player['averagePPA']['all'] +1442 row_df['avg_ppa_pass'] = player['averagePPA']['pass'] +1443 row_df['avg_ppa_rush'] = player['averagePPA']['rush'] +1444 +1445 # Have to do this because of a FutureWarning that is raised +1446 # starting in pandas 2.1.1, when using pd.concat(), +1447 # and a column datatype mismatch is found. +1448 row_df = row_df.astype( +1449 { +1450 "avg_ppa_all": "float", +1451 "avg_ppa_pass": "float", +1452 "avg_ppa_rush": "float", +1453 } +1454 ) +1455 +1456 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +1457 +1458 del row_df +1459 del p_season +1460 +1461 return cfb_games_df +1462 +1463 +1464def get_cfbd_player_season_ppa_data( +1465 api_key: str = None, +1466 api_key_dir: str = None, +1467 season: int = None, +1468 team: str = None, +1469 conference_abv: str = None, +1470 position: str = None, +1471 player_id: int = None, +1472 play_threshold: int = None, +1473 exclude_garbage_time: bool = False, +1474 return_as_dict: bool = False): +1475 """ +1476 Allows you to get player PPA data, +1477 at a season level, +1478 with or without garbage time plays, +1479 for a specificed time period and/or team. +1480 +1481 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). +1482 +1483 Parameters +1484 ---------- +1485 +1486 `api_key` (str, optional): +1487 Semi-optional argument. +1488 If `api_key` is null, this function will attempt to load a CFBD API key +1489 from the python environment, or from a file on this computer. +1490 If `api_key` is not null, this function will automatically assume that the +1491 inputted `api_key` is a valid CFBD API key. +1492 +1493 `api_key_dir` (str, optional): +1494 Optional argument. +1495 If `api_key` is set to am empty string, this variable is ignored. +1496 If `api_key_dir` is null, and `api_key` is null, +1497 this function will try to find a CFBD API key file in this user's home directory. +1498 If `api_key_dir` is set to a string, and `api_key` is null, +1499 this function will assume that `api_key_dir` is a directory, +1500 and will try to find a CFBD API key file in that directory. +1501 +1502 `season` (int, semi-optional): +1503 Semi-Optional argument. +1504 Specifies the season you want player season PPA data information from. +1505 This must be specified, otherwise this package, and by extension +1506 the CFBD API, will not accept the request to get player season PPA data information. +1507 +1508 +1509 `team` (str, semi-optional): +1510 Semi-Optional argument. +1511 If you only want player season PPA data for players of a specific team, +1512 regardless if they are the home/away team, +1513 set `team` to the name of the team you want player season PPA data from. +1514 `week` and/or `team` must be set to a non-null value for this function +1515 to work. +1516 +1517 `conference_abv` (str, optional): +1518 Optional argument. +1519 If you only want player season PPA data from games +1520 involving teams from a specific confrence, +1521 set `conference_abv` to the abbreviation +1522 of the conference you want player season PPA data from. +1523 For a list of confrences, +1524 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +1525 function. +1526 +1527 `position` (str, optional): +1528 Optional argument. +1529 If you only want player season PPA data for players of a specific position, +1530 set `position` to the position you want player season PPA data from. +1531 +1532 `player_id` (int, optional): +1533 Optional argument. +1534 If you only want PPA data for a specific player ID, +1535 set this variable to the player ID of the player you want PPA data from. +1536 +1537 `play_threshold` +1538 Optional argument. +1539 If you only want PPA data for players +1540 who touched the ball for *X* number of plays in a game, +1541 set `play_threshold = x`, where `x` is +1542 your specified minimum number of plays. +1543 +1544 `exclude_garbage_time` (bool, optional): +1545 Optional argument. +1546 If you want to filter out plays where the result of the game is largely decided, +1547 set `exclude_garbage_time = True`. +1548 Default behavior is that this variable is set to +1549 `False` when this function is called. +1550 +1551 +1552 `return_as_dict` (bool, semi-optional): +1553 Semi-optional argument. +1554 If you want this function to return the data as a dictionary (read: JSON object), +1555 instead of a pandas `DataFrame` object, +1556 set `return_as_dict` to `True`. +1557 +1558 Usage +1559 ---------- +1560 ``` +1561 import time +1562 +1563 from cfbd_json_py.metrics import get_cfbd_player_season_ppa_data +1564 +1565 +1566 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1567 +1568 if cfbd_key != "tigersAreAwsome": +1569 print("Using the user's API key declared in this script for this example.") +1570 +1571 # Get player season PPA data for the 2020 CFB season. +1572 print("Get player season PPA data for the 2020 CFB season.") +1573 json_data = get_cfbd_player_season_ppa_data( +1574 api_key=cfbd_key, +1575 season=2020 +1576 ) +1577 print(json_data) +1578 time.sleep(5) +1579 +1580 # Get player season PPA data from the 2020 Ohio Bobcats Football Team. +1581 print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") +1582 json_data = get_cfbd_player_season_ppa_data( +1583 api_key=cfbd_key, +1584 season=2020, +1585 team="Ohio" +1586 ) +1587 print(json_data) +1588 time.sleep(5) +1589 +1590 # Get player season PPA data for players who played on +1591 # teams within the Southeastern Conference (SEC) for the +1592 # 2020 CFB Season. +1593 print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") +1594 json_data = get_cfbd_player_season_ppa_data( +1595 api_key=cfbd_key, +1596 season=2020, +1597 conference_abv="SEC" +1598 ) +1599 print(json_data) +1600 time.sleep(5) +1601 +1602 # Get player season PPA data from QBs in the 2020 CFB Season. +1603 print("Get player season PPA data from QBs in the 2020 CFB Season.") +1604 json_data = get_cfbd_player_season_ppa_data( +1605 api_key=cfbd_key, +1606 season=2020, +1607 position="QB" +1608 ) +1609 print(json_data) +1610 time.sleep(5) +1611 +1612 # Get player season PPA data from +1613 # former Ohio State and LSU QB Joe Burrow (player ID #3915511). +1614 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") +1615 json_data = get_cfbd_player_season_ppa_data( +1616 api_key=cfbd_key, +1617 player_id=3915511 +1618 ) +1619 print(json_data) +1620 time.sleep(5) +1621 +1622 # Get player season PPA data from +1623 # former Ohio State and LSU QB Joe Burrow (player ID #3915511), +1624 # but exclude plays that occured in garbage time. +1625 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") +1626 json_data = get_cfbd_player_season_ppa_data( +1627 api_key=cfbd_key, +1628 player_id=3915511, +1629 exclude_garbage_time=True +1630 ) +1631 print(json_data) +1632 time.sleep(5) +1633 +1634 # Get player season PPA data from the 2020 CFB Season, +1635 # for players with at least 100 plays/touches. +1636 print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") +1637 json_data = get_cfbd_player_season_ppa_data( +1638 api_key=cfbd_key, +1639 season=2020, +1640 play_threshold=100 +1641 ) +1642 print(json_data) +1643 time.sleep(5) +1644 +1645 # You can also tell this function to just return the API call as +1646 # a Dictionary (read: JSON) object. +1647 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1648 json_data = get_cfbd_player_season_ppa_data( +1649 api_key=cfbd_key, +1650 season=2020, +1651 return_as_dict=True +1652 ) +1653 print(json_data) +1654 +1655 else: +1656 # Alternatively, if the CFBD API key exists in this python environment, +1657 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1658 # you could just call these functions directly, without setting the API key +1659 # in the script. +1660 print("Using the user's API key suposedly loaded into this python environment for this example.") +1661 +1662 # Get player season PPA data for the 2020 CFB season. +1663 print("Get player season PPA data for the 2020 CFB season.") +1664 json_data = get_cfbd_player_season_ppa_data( +1665 season=2020 +1666 ) +1667 print(json_data) +1668 time.sleep(5) +1669 +1670 # Get player season PPA data from the 2020 Ohio Bobcats Football Team. +1671 print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") +1672 json_data = get_cfbd_player_season_ppa_data( +1673 season=2020, +1674 team="Ohio" +1675 ) +1676 print(json_data) +1677 time.sleep(5) +1678 +1679 # Get player season PPA data for players who played on +1680 # teams within the Southeastern Conference (SEC) for the +1681 # 2020 CFB Season. +1682 print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") +1683 json_data = get_cfbd_player_season_ppa_data( +1684 season=2020, +1685 conference_abv="SEC" +1686 ) +1687 print(json_data) +1688 time.sleep(5) +1689 +1690 # Get player season PPA data from QBs in the 2020 CFB Season. +1691 print("Get player season PPA data from QBs in the 2020 CFB Season.") +1692 json_data = get_cfbd_player_season_ppa_data( +1693 season=2020, +1694 position="QB" +1695 ) +1696 print(json_data) +1697 time.sleep(5) +1698 +1699 # Get player season PPA data from +1700 # former Ohio State and LSU QB Joe Burrow (player ID #3915511). +1701 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") +1702 json_data = get_cfbd_player_season_ppa_data( +1703 player_id=3915511 +1704 ) +1705 print(json_data) +1706 time.sleep(5) +1707 +1708 # Get player season PPA data from +1709 # former Ohio State and LSU QB Joe Burrow (player ID #3915511), +1710 # but exclude plays that occured in garbage time. +1711 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") +1712 json_data = get_cfbd_player_season_ppa_data( +1713 player_id=3915511, +1714 exclude_garbage_time=True +1715 ) +1716 print(json_data) +1717 time.sleep(5) +1718 +1719 # Get player season PPA data from the 2020 CFB Season, +1720 # for players with at least 100 plays/touches. +1721 print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") +1722 json_data = get_cfbd_player_season_ppa_data( +1723 season=2020, +1724 play_threshold=100 +1725 ) +1726 print(json_data) +1727 time.sleep(5) +1728 +1729 # You can also tell this function to just return the API call as +1730 # a Dictionary (read: JSON) object. +1731 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1732 json_data = get_cfbd_player_season_ppa_data( +1733 season=2020, +1734 return_as_dict=True +1735 ) +1736 print(json_data) +1737 +1738 ``` +1739 Returns +1740 ---------- +1741 A pandas `DataFrame` object with player PPA data, +1742 or (if `return_as_dict` is set to `True`) +1743 a dictionary object with player PPA data. +1744 +1745 """ +1746 now = datetime.now() +1747 cfb_games_df = pd.DataFrame() +1748 row_df = pd.DataFrame() +1749 url = "https://api.collegefootballdata.com/ppa/players/season" +1750 +1751 ######################################################################################################################################################################################################## +1752 +1753 if api_key != None: +1754 real_api_key = api_key +1755 del api_key +1756 else: +1757 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1758 +1759 if real_api_key == "tigersAreAwsome": +1760 raise ValueError( +1761 "You actually need to change `cfbd_key` to your CFBD API key.") +1762 elif "Bearer " in real_api_key: +1763 pass +1764 elif "Bearer" in real_api_key: +1765 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1766 else: +1767 real_api_key = "Bearer " + real_api_key +1768 +1769 if season == None: +1770 pass +1771 elif season > now.year: +1772 raise ValueError(f"`season` cannot be greater than {season}.") +1773 elif season < 1869: +1774 raise ValueError(f"`season` cannot be less than 1869.") +1775 +1776 if play_threshold != None and play_threshold < 0: +1777 raise ValueError( +1778 "`play_threshold` must be an integer at or greater than 0." +1779 ) +1780 +1781 gt_str = "" +1782 if exclude_garbage_time == True: +1783 gt_str = "true" +1784 elif exclude_garbage_time == False: +1785 gt_str = "false" +1786 +1787 # URL builder +1788 ######################################################################################################################################################################################################## +1789 url_elements = 0 +1790 +1791 if season != None and url_elements == 0: +1792 url += f"?year={season}" +1793 url_elements += 1 +1794 elif season != None: +1795 url += f"&year={season}" +1796 url_elements += 1 +1797 +1798 if team != None and url_elements == 0: +1799 url += f"?team={team}" +1800 url_elements += 1 +1801 elif team != None: +1802 url += f"&team={team}" +1803 url_elements += 1 +1804 +1805 if conference_abv != None and url_elements == 0: +1806 url += f"?conference={conference_abv}" +1807 url_elements += 1 +1808 elif conference_abv != None: +1809 url += f"&conference={conference_abv}" +1810 url_elements += 1 +1811 +1812 if position != None and url_elements == 0: +1813 url += f"?position={position}" +1814 url_elements += 1 +1815 elif position != None: +1816 url += f"&position={position}" +1817 url_elements += 1 +1818 +1819 if player_id != None and url_elements == 0: +1820 url += f"?playerId={player_id}" +1821 url_elements += 1 +1822 elif player_id != None: +1823 url += f"&playerId={player_id}" +1824 url_elements += 1 +1825 +1826 if play_threshold != None and url_elements == 0: +1827 url += f"?threshold={play_threshold}" +1828 url_elements += 1 +1829 elif play_threshold != None: +1830 url += f"&threshold={play_threshold}" +1831 url_elements += 1 +1832 +1833 if exclude_garbage_time != None and url_elements == 0: +1834 url += f"?excludeGarbageTime={gt_str}" +1835 url_elements += 1 +1836 elif exclude_garbage_time != None: +1837 url += f"&excludeGarbageTime={gt_str}" +1838 url_elements += 1 +1839 +1840 headers = { +1841 'Authorization': f'{real_api_key}', +1842 'accept': 'application/json' +1843 } +1844 response = requests.get(url, headers=headers) +1845 +1846 if response.status_code == 200: +1847 pass +1848 elif response.status_code == 401: +1849 raise ConnectionRefusedError( +1850 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1851 ) +1852 else: +1853 raise ConnectionError( +1854 f'Could not connect.\nHTTP Status code {response.status_code}' +1855 ) +1856 +1857 json_data = response.json() +1858 +1859 if return_as_dict == True: +1860 return json_data +1861 +1862 for player in tqdm(json_data): +1863 p_season = player['season'] +1864 row_df = pd.DataFrame( +1865 {"season": p_season}, +1866 index=[0] +1867 ) +1868 row_df['player_id'] = player['id'] +1869 row_df['player_name'] = player['name'] +1870 row_df['player_position'] = player['position'] +1871 row_df['team'] = player['team'] +1872 row_df['conference'] = player['conference'] +1873 row_df['countable_plays'] = player['countablePlays'] +1874 +1875 # Average PPA +1876 row_df['average_ppa_all'] = player['averagePPA']['all'] +1877 row_df['average_ppa_pass'] = player['averagePPA']['pass'] +1878 row_df['average_ppa_rush'] = player['averagePPA']['rush'] +1879 row_df['average_ppa_first_down'] = player['averagePPA']['firstDown'] +1880 row_df['average_ppa_second_down'] = player['averagePPA']['secondDown'] +1881 row_df['average_ppa_third_down'] = player['averagePPA']['thirdDown'] +1882 row_df['average_ppa_standard_downs'] = player['averagePPA']['standardDowns'] +1883 row_df['average_ppa_passing_downs'] = player['averagePPA']['passingDowns'] +1884 +1885 # Total PPA +1886 row_df['total_ppa_all'] = player['totalPPA']['all'] +1887 row_df['total_ppa_pass'] = player['totalPPA']['pass'] +1888 row_df['total_ppa_rush'] = player['totalPPA']['rush'] +1889 row_df['total_ppa_first_down'] = player['totalPPA']['firstDown'] +1890 row_df['total_ppa_second_down'] = player['totalPPA']['secondDown'] +1891 row_df['total_ppa_third_down'] = player['totalPPA']['thirdDown'] +1892 row_df['total_ppa_standard_downs'] = player['totalPPA']['standardDowns'] +1893 row_df['total_ppa_passing_downs'] = player['totalPPA']['passingDowns'] +1894 +1895 # Have to do this because of a FutureWarning that is raised +1896 # starting in pandas 2.1.1, when using pd.concat(), +1897 # and a column datatype mismatch is found. +1898 row_df = row_df.astype( +1899 { +1900 "average_ppa_all": "float", +1901 "average_ppa_pass": "float", +1902 "average_ppa_rush": "float", +1903 "average_ppa_first_down": "float", +1904 "average_ppa_second_down": "float", +1905 "average_ppa_third_down": "float", +1906 "average_ppa_standard_downs": "float", +1907 "average_ppa_passing_downs": "float", +1908 +1909 "total_ppa_all": "float", +1910 "total_ppa_pass": "float", +1911 "total_ppa_rush": "float", +1912 "total_ppa_first_down": "float", +1913 "total_ppa_second_down": "float", +1914 "total_ppa_third_down": "float", +1915 "total_ppa_standard_downs": "float", +1916 "total_ppa_passing_downs": "float" +1917 } +1918 ) +1919 +1920 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +1921 del row_df +1922 del p_season +1923 +1924 return cfb_games_df +1925 +1926 +1927def get_cfbd_game_win_probability_data( +1928 game_id: int, +1929 api_key: str = None, +1930 api_key_dir: str = None, +1931 return_as_dict: bool = False): +1932 """ +1933 Allows one to get win probabliity data for a given game ID. +1934 +1935 Parameters +1936 ---------- +1937 +1938 `game_id` (int, mandatory): +1939 Mandatory argument. +1940 This is the game ID for the game you want win probability data from, +1941 at the play-by-play level. +1942 +1943 `api_key` (str, optional): +1944 Semi-optional argument. +1945 If `api_key` is null, this function will attempt to load a CFBD API key +1946 from the python environment, or from a file on this computer. +1947 If `api_key` is not null, this function will automatically assume that the +1948 inputted `api_key` is a valid CFBD API key. +1949 +1950 `api_key_dir` (str, optional): +1951 Optional argument. +1952 If `api_key` is set to am empty string, this variable is ignored. +1953 If `api_key_dir` is null, and `api_key` is null, +1954 this function will try to find a CFBD API key file in this user's home directory. +1955 If `api_key_dir` is set to a string, and `api_key` is null, +1956 this function will assume that `api_key_dir` is a directory, +1957 and will try to find a CFBD API key file in that directory. +1958 +1959 `return_as_dict` (bool, semi-optional): +1960 Semi-optional argument. +1961 If you want this function to return the data as a dictionary (read: JSON object), +1962 instead of a pandas `DataFrame` object, +1963 set `return_as_dict` to `True`. +1964 +1965 Usage +1966 ---------- +1967 ``` +1968 import time +1969 +1970 from cfbd_json_py.metrics import get_cfbd_game_win_probability_data +1971 +1972 +1973 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1974 +1975 if cfbd_key != "tigersAreAwsome": +1976 print("Using the user's API key declared in this script for this example.") +1977 +1978 # Get the win probablility data for a 2017 game between +1979 # the University of Cincinnati and UConn (game ID #400941851). +1980 print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") +1981 json_data = get_cfbd_game_win_probability_data( +1982 api_key=cfbd_key, +1983 game_id=400941851 +1984 ) +1985 print(json_data) +1986 time.sleep(5) +1987 +1988 # Get the win probablility data for a 2023 game between +1989 # the University of Duke and the University of Louisville (game ID #401525535). +1990 print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") +1991 json_data = get_cfbd_game_win_probability_data( +1992 api_key=cfbd_key, +1993 game_id=401525535 +1994 ) +1995 print(json_data) +1996 time.sleep(5) +1997 +1998 +1999 # You can also tell this function to just return the API call as +2000 # a Dictionary (read: JSON) object. +2001 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2002 json_data = get_cfbd_game_win_probability_data( +2003 api_key=cfbd_key, +2004 game_id=400941851, +2005 return_as_dict=True +2006 ) +2007 print(json_data) +2008 +2009 else: +2010 # Alternatively, if the CFBD API key exists in this python environment, +2011 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +2012 # you could just call these functions directly, without setting the API key +2013 # in the script. +2014 print("Using the user's API key suposedly loaded into this python environment for this example.") +2015 +2016 # Get win probablility data for a 2017 game between +2017 # the University of Cincinnati and UConn (game ID #400941851). +2018 print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") +2019 json_data = get_cfbd_game_win_probability_data( +2020 game_id=400941851 +2021 ) +2022 print(json_data) +2023 time.sleep(5) +2024 +2025 # Get win probablility data for a 2023 game between +2026 # the University of Duke and the University of Louisville (game ID #401525535). +2027 print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") +2028 json_data = get_cfbd_game_win_probability_data( +2029 game_id=401525535 +2030 ) +2031 print(json_data) +2032 time.sleep(5) +2033 +2034 +2035 # You can also tell this function to just return the API call as +2036 # a Dictionary (read: JSON) object. +2037 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2038 json_data = get_cfbd_game_win_probability_data( +2039 game_id=400941851, +2040 return_as_dict=True +2041 ) +2042 print(json_data) +2043 +2044 ``` +2045 Returns +2046 ---------- +2047 A pandas `DataFrame` object with win probability data at the play-by-play level, +2048 or (if `return_as_dict` is set to `True`) +2049 a dictionary object with win probability data at the play-by-play level. +2050 +2051 """ +2052 +2053 wp_df = pd.DataFrame() +2054 row_df = pd.DataFrame() +2055 url = "https://api.collegefootballdata.com/metrics/wp" +2056 +2057 ######################################################################################################################################################################################################## +2058 +2059 if api_key != None: +2060 real_api_key = api_key +2061 del api_key +2062 else: +2063 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +2064 +2065 if real_api_key == "tigersAreAwsome": +2066 raise ValueError( +2067 "You actually need to change `cfbd_key` to your CFBD API key.") +2068 elif "Bearer " in real_api_key: +2069 pass +2070 elif "Bearer" in real_api_key: +2071 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +2072 else: +2073 real_api_key = "Bearer " + real_api_key +2074 # URL builder +2075 ######################################################################################################################################################################################################## +2076 +2077 # Required by API +2078 url += f"?gameId={game_id}" +2079 +2080 headers = { +2081 'Authorization': f'{real_api_key}', +2082 'accept': 'application/json' +2083 } +2084 +2085 response = requests.get(url, headers=headers) +2086 +2087 if response.status_code == 200: +2088 pass +2089 elif response.status_code == 401: +2090 raise ConnectionRefusedError( +2091 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +2092 ) +2093 else: +2094 raise ConnectionError( +2095 f'Could not connect.\nHTTP Status code {response.status_code}' +2096 ) +2097 +2098 json_data = response.json() +2099 +2100 if return_as_dict == True: +2101 return json_data +2102 +2103 for play in tqdm(json_data): +2104 row_df = pd.DataFrame( +2105 {"game_id": game_id}, +2106 index=[0] +2107 ) +2108 row_df['play_id'] = play['playId'] +2109 row_df['play_text'] = play['playText'] +2110 row_df['home_id'] = play['homeId'] +2111 row_df['home_team_name'] = play['home'] +2112 row_df['away_id'] = play['awayId'] +2113 row_df['away_team_name'] = play['away'] +2114 row_df['spread'] = play['spread'] +2115 row_df['home_team_has_ball'] = play['homeBall'] +2116 row_df['home_score'] = play['homeScore'] +2117 row_df['away_score'] = play['awayScore'] +2118 row_df['down'] = play['down'] +2119 row_df['distance'] = play['distance'] +2120 row_df['home_win_probability'] = play['homeWinProb'] +2121 row_df['play_number'] = play['playNumber'] +2122 +2123 wp_df = pd.concat([wp_df, row_df], ignore_index=True) +2124 +2125 if len(wp_df) == 0: +2126 logging.error( +2127 "The CFBD API accepted your inputs, " + +2128 "but found no data within your specified input paramaters." + +2129 " Please double check your input paramaters." +2130 ) +2131 else: +2132 wp_df = wp_df.astype( +2133 {"home_win_probability": "float"} +2134 ) +2135 wp_df['away_win_probability'] = 1 - wp_df['home_win_probability'] +2136 +2137 return wp_df +2138 +2139 +2140def get_cfbd_pregame_win_probability_data( +2141 season: int, +2142 api_key: str = None, +2143 api_key_dir: str = None, +2144 week: int = None, +2145 team: str = None, +2146 season_type: str = "regular", # "regular" or "postseason" +2147 return_as_dict: bool = False): +2148 """ +2149 Allows you to get pregame win probability data for games within a timeframe. +2150 +2151 Parameters +2152 ---------- +2153 `api_key` (str, optional): +2154 Semi-optional argument. +2155 If `api_key` is null, this function will attempt to load a CFBD API key +2156 from the python environment, or from a file on this computer. +2157 If `api_key` is not null, this function will automatically assume that the +2158 inputted `api_key` is a valid CFBD API key. +2159 +2160 `api_key_dir` (str, optional): +2161 Optional argument. +2162 If `api_key` is set to am empty string, this variable is ignored. +2163 If `api_key_dir` is null, and `api_key` is null, +2164 this function will try to find a CFBD API key file in this user's home directory. +2165 If `api_key_dir` is set to a string, and `api_key` is null, +2166 this function will assume that `api_key_dir` is a directory, +2167 and will try to find a CFBD API key file in that directory. +2168 +2169 `season` (int, optional): +2170 Semi-optional argument. +2171 Specifies the season you want pregame win probability data. +2172 +2173 `week` (int, optional): +2174 Optional argument. +2175 If `week` is set to an integer, this function will attempt +2176 to load CFB game data from games in that season, and in that week. +2177 +2178 `team` (str, optional): +2179 Semi-ptional argument. +2180 If you only want pregame win probability data for a specific team, +2181 set `team` to the name of the team you want pregame win probability data from. +2182 +2183 `season_type` (str, semi-optional): +2184 Semi-optional argument. +2185 By defualt, this will be set to "regular", for the CFB regular season. +2186 If you want CFB game information for non-regular season games, +2187 set `season_type` to "postseason". +2188 If `season_type` is set to anything but "regular" or "postseason", +2189 a `ValueError()` will be raised. +2190 +2191 `return_as_dict` (bool, semi-optional): +2192 Semi-optional argument. +2193 If you want this function to return the data as a dictionary (read: JSON object), +2194 instead of a pandas `DataFrame` object, +2195 set `return_as_dict` to `True`. +2196 +2197 Usage +2198 ---------- +2199 ``` +2200 import time +2201 +2202 from cfbd_json_py.metrics import get_cfbd_pregame_win_probability_data +2203 +2204 +2205 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +2206 +2207 if cfbd_key != "tigersAreAwsome": +2208 print("Using the user's API key declared in this script for this example.") +2209 +2210 # Get pregame win probabilities for games in the 2023 CFB season. +2211 print("Get pregame win probabilities for games in the 2023 CFB season.") +2212 json_data = get_cfbd_pregame_win_probability_data( +2213 api_key=cfbd_key, +2214 season=2023 +2215 ) +2216 print(json_data) +2217 time.sleep(5) +2218 +2219 +2220 # Get pregame win probabilities for games in week 10 of the 2021 CFB season. +2221 print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") +2222 json_data = get_cfbd_pregame_win_probability_data( +2223 api_key=cfbd_key, +2224 season=2021, +2225 week=10 +2226 ) +2227 print(json_data) +2228 time.sleep(5) +2229 +2230 +2231 # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. +2232 print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") +2233 json_data = get_cfbd_pregame_win_probability_data( +2234 api_key=cfbd_key, +2235 season=2021, +2236 week=10 +2237 ) +2238 print(json_data) +2239 time.sleep(5) +2240 +2241 +2242 # Get pregame win probabilities for postseason games in the 2020 CFB season. +2243 print("Get pregame win probabilities for postseason games in the 2020 CFB season.") +2244 json_data = get_cfbd_pregame_win_probability_data( +2245 api_key=cfbd_key, +2246 season=2020, +2247 season_type="postseason" +2248 ) +2249 print(json_data) +2250 time.sleep(5) +2251 +2252 +2253 # You can also tell this function to just return the API call as +2254 # a Dictionary (read: JSON) object. +2255 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2256 json_data = get_cfbd_pregame_win_probability_data( +2257 api_key=cfbd_key, +2258 season=2023, +2259 week=10, +2260 return_as_dict=True +2261 ) +2262 print(json_data) +2263 +2264 else: +2265 # Alternatively, if the CFBD API key exists in this python environment, +2266 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +2267 # you could just call these functions directly, without setting the API key +2268 # in the script. +2269 print("Using the user's API key suposedly loaded into this python environment for this example.") +2270 +2271 # Get pregame win probabilities for games in the 2023 CFB season. +2272 print("Get pregame win probabilities for games in the 2023 CFB season.") +2273 json_data = get_cfbd_pregame_win_probability_data( +2274 season=2023 +2275 ) +2276 print(json_data) +2277 time.sleep(5) +2278 +2279 +2280 # Get pregame win probabilities for games in week 10 of the 2021 CFB season. +2281 print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") +2282 json_data = get_cfbd_pregame_win_probability_data( +2283 season=2021, +2284 week=10 +2285 ) +2286 print(json_data) +2287 time.sleep(5) +2288 +2289 +2290 # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. +2291 print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") +2292 json_data = get_cfbd_pregame_win_probability_data( +2293 season=2021, +2294 week=10 +2295 ) +2296 print(json_data) +2297 time.sleep(5) +2298 +2299 +2300 # Get pregame win probabilities for postseason games in the 2020 CFB season. +2301 print("Get pregame win probabilities for postseason games in the 2020 CFB season.") +2302 json_data = get_cfbd_pregame_win_probability_data( +2303 season=2020, +2304 season_type="postseason" +2305 ) +2306 print(json_data) +2307 time.sleep(5) +2308 +2309 +2310 # You can also tell this function to just return the API call as +2311 # a Dictionary (read: JSON) object. +2312 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2313 json_data = get_cfbd_pregame_win_probability_data( +2314 season=2023, +2315 week=10, +2316 return_as_dict=True +2317 ) +2318 print(json_data) +2319 +2320 ``` +2321 Returns +2322 ---------- +2323 A pandas `DataFrame` object with pregame win probability data, +2324 or (if `return_as_dict` is set to `True`) +2325 a dictionary object with a pregame win probability data. +2326 +2327 """ +2328 now = datetime.now() +2329 wp_df = pd.DataFrame() +2330 row_df = pd.DataFrame() +2331 url = "https://api.collegefootballdata.com/metrics/wp/pregame" +2332 +2333 ######################################################################################################################################################################################################## +2334 +2335 if api_key != None: +2336 real_api_key = api_key +2337 del api_key +2338 else: +2339 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +2340 +2341 if real_api_key == "tigersAreAwsome": +2342 raise ValueError( +2343 "You actually need to change `cfbd_key` to your CFBD API key.") +2344 elif "Bearer " in real_api_key: +2345 pass +2346 elif "Bearer" in real_api_key: +2347 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +2348 else: +2349 real_api_key = "Bearer " + real_api_key +2350 +2351 if season == None: +2352 pass +2353 elif season > now.year: +2354 raise ValueError(f"`season` cannot be greater than {season}.") +2355 elif season < 1869: +2356 raise ValueError(f"`season` cannot be less than 1869.") +2357 +2358 if week != None and week < 0: +2359 raise ValueError( +2360 "`week` must be an integer greater than 0." +2361 ) +2362 +2363 if season_type != "regular" and season_type != "postseason": +2364 raise ValueError( +2365 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +2366 +2367 +2368 +2369 # URL builder +2370 ######################################################################################################################################################################################################## +2371 url_elements = 0 +2372 +2373 if season != None and url_elements == 0: +2374 url += f"?year={season}" +2375 url_elements += 1 +2376 elif season != None: +2377 url += f"&year={season}" +2378 url_elements += 1 +2379 +2380 if week != None and url_elements == 0: +2381 url += f"?week={week}" +2382 url_elements += 1 +2383 elif week != None: +2384 url += f"&week={week}" +2385 url_elements += 1 +2386 +2387 if team != None and url_elements == 0: +2388 url += f"?team={team}" +2389 url_elements += 1 +2390 elif team != None: +2391 url += f"&team={team}" +2392 url_elements += 1 +2393 +2394 if season_type != None and url_elements == 0: +2395 url += f"?seasonType={season_type}" +2396 url_elements += 1 +2397 elif season_type != None: +2398 url += f"&seasonType={season_type}" +2399 url_elements += 1 +2400 +2401 +2402 headers = { +2403 'Authorization': f'{real_api_key}', +2404 'accept': 'application/json' +2405 } +2406 +2407 response = requests.get(url, headers=headers) +2408 +2409 if response.status_code == 200: +2410 pass +2411 elif response.status_code == 401: +2412 raise ConnectionRefusedError( +2413 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +2414 ) +2415 else: +2416 raise ConnectionError( +2417 f'Could not connect.\nHTTP Status code {response.status_code}' +2418 ) +2419 +2420 json_data = response.json() +2421 +2422 if return_as_dict == True: +2423 return json_data +2424 +2425 for game in tqdm(json_data): +2426 g_season = game['season'] +2427 row_df = pd.DataFrame( +2428 {"season":g_season}, +2429 index=[0] +2430 ) +2431 row_df['week'] = game['week'] +2432 row_df['season_type'] = game['seasonType'] +2433 row_df['game_id'] = game['gameId'] +2434 row_df['home_team_name'] = game['homeTeam'] +2435 row_df['away_team_name'] = game['awayTeam'] +2436 row_df['spread'] = game['spread'] +2437 row_df['home_win_probability'] = game['homeWinProb'] +2438 +2439 wp_df = pd.concat([wp_df,row_df],ignore_index=True) +2440 del row_df +2441 del g_season +2442 +2443 if len(wp_df) == 0: +2444 logging.error( +2445 "The CFBD API accepted your inputs, " + +2446 "but found no data within your specified input paramaters." + +2447 " Please double check your input paramaters." +2448 ) +2449 else: +2450 wp_df = wp_df.astype( +2451 {"home_win_probability": "float"} +2452 ) +2453 wp_df['away_win_probability'] = 1 - wp_df['home_win_probability'] +2454 +2455 return wp_df
def - get_cfbd_predicted_ppa_from_down_distance( down: int, distance: int, api_key: str = None, api_key_dir: str = None): + get_cfbd_predicted_ppa_from_down_distance( down: int, distance: int, api_key: str = None, api_key_dir: str = None, return_as_dict: bool = False):-9def get_cfbd_predicted_ppa_from_down_distance( -10 down: int, -11 distance: int, -12 api_key: str = None, -13 api_key_dir: str = None): -14 """ -15 """ -16 -17 raise NotImplementedError( -18 'This function has yet to be implemented by this version.' -19 ) +- +18def get_cfbd_predicted_ppa_from_down_distance( + 19 down: int, + 20 distance: int, + 21 api_key: str = None, + 22 api_key_dir: str = None, + 23 return_as_dict: bool = False): + 24 """ + 25 Given a down and distance, + 26 this function will attempt to get the predicted + 27 PPA value for that down and distance, + 28 at every yard line possible for that down and distance. + 29 + 30 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). + 31 + 32 For this endpoint, + 33 [`yardLine`] is the number of yards from 1 (offense has the ball on their side, + 34 at their 1 yard line), to 99 + 35 (offense with the ball with a X and goal situation on the opponent's 1 yard line. + 36 + 37 Parameters + 38 ---------- + 39 `down` (int, mandatory): + 40 Mandatory argument. + 41 This is the down (a number between 1 and 4 in normal situations) + 42 for this play you want PPA for. + 43 + 44 `distance` (int, mandatory): + 45 Mandatory argument. + 46 This variable should be set to the number of yards between + 47 the line of scrimage (LOS), and the first down line on the field. + 48 + 49 `api_key` (str, optional): + 50 Semi-optional argument. + 51 If `api_key` is null, this function will attempt to load a CFBD API key + 52 from the python environment, or from a file on this computer. + 53 If `api_key` is not null, this function will automatically assume that the + 54 inputted `api_key` is a valid CFBD API key. + 55 + 56 `api_key_dir` (str, optional): + 57 Optional argument. + 58 If `api_key` is set to am empty string, this variable is ignored. + 59 If `api_key_dir` is null, and `api_key` is null, + 60 this function will try to find a CFBD API key file in this user's home directory. + 61 If `api_key_dir` is set to a string, and `api_key` is null, + 62 this function will assume that `api_key_dir` is a directory, + 63 and will try to find a CFBD API key file in that directory. + 64 + 65 `return_as_dict` (bool, semi-optional): + 66 Semi-optional argument. + 67 If you want this function to return the data as a dictionary (read: JSON object), + 68 instead of a pandas `DataFrame` object, + 69 set `return_as_dict` to `True`. + 70 + 71 Usage + 72 ---------- + 73 ``` + 74 import time + 75 + 76 from cfbd_json_py.metrics import get_cfbd_predicted_ppa_from_down_distance + 77 + 78 + 79 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + 80 + 81 if cfbd_key != "tigersAreAwsome": + 82 print("Using the user's API key declared in this script for this example.") + 83 + 84 # Get the predicted PPA for a 1st and 10 play, + 85 # in every possible situation. + 86 print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + 87 json_data = get_cfbd_predicted_ppa_from_down_distance( + 88 down=1, + 89 distance=10, + 90 api_key=cfbd_key + 91 ) + 92 print(json_data) + 93 time.sleep(5) + 94 + 95 + 96 # You can also tell this function to just return the API call as + 97 # a Dictionary (read: JSON) object. + 98 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + 99 json_data = get_cfbd_predicted_ppa_from_down_distance( +100 down=1, +101 distance=10, +102 api_key=cfbd_key, +103 return_as_dict=True +104 ) +105 print(json_data) +106 +107 else: +108 # Alternatively, if the CFBD API key exists in this python environment, +109 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +110 # you could just call these functions directly, without setting the API key +111 # in the script. +112 print("Using the user's API key suposedly loaded into this python environment for this example.") +113 +114 +115 # Get the predicted PPA for a 1st and 10 play, +116 # in every possible situation. +117 print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") +118 json_data = get_cfbd_predicted_ppa_from_down_distance( +119 down=1, +120 distance=10 +121 ) +122 print(json_data) +123 time.sleep(5) +124 +125 +126 # You can also tell this function to just return the API call as +127 # a Dictionary (read: JSON) object. +128 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +129 json_data = get_cfbd_predicted_ppa_from_down_distance( +130 down=1, +131 distance=10, +132 return_as_dict=True +133 ) +134 print(json_data) +135 +136 ``` +137 Returns +138 ---------- +139 A pandas `DataFrame` object with a calculated PPA from a dwon and distance, +140 or (if `return_as_dict` is set to `True`) +141 a dictionary object with a calculated PPA from a dwon and distance. +142 +143 +144 """ +145 +146 # now = datetime.now() +147 ppa_df = pd.DataFrame() +148 row_df = pd.DataFrame() +149 url = "https://api.collegefootballdata.com/ppa/predicted" +150 +151 ######################################################################################################################################################################################################## +152 +153 if api_key != None: +154 real_api_key = api_key +155 del api_key +156 else: +157 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +158 +159 if real_api_key == "tigersAreAwsome": +160 raise ValueError( +161 "You actually need to change `cfbd_key` to your CFBD API key.") +162 elif "Bearer " in real_api_key: +163 pass +164 elif "Bearer" in real_api_key: +165 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +166 else: +167 real_api_key = "Bearer " + real_api_key +168 +169 if down >= 1 and down <= 4: +170 # This is normal, so pass. +171 pass +172 elif down == 5: +173 # Due to a Missouri-Colorado game in the 90s +174 # being won by Colorado on a mythical "5th down", +175 # we cannot reject this down outright, +176 # but we have to convey to the person calling this +177 # function that setting `down = 5` +178 # is not something they should be doing. +179 logging.warn( +180 "There is a very limited number of \"5th down\" situations " + +181 "in American Football history. " + +182 "Do not expect anything back when calling this function, " + +183 "and setting`down` to `5`." +184 ) +185 else: +186 raise ValueError( +187 "Invalid `down` inputted! Valid inputs are:\n" + +188 "\n\t- `1`" + +189 "\n\t- `2`" + +190 "\n\t- `3`" + +191 "\n\t- `4`" + +192 f"\nYou entered: \t`{down}`" +193 +194 +195 ) +196 +197 if distance == 0: +198 raise ValueError( +199 "If you want \"X and inches\" predicted PPA data, " + +200 "set `down` to `1` when calling this function." +201 ) +202 elif distance >= 100 and distance <= 110: +203 raise ValueError( +204 "The CFBD API cannot calculate predicted PPA for " + +205 "U-Sports (Canada) football." +206 ) +207 elif distance >= 1 and distance <= 99: +208 # While numbers beyond 30 are rare, +209 # there are some situations IRL that caused the distance +210 # in "down and distance" to exceed 90 +211 # (most famously a 2017 game between +212 # Mississippi State and Louisiana Tech). +213 pass +214 +215 # URL builder +216 ######################################################################################################################################################################################################## +217 +218 # Required by API +219 url += f"?down={down}&distance={distance}" +220 +221 headers = { +222 'Authorization': f'{real_api_key}', +223 'accept': 'application/json' +224 } +225 +226 response = requests.get(url, headers=headers) +227 +228 if response.status_code == 200: +229 pass +230 elif response.status_code == 401: +231 raise ConnectionRefusedError( +232 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +233 ) +234 else: +235 raise ConnectionError( +236 f'Could not connect.\nHTTP Status code {response.status_code}' +237 ) +238 +239 json_data = response.json() +240 +241 if return_as_dict == True: +242 return json_data +243 +244 for dnd in json_data: +245 row_df = pd.DataFrame( +246 { +247 "down": down, +248 "distance": distance, +249 +250 }, +251 index=[0] +252 ) +253 row_df['predicted_points'] = dnd['predictedPoints'] +254 row_df['yard_line'] = dnd['yardLine'] +255 ppa_df = pd.concat([ppa_df, row_df], ignore_index=True) +256 +257 return ppa_df+ -Given a down and distance, +this function will attempt to get the predicted +PPA value for that down and distance, +at every yard line possible for that down and distance.
+ +PPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
+ +For this endpoint, +[
+ +yardLine
] is the number of yards from 1 (offense has the ball on their side, +at their 1 yard line), to 99 +(offense with the ball with a X and goal situation on the opponent's 1 yard line.Parameters
+ ++ +
down
(int, mandatory): + Mandatory argument. + This is the down (a number between 1 and 4 in normal situations) + for this play you want PPA for.+ +
distance
(int, mandatory): + Mandatory argument. + This variable should be set to the number of yards between + the line of scrimage (LOS), and the first down line on the field.+ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_predicted_ppa_from_down_distance + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get the predicted PPA for a 1st and 10 play, + # in every possible situation. + print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10, + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10, + api_key=cfbd_key, + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + + # Get the predicted PPA for a 1st and 10 play, + # in every possible situation. + print("Get the predicted PPA for a 1st and 10 play, in every possible situation.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10 + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_predicted_ppa_from_down_distance( + down=1, + distance=10, + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with a calculated PPA from a dwon and distance, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with a calculated PPA from a dwon and distance.- + + def - get_cfbd_team_ppa_data( api_key: str = None, api_key_dir: str = None, season: int = None, team: str = None, conference_abv: str = None, exclude_garbage_time: bool = False, return_as_dict: bool = False): + get_cfbd_team_season_ppa_data( api_key: str = None, api_key_dir: str = None, season: int = None, team: str = None, conference_abv: str = None, exclude_garbage_time: bool = False, return_as_dict: bool = False): - +- -22def get_cfbd_team_ppa_data( -23 api_key: str = None, -24 api_key_dir: str = None, -25 season: int = None, -26 team: str = None, -27 # `year` and/or `team` must be not null for this function to work. -28 conference_abv: str = None, -29 exclude_garbage_time: bool = False, -30 -31 return_as_dict: bool = False): -32 """ -33 -34 """ -35 -36 raise NotImplementedError( -37 'This function has yet to be implemented by this version.' -38 ) + +- +260def get_cfbd_team_season_ppa_data( +261 api_key: str = None, +262 api_key_dir: str = None, +263 season: int = None, +264 team: str = None, +265 # `year` and/or `team` must be not null for this function to work. +266 conference_abv: str = None, +267 exclude_garbage_time: bool = False, +268 return_as_dict: bool = False): +269 """ +270 Allows you to get team PPA data, +271 over an entire season, +272 with or without garbage time plays, +273 for a specificed team and/or time period. +274 +275 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). +276 +277 Parameters +278 ---------- +279 `api_key` (str, optional): +280 Semi-optional argument. +281 If `api_key` is null, this function will attempt to load a CFBD API key +282 from the python environment, or from a file on this computer. +283 If `api_key` is not null, this function will automatically assume that the +284 inputted `api_key` is a valid CFBD API key. +285 +286 `api_key_dir` (str, optional): +287 Optional argument. +288 If `api_key` is set to am empty string, this variable is ignored. +289 If `api_key_dir` is null, and `api_key` is null, +290 this function will try to find a CFBD API key file in this user's home directory. +291 If `api_key_dir` is set to a string, and `api_key` is null, +292 this function will assume that `api_key_dir` is a directory, +293 and will try to find a CFBD API key file in that directory. +294 +295 `season` (int, optional): +296 Semi-optional argument. +297 Specifies the season you want team PPA data from. +298 You MUST set `season` or `team` to a non-null value for +299 this function to work. If you don't, a `ValueError()` +300 will be raised. +301 +302 `team` (str, optional): +303 Semi-ptional argument. +304 If you only want team PPA data for a specific team, +305 set `team` to the name of the team you want team PPA data from. +306 You MUST set `season` or `team` to a non-null value for +307 this function to work. If you don't, a `ValueError()` +308 will be raised. +309 +310 `conference_abv` (str, optional): +311 Optional argument. +312 If you only want team PPA data from games +313 involving teams from a specific confrence, +314 set `conference_abv` to the abbreviation +315 of the conference you want team PPA data from. +316 For a list of confrences, +317 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +318 function. +319 +320 `exclude_garbage_time` (bool, optional): +321 Optional argument. +322 If you want to filter out plays where the result of the game is largely decided, +323 set `exclude_garbage_time = True`. +324 Default behavior is that this variable is set to +325 `False` when this function is called. +326 +327 `return_as_dict` (bool, semi-optional): +328 Semi-optional argument. +329 If you want this function to return the data as a dictionary (read: JSON object), +330 instead of a pandas `DataFrame` object, +331 set `return_as_dict` to `True`. +332 +333 Usage +334 ---------- +335 ``` +336 import time +337 +338 from cfbd_json_py.metrics import get_cfbd_team_ppa_data +339 +340 +341 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +342 +343 if cfbd_key != "tigersAreAwsome": +344 print("Using the user's API key declared in this script for this example.") +345 +346 # Get team season PPA data for the 2020 CFB season. +347 print("Get team PPA data for the 2020 CFB season.") +348 json_data = get_cfbd_team_ppa_data( +349 api_key=cfbd_key, +350 season=2020 +351 ) +352 print(json_data) +353 time.sleep(5) +354 +355 # Get team season PPA data for the 2020 Ohio State Buckeyes. +356 print("Get team season PPA data for the 2020 Ohio State Buckeyes.") +357 json_data = get_cfbd_team_ppa_data( +358 api_key=cfbd_key, +359 season=2020, +360 team="Ohio State" +361 ) +362 print(json_data) +363 time.sleep(5) +364 +365 # Get team season PPA data for the 2020 Ohio State Buckeyes, +366 # but exclude garbage time plays when making the PPA calculations. +367 print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") +368 json_data = get_cfbd_team_ppa_data( +369 api_key=cfbd_key, +370 season=2020, +371 team="Ohio State", +372 exclude_garbage_time=True +373 ) +374 print(json_data) +375 time.sleep(5) +376 +377 # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. +378 print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") +379 json_data = get_cfbd_team_ppa_data( +380 api_key=cfbd_key, +381 season=2020, +382 conference_abv="B1G" +383 ) +384 print(json_data) +385 time.sleep(5) +386 +387 # You can also tell this function to just return the API call as +388 # a Dictionary (read: JSON) object. +389 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +390 json_data = get_cfbd_team_ppa_data( +391 api_key=cfbd_key, +392 season=2020, +393 conference_abv="B1G", +394 return_as_dict=True +395 ) +396 print(json_data) +397 +398 else: +399 # Alternatively, if the CFBD API key exists in this python environment, +400 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +401 # you could just call these functions directly, without setting the API key +402 # in the script. +403 print("Using the user's API key suposedly loaded into this python environment for this example.") +404 +405 # Get team season PPA data for the 2020 CFB season. +406 print("Get team PPA data for the 2020 CFB season.") +407 json_data = get_cfbd_team_ppa_data( +408 season=2020 +409 ) +410 print(json_data) +411 time.sleep(5) +412 +413 # Get team season PPA data for the 2020 Ohio State Buckeyes. +414 print("Get team season PPA data for the 2020 Ohio State Buckeyes.") +415 json_data = get_cfbd_team_ppa_data( +416 season=2020, +417 team="Ohio State" +418 ) +419 print(json_data) +420 time.sleep(5) +421 +422 # Get team season PPA data for the 2020 Ohio State Buckeyes, +423 # but exclude garbage time plays when making the PPA calculations. +424 print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") +425 json_data = get_cfbd_team_ppa_data( +426 season=2020, +427 team="Ohio State", +428 exclude_garbage_time=True +429 ) +430 print(json_data) +431 time.sleep(5) +432 +433 # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. +434 print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") +435 json_data = get_cfbd_team_ppa_data( +436 season=2020, +437 conference_abv="B1G" +438 ) +439 print(json_data) +440 time.sleep(5) +441 +442 # You can also tell this function to just return the API call as +443 # a Dictionary (read: JSON) object. +444 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +445 json_data = get_cfbd_team_ppa_data( +446 season=2020, +447 conference_abv="B1G", +448 return_as_dict=True +449 ) +450 print(json_data) +451 +452 ``` +453 Returns +454 ---------- +455 A pandas `DataFrame` object with team season PPA data, +456 or (if `return_as_dict` is set to `True`) +457 a dictionary object with a team season PPA data. +458 +459 """ +460 +461 now = datetime.now() +462 ppa_df = pd.DataFrame() +463 row_df = pd.DataFrame() +464 url = "https://api.collegefootballdata.com/ppa/teams" +465 +466 ######################################################################################################################################################################################################## +467 +468 if api_key != None: +469 real_api_key = api_key +470 del api_key +471 else: +472 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +473 +474 if real_api_key == "tigersAreAwsome": +475 raise ValueError( +476 "You actually need to change `cfbd_key` to your CFBD API key.") +477 elif "Bearer " in real_api_key: +478 pass +479 elif "Bearer" in real_api_key: +480 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +481 else: +482 real_api_key = "Bearer " + real_api_key +483 +484 if season == None and team == None: +485 raise ValueError( +486 "To use this function, `season` and/or `team` must be set to a " + +487 "non-null variable." +488 ) +489 +490 if season == None: +491 # Rare, but in this endpoint, +492 # you don't need to input the season. +493 pass +494 elif season > now.year: +495 raise ValueError(f"`season` cannot be greater than {season}.") +496 elif season < 1869: +497 raise ValueError(f"`season` cannot be less than 1869.") +498 +499 gt_str = "" +500 if exclude_garbage_time == True: +501 gt_str = "true" +502 elif exclude_garbage_time == False: +503 gt_str = "false" +504 +505 # URL builder +506 ######################################################################################################################################################################################################## +507 url_elements = 0 +508 +509 if season != None and url_elements == 0: +510 url += f"?year={season}" +511 url_elements += 1 +512 elif season != None: +513 url += f"&year={season}" +514 url_elements += 1 +515 +516 if team != None and url_elements == 0: +517 url += f"?team={team}" +518 url_elements += 1 +519 elif team != None: +520 url += f"&team={team}" +521 url_elements += 1 +522 +523 if conference_abv != None and url_elements == 0: +524 url += f"?conference={conference_abv}" +525 url_elements += 1 +526 elif conference_abv != None: +527 url += f"&conference={conference_abv}" +528 url_elements += 1 +529 +530 if exclude_garbage_time != None and url_elements == 0: +531 url += f"?excludeGarbageTime={gt_str}" +532 url_elements += 1 +533 elif exclude_garbage_time != None: +534 url += f"&excludeGarbageTime={gt_str}" +535 url_elements += 1 +536 +537 headers = { +538 'Authorization': f'{real_api_key}', +539 'accept': 'application/json' +540 } +541 +542 response = requests.get(url, headers=headers) +543 +544 if response.status_code == 200: +545 pass +546 elif response.status_code == 401: +547 raise ConnectionRefusedError( +548 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +549 ) +550 else: +551 raise ConnectionError( +552 f'Could not connect.\nHTTP Status code {response.status_code}' +553 ) +554 +555 json_data = response.json() +556 +557 if return_as_dict == True: +558 return json_data +559 +560 for team in tqdm(json_data): +561 t_season = team['season'] +562 t_conference = team['conference'] +563 t_name = team['team'] +564 +565 row_df = pd.DataFrame( +566 { +567 "season": t_season, +568 "team_name": t_name, +569 "team_conference": t_conference +570 }, +571 index=[0] +572 ) +573 +574 # Team offense +575 row_df['offensive_ppa_overall'] = team['offense']['overall'] +576 row_df['offensive_ppa_passing'] = team['offense']['passing'] +577 row_df['offensive_ppa_rushing'] = team['offense']['rushing'] +578 row_df['offensive_ppa_first_down'] = team['offense']['firstDown'] +579 row_df['offensive_ppa_second_down'] = team['offense']['secondDown'] +580 row_df['offensive_ppa_third_down'] = team['offense']['thirdDown'] +581 row_df['offensive_ppa_cumulative'] = team['offense']['cumulative']['total'] +582 row_df['offensive_ppa_cumulative_passing'] = team['offense']['cumulative']['passing'] +583 row_df['offensive_ppa_cumulative_rushing'] = team['offense']['cumulative']['rushing'] +584 +585 # Team defense +586 row_df['defensive_ppa_overall'] = team['defense']['overall'] +587 row_df['defensive_ppa_passing'] = team['defense']['passing'] +588 row_df['defensive_ppa_rushing'] = team['defense']['rushing'] +589 row_df['defensive_ppa_first_down'] = team['defense']['firstDown'] +590 row_df['defensive_ppa_second_down'] = team['defense']['secondDown'] +591 row_df['defensive_ppa_third_down'] = team['defense']['thirdDown'] +592 row_df['defensive_ppa_cumulative'] = team['defense']['cumulative']['total'] +593 row_df['defensive_ppa_cumulative_passing'] = team['defense']['cumulative']['passing'] +594 row_df['defensive_ppa_cumulative_rushing'] = team['defense']['cumulative']['rushing'] +595 +596 ppa_df = pd.concat([ppa_df, row_df], ignore_index=True) +597 +598 del t_season, t_conference, t_name +599 del row_df +600 +601 return ppa_df+ -Allows you to get team PPA data, +over an entire season, +with or without garbage time plays, +for a specificed team and/or time period.
+ +PPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
+ +Parameters
+ ++ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
season
(int, optional): + Semi-optional argument. + Specifies the season you want team PPA data from. + You MUST setseason
orteam
to a non-null value for + this function to work. If you don't, aValueError()
+ will be raised.+ +
team
(str, optional): + Semi-ptional argument. + If you only want team PPA data for a specific team, + setteam
to the name of the team you want team PPA data from. + You MUST setseason
orteam
to a non-null value for + this function to work. If you don't, aValueError()
+ will be raised.+ +
conference_abv
(str, optional): + Optional argument. + If you only want team PPA data from games + involving teams from a specific confrence, + setconference_abv
to the abbreviation + of the conference you want team PPA data from. + For a list of confrences, + use thecfbd_json_py.conferences.get_cfbd_conference_info()
+ function.+ +
exclude_garbage_time
(bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + setexclude_garbage_time = True
. + Default behavior is that this variable is set to +False
when this function is called.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_team_ppa_data + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get team season PPA data for the 2020 CFB season. + print("Get team PPA data for the 2020 CFB season.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes. + print("Get team season PPA data for the 2020 Ohio State Buckeyes.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + team="Ohio State" + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes, + # but exclude garbage time plays when making the PPA calculations. + print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + team="Ohio State", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. + print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="B1G" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="B1G", + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get team season PPA data for the 2020 CFB season. + print("Get team PPA data for the 2020 CFB season.") + json_data = get_cfbd_team_ppa_data( + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes. + print("Get team season PPA data for the 2020 Ohio State Buckeyes.") + json_data = get_cfbd_team_ppa_data( + season=2020, + team="Ohio State" + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for the 2020 Ohio State Buckeyes, + # but exclude garbage time plays when making the PPA calculations. + print("Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.") + json_data = get_cfbd_team_ppa_data( + season=2020, + team="Ohio State", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season. + print("Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.") + json_data = get_cfbd_team_ppa_data( + season=2020, + conference_abv="B1G" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_ppa_data( + season=2020, + conference_abv="B1G", + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with team season PPA data, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with a team season PPA data.- + + def - get_cfbd_game_ppa_data( season: int, api_key: str = None, api_key_dir: str = None, week: int = None, team: str = None, conference_abv: str = None, exclude_garbage_time: bool = False, season_type: str = 'regular', return_as_dict: bool = False): + get_cfbd_team_game_ppa_data( season: int, api_key: str = None, api_key_dir: str = None, week: int = None, team: str = None, conference_abv: str = None, exclude_garbage_time: bool = False, season_type: str = 'regular', return_as_dict: bool = False): - +- --41def get_cfbd_game_ppa_data( -42 season: int, -43 api_key: str = None, -44 api_key_dir: str = None, -45 week: int = None, -46 team: str = None, -47 conference_abv: str = None, -48 exclude_garbage_time: bool = False, -49 season_type: str = "regular", # "regular" or "postseason" -50 -51 return_as_dict: bool = False): -52 """ -53 -54 """ -55 -56 raise NotImplementedError( -57 'This function has yet to be implemented by this version.' -58 ) + +- +604def get_cfbd_team_game_ppa_data( +605 season: int, +606 api_key: str = None, +607 api_key_dir: str = None, +608 week: int = None, +609 team: str = None, +610 conference_abv: str = None, +611 exclude_garbage_time: bool = False, +612 season_type: str = "regular", # "regular" or "postseason" +613 return_as_dict: bool = False): +614 """ +615 Allows you to get team PPA data, +616 at a game level, +617 with or without garbage time plays, +618 for a specificed team and/or time period. +619 +620 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). +621 +622 Parameters +623 ---------- +624 `season` (int, mandatory): +625 Required argument. +626 Specifies the season you want team game PPA data information from. +627 This must be specified, otherwise this package, and by extension +628 the CFBD API, will not accept the request to get team game PPA data information. +629 +630 `api_key` (str, optional): +631 Semi-optional argument. +632 If `api_key` is null, this function will attempt to load a CFBD API key +633 from the python environment, or from a file on this computer. +634 If `api_key` is not null, this function will automatically assume that the +635 inputted `api_key` is a valid CFBD API key. +636 +637 `api_key_dir` (str, optional): +638 Optional argument. +639 If `api_key` is set to am empty string, this variable is ignored. +640 If `api_key_dir` is null, and `api_key` is null, +641 this function will try to find a CFBD API key file in this user's home directory. +642 If `api_key_dir` is set to a string, and `api_key` is null, +643 this function will assume that `api_key_dir` is a directory, +644 and will try to find a CFBD API key file in that directory. +645 +646 `week` (int, optional): +647 Optional argument. +648 If `week` is set to an integer, this function will attempt +649 to load team game PPA data from games in that season, and in that week. +650 +651 `team` (str, optional): +652 Optional argument. +653 If you only want team game PPA data for a team, +654 regardless if they are the home/away team, +655 set `team` to the name of the team you want team game PPA data from. +656 +657 `conference_abv` (str, optional): +658 Optional argument. +659 If you only want team game PPA data from games +660 involving teams a specific confrence, +661 set `conference_abv` to the abbreviation +662 of the conference you want team game PPA data from. +663 +664 `exclude_garbage_time` (bool, optional): +665 Optional argument. +666 If you want to filter out plays where the result of the game is largely decided, +667 set `exclude_garbage_time = True`. +668 Default behavior is that this variable is set to +669 `False` when this function is called. +670 +671 `season_type` (str, semi-optional): +672 Semi-optional argument. +673 By defualt, this will be set to "regular", for the CFB regular season. +674 If you want team game PPA data for non-regular season games, +675 set `season_type` to "postseason". +676 If `season_type` is set to anything but "regular" or "postseason", +677 a `ValueError()` will be raised. +678 +679 `return_as_dict` (bool, semi-optional): +680 Semi-optional argument. +681 If you want this function to return the data as a dictionary (read: JSON object), +682 instead of a pandas `DataFrame` object, +683 set `return_as_dict` to `True`. +684 +685 Usage +686 ---------- +687 ``` +688 import time +689 +690 from cfbd_json_py.metrics import get_cfbd_team_game_ppa_data +691 +692 +693 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +694 +695 if cfbd_key != "tigersAreAwsome": +696 print("Using the user's API key declared in this script for this example.") +697 +698 # Get team PPA data for individual games within the 2020 CFB season. +699 print("Get team PPA data for individual games within the 2020 CFB season.") +700 json_data = get_cfbd_team_game_ppa_data( +701 api_key=cfbd_key, +702 season=2020 +703 ) +704 print(json_data) +705 time.sleep(5) +706 +707 # Get team PPA data for week 10 games within the 2020 CFB season. +708 print("Get team PPA data for week 10 games within the 2020 CFB season.") +709 json_data = get_cfbd_team_game_ppa_data( +710 api_key=cfbd_key, +711 season=2020, +712 week=10 +713 ) +714 print(json_data) +715 time.sleep(5) +716 +717 # Get team PPA data for +718 # University of Cincinnati football games within the 2020 CFB season. +719 print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") +720 json_data = get_cfbd_team_game_ppa_data( +721 api_key=cfbd_key, +722 season=2020, +723 team="Cincinnati" +724 ) +725 print(json_data) +726 time.sleep(5) +727 +728 # Get team PPA data for Southeastern Conference (SEC) +729 # games within the 2020 CFB season. +730 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") +731 json_data = get_cfbd_team_game_ppa_data( +732 api_key=cfbd_key, +733 season=2020, +734 conference_abv="SEC" +735 ) +736 print(json_data) +737 time.sleep(5) +738 +739 # Get team PPA data for Southeastern Conference (SEC) +740 # games within the 2020 CFB season, but exclude plays that occur in garbage time. +741 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") +742 json_data = get_cfbd_team_game_ppa_data( +743 api_key=cfbd_key, +744 season=2020, +745 conference_abv="SEC", +746 exclude_garbage_time=True +747 ) +748 print(json_data) +749 time.sleep(5) +750 +751 # Get team PPA data for postseason games in the 2020 CFB season. +752 print("Get team PPA data for postseason games in the 2020 CFB season.") +753 json_data = get_cfbd_team_game_ppa_data( +754 api_key=cfbd_key, +755 season=2020, +756 season_type="postseason" +757 ) +758 print(json_data) +759 time.sleep(5) +760 +761 # You can also tell this function to just return the API call as +762 # a Dictionary (read: JSON) object. +763 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +764 json_data = get_cfbd_team_game_ppa_data( +765 api_key=cfbd_key, +766 season=2020, +767 team="Cincinnati", +768 return_as_dict=True +769 ) +770 print(json_data) +771 +772 else: +773 # Alternatively, if the CFBD API key exists in this python environment, +774 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +775 # you could just call these functions directly, without setting the API key +776 # in the script. +777 print("Using the user's API key suposedly loaded into this python environment for this example.") +778 +779 # Get team PPA data for individual games within the 2020 CFB season. +780 print("Get team PPA data for individual games within the 2020 CFB season.") +781 json_data = get_cfbd_team_game_ppa_data( +782 season=2020 +783 ) +784 print(json_data) +785 time.sleep(5) +786 +787 # Get team PPA data for week 10 games within the 2020 CFB season. +788 print("Get team PPA data for week 10 games within the 2020 CFB season.") +789 json_data = get_cfbd_team_game_ppa_data( +790 season=2020, +791 week=10 +792 ) +793 print(json_data) +794 time.sleep(5) +795 +796 # Get team PPA data for +797 # University of Cincinnati football games within the 2020 CFB season. +798 print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") +799 json_data = get_cfbd_team_game_ppa_data( +800 season=2020, +801 team="Cincinnati" +802 ) +803 print(json_data) +804 time.sleep(5) +805 +806 # Get team PPA data for Southeastern Conference (SEC) +807 # games within the 2020 CFB season. +808 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") +809 json_data = get_cfbd_team_game_ppa_data( +810 season=2020, +811 conference_abv="SEC" +812 ) +813 print(json_data) +814 time.sleep(5) +815 +816 # Get team PPA data for Southeastern Conference (SEC) +817 # games within the 2020 CFB season, but exclude plays that occur in garbage time. +818 print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") +819 json_data = get_cfbd_team_game_ppa_data( +820 season=2020, +821 conference_abv="SEC", +822 exclude_garbage_time=True +823 ) +824 print(json_data) +825 time.sleep(5) +826 +827 # Get team PPA data for postseason games in the 2020 CFB season. +828 print("Get team PPA data for postseason games in the 2020 CFB season.") +829 json_data = get_cfbd_team_game_ppa_data( +830 season=2020, +831 season_type="postseason" +832 ) +833 print(json_data) +834 time.sleep(5) +835 +836 # You can also tell this function to just return the API call as +837 # a Dictionary (read: JSON) object. +838 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +839 json_data = get_cfbd_team_game_ppa_data( +840 season=2020, +841 team="Cincinnati", +842 return_as_dict=True +843 ) +844 print(json_data) +845 +846 ``` +847 Returns +848 ---------- +849 A pandas `DataFrame` object with team PPA data, +850 or (if `return_as_dict` is set to `True`) +851 a dictionary object with team PPA data. +852 +853 """ +854 +855 now = datetime.now() +856 cfb_games_df = pd.DataFrame() +857 row_df = pd.DataFrame() +858 url = "https://api.collegefootballdata.com/ppa/games" +859 +860 ######################################################################################################################################################################################################## +861 +862 if api_key != None: +863 real_api_key = api_key +864 del api_key +865 else: +866 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +867 +868 if real_api_key == "tigersAreAwsome": +869 raise ValueError( +870 "You actually need to change `cfbd_key` to your CFBD API key.") +871 elif "Bearer " in real_api_key: +872 pass +873 elif "Bearer" in real_api_key: +874 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +875 else: +876 real_api_key = "Bearer " + real_api_key +877 +878 if season == None: +879 # This should never happen without user tampering, but if it does, +880 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +881 raise SystemError( +882 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +883 " and the function got to this point in the code." + +884 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +885 "https://github.com/armstjc/cfbd-json-py/issues" +886 ) +887 elif season > now.year: +888 raise ValueError(f"`season` cannot be greater than {season}.") +889 elif season < 1869: +890 raise ValueError(f"`season` cannot be less than 1869.") +891 +892 if season_type != "regular" and season_type != "postseason": +893 raise ValueError( +894 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +895 +896 if week != None and week < 0: +897 raise ValueError( +898 "`week` must be a positive number." +899 ) +900 +901 if season_type != "regular" and season_type != "postseason": +902 raise ValueError( +903 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +904 +905 gt_str = "" +906 if exclude_garbage_time == True: +907 gt_str = "true" +908 elif exclude_garbage_time == False: +909 gt_str = "false" +910 +911 # URL builder +912 ######################################################################################################################################################################################################## +913 +914 # Required by API +915 url += f"?seasonType={season_type}" +916 url += f"&year={season}" +917 +918 if week != None: +919 url += f"&week={week}" +920 +921 if team != None: +922 url += f"&team={team}" +923 +924 if conference_abv != None: +925 url += f"&conference={conference_abv}" +926 +927 if exclude_garbage_time != None: +928 url += f"&excludeGarbageTime={gt_str}" +929 +930 headers = { +931 'Authorization': f'{real_api_key}', +932 'accept': 'application/json' +933 } +934 response = requests.get(url, headers=headers) +935 +936 if response.status_code == 200: +937 pass +938 elif response.status_code == 401: +939 raise ConnectionRefusedError( +940 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +941 ) +942 else: +943 raise ConnectionError( +944 f'Could not connect.\nHTTP Status code {response.status_code}' +945 ) +946 +947 json_data = response.json() +948 +949 if return_as_dict == True: +950 return json_data +951 +952 for game in tqdm(json_data): +953 g_season = game['season'] +954 g_gid = game['gameId'] +955 g_week = game['week'] +956 g_tm = game['team'] +957 g_conf = game['conference'] +958 g_opp = game['opponent'] +959 +960 row_df = pd.DataFrame( +961 { +962 "season": g_season, +963 "game_id": g_gid, +964 "week": g_week, +965 "team": g_tm, +966 "conference": g_conf, +967 "opponent": g_opp +968 }, +969 index=[0] +970 ) +971 +972 # Team Offense +973 row_df['ppa_offense_overall'] = game['offense']['overall'] +974 row_df['ppa_offense_passing'] = game['offense']['passing'] +975 row_df['ppa_offense_rushing'] = game['offense']['rushing'] +976 row_df['ppa_offense_first_down'] = game['offense']['firstDown'] +977 row_df['ppa_offense_second_down'] = game['offense']['secondDown'] +978 row_df['ppa_offense_third_down'] = game['offense']['thirdDown'] +979 +980 # Team Defense +981 row_df['ppa_defense_overall'] = game['defense']['overall'] +982 row_df['ppa_defense_passing'] = game['defense']['passing'] +983 row_df['ppa_defense_rushing'] = game['defense']['rushing'] +984 row_df['ppa_defense_first_down'] = game['defense']['firstDown'] +985 row_df['ppa_defense_second_down'] = game['defense']['secondDown'] +986 row_df['ppa_defense_third_down'] = game['defense']['thirdDown'] +987 +988 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +989 +990 del row_df +991 del g_gid, g_season, g_week,\ +992 g_conf, g_tm, g_opp +993 +994 return cfb_games_df+ -Allows you to get team PPA data, +at a game level, +with or without garbage time plays, +for a specificed team and/or time period.
+ +PPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
+ +Parameters
+ ++ +
season
(int, mandatory): + Required argument. + Specifies the season you want team game PPA data information from. + This must be specified, otherwise this package, and by extension + the CFBD API, will not accept the request to get team game PPA data information.+ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
week
(int, optional): + Optional argument. + Ifweek
is set to an integer, this function will attempt + to load team game PPA data from games in that season, and in that week.+ +
team
(str, optional): + Optional argument. + If you only want team game PPA data for a team, + regardless if they are the home/away team, + setteam
to the name of the team you want team game PPA data from.+ +
conference_abv
(str, optional): + Optional argument. + If you only want team game PPA data from games + involving teams a specific confrence, + setconference_abv
to the abbreviation + of the conference you want team game PPA data from.+ +
exclude_garbage_time
(bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + setexclude_garbage_time = True
. + Default behavior is that this variable is set to +False
when this function is called.+ +
season_type
(str, semi-optional): + Semi-optional argument. + By defualt, this will be set to "regular", for the CFB regular season. + If you want team game PPA data for non-regular season games, + setseason_type
to "postseason". + Ifseason_type
is set to anything but "regular" or "postseason", + aValueError()
will be raised.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_team_game_ppa_data + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get team PPA data for individual games within the 2020 CFB season. + print("Get team PPA data for individual games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for week 10 games within the 2020 CFB season. + print("Get team PPA data for week 10 games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for + # University of Cincinnati football games within the 2020 CFB season. + print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season, but exclude plays that occur in garbage time. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="SEC", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for postseason games in the 2020 CFB season. + print("Get team PPA data for postseason games in the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Cincinnati", + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get team PPA data for individual games within the 2020 CFB season. + print("Get team PPA data for individual games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for week 10 games within the 2020 CFB season. + print("Get team PPA data for week 10 games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for + # University of Cincinnati football games within the 2020 CFB season. + print("Get team PPA data for University of Cincinnati football games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for Southeastern Conference (SEC) + # games within the 2020 CFB season, but exclude plays that occur in garbage time. + print("Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + conference_abv="SEC", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get team PPA data for postseason games in the 2020 CFB season. + print("Get team PPA data for postseason games in the 2020 CFB season.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_team_game_ppa_data( + season=2020, + team="Cincinnati", + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with team PPA data, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with team PPA data.- + + def - get_cfbd_game_player_ppa_data( season: int, api_key: str = None, api_key_dir: str = None, week: int = None, team: str = None, position: str = None, player_id: int = None, play_threshold: int = None, exclude_garbage_time: bool = False, season_type: str = 'regular', return_as_dict: bool = False): + get_cfbd_player_game_ppa_data( api_key: str = None, api_key_dir: str = None, season: int = None, week: int = None, team: str = None, position: str = None, player_id: int = None, play_threshold: int = None, exclude_garbage_time: bool = False, season_type: str = 'regular', return_as_dict: bool = False): - +- -@@ -204,22 +202,22 @@61def get_cfbd_game_player_ppa_data( -62 season: int, -63 api_key: str = None, -64 api_key_dir: str = None, -65 week: int = None, -66 team: str = None, -67 # A week or team must be specified -68 position: str = None, -69 player_id: int = None, -70 play_threshold: int = None, -71 exclude_garbage_time: bool = False, -72 season_type: str = "regular", # "regular" or "postseason" -73 -74 return_as_dict: bool = False): -75 """ -76 -77 """ -78 -79 raise NotImplementedError( -80 'This function has yet to be implemented by this version.' -81 ) + +- +997def get_cfbd_player_game_ppa_data( + 998 api_key: str = None, + 999 api_key_dir: str = None, +1000 season: int = None, +1001 week: int = None, +1002 team: str = None, +1003 # A week or team must be specified +1004 position: str = None, +1005 player_id: int = None, +1006 play_threshold: int = None, +1007 exclude_garbage_time: bool = False, +1008 season_type: str = "regular", # "regular" or "postseason" +1009 return_as_dict: bool = False): +1010 """ +1011 Allows you to get player PPA data, +1012 at a game level, +1013 with or without garbage time plays, +1014 for a specificed time period and/or team. +1015 +1016 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). +1017 +1018 Parameters +1019 ---------- +1020 +1021 `api_key` (str, optional): +1022 Semi-optional argument. +1023 If `api_key` is null, this function will attempt to load a CFBD API key +1024 from the python environment, or from a file on this computer. +1025 If `api_key` is not null, this function will automatically assume that the +1026 inputted `api_key` is a valid CFBD API key. +1027 +1028 `api_key_dir` (str, optional): +1029 Optional argument. +1030 If `api_key` is set to am empty string, this variable is ignored. +1031 If `api_key_dir` is null, and `api_key` is null, +1032 this function will try to find a CFBD API key file in this user's home directory. +1033 If `api_key_dir` is set to a string, and `api_key` is null, +1034 this function will assume that `api_key_dir` is a directory, +1035 and will try to find a CFBD API key file in that directory. +1036 +1037 `season` (int, semi-optional): +1038 Semi-Optional argument. +1039 Specifies the season you want player game PPA data information from. +1040 This must be specified, otherwise this package, and by extension +1041 the CFBD API, will not accept the request to get player game PPA data information. +1042 +1043 `week` (int, semi-optional): +1044 Semi-Optional argument. +1045 If `week` is set to an integer, this function will attempt +1046 to load player game PPA data from games in that season, and in that week. +1047 `week` and/or `team` must be set to a non-null value for this function +1048 to work. +1049 +1050 `team` (str, semi-optional): +1051 Semi-Optional argument. +1052 If you only want player game PPA data for players of a specific team, +1053 regardless if they are the home/away team, +1054 set `team` to the name of the team you want player game PPA data from. +1055 `week` and/or `team` must be set to a non-null value for this function +1056 to work. +1057 +1058 `position` (str, optional): +1059 Optional argument. +1060 If you only want player game PPA data for players of a specific position, +1061 set `position` to the position you want player game PPA data from. +1062 +1063 `player_id` (int, optional): +1064 Optional argument. +1065 If you only want PPA data for a specific player ID, +1066 set this variable to the player ID of the player you want PPA data from. +1067 +1068 `play_threshold` +1069 Optional argument. +1070 If you only want PPA data for players +1071 who touched the ball for *X* number of plays in a game, +1072 set `play_threshold = x`, where `x` is +1073 your specified minimum number of plays. +1074 +1075 `exclude_garbage_time` (bool, optional): +1076 Optional argument. +1077 If you want to filter out plays where the result of the game is largely decided, +1078 set `exclude_garbage_time = True`. +1079 Default behavior is that this variable is set to +1080 `False` when this function is called. +1081 +1082 `season_type` (str, semi-optional): +1083 Semi-optional argument. +1084 By defualt, this will be set to "regular", for the CFB regular season. +1085 If you want player game PPA data for non-regular season games, +1086 set `season_type` to "postseason". +1087 If `season_type` is set to anything but "regular" or "postseason", +1088 a `ValueError()` will be raised. +1089 +1090 `return_as_dict` (bool, semi-optional): +1091 Semi-optional argument. +1092 If you want this function to return the data as a dictionary (read: JSON object), +1093 instead of a pandas `DataFrame` object, +1094 set `return_as_dict` to `True`. +1095 +1096 Usage +1097 ---------- +1098 ``` +1099 import time +1100 +1101 from cfbd_json_py.metrics import get_cfbd_player_game_ppa_data +1102 +1103 +1104 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1105 +1106 if cfbd_key != "tigersAreAwsome": +1107 print("Using the user's API key declared in this script for this example.") +1108 +1109 # Get player game PPA data for week 10 of the 2020 CFB season. +1110 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1111 json_data = get_cfbd_player_game_ppa_data( +1112 api_key=cfbd_key, +1113 season=2020, +1114 week=10 +1115 ) +1116 print(json_data) +1117 time.sleep(5) +1118 +1119 # Get player game PPA data for players of the +1120 # 2020 University of Cincinnati Football team. +1121 print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") +1122 json_data = get_cfbd_player_game_ppa_data( +1123 api_key=cfbd_key, +1124 season=2020, +1125 team="Cincinnati" +1126 ) +1127 print(json_data) +1128 time.sleep(5) +1129 +1130 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. +1131 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1132 json_data = get_cfbd_player_game_ppa_data( +1133 api_key=cfbd_key, +1134 season=2020, +1135 week=10, +1136 position="QB" +1137 ) +1138 print(json_data) +1139 time.sleep(5) +1140 +1141 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, +1142 # but exclude plays in garbage time. +1143 print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") +1144 json_data = get_cfbd_player_game_ppa_data( +1145 api_key=cfbd_key, +1146 season=2020, +1147 week=10, +1148 position="QB", +1149 exclude_garbage_time=True +1150 ) +1151 print(json_data) +1152 time.sleep(5) +1153 +1154 # Get player game PPA data for week 10 of the 2020 CFB season, +1155 # where a player touched the ball for at least 25 plays. +1156 print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") +1157 json_data = get_cfbd_player_game_ppa_data( +1158 api_key=cfbd_key, +1159 season=2020, +1160 week=10, +1161 play_threshold=25 +1162 ) +1163 print(json_data) +1164 time.sleep(5) +1165 +1166 # Get player game PPA data the 2020 Alabama Crimson Tide Football team, +1167 # during their postseason. +1168 print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") +1169 json_data = get_cfbd_player_game_ppa_data( +1170 api_key=cfbd_key, +1171 season=2020, +1172 team="Alabama", +1173 season_type="postseason" +1174 ) +1175 print(json_data) +1176 time.sleep(5) +1177 +1178 # You can also tell this function to just return the API call as +1179 # a Dictionary (read: JSON) object. +1180 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1181 json_data = get_cfbd_player_game_ppa_data( +1182 api_key=cfbd_key, +1183 season=2020, +1184 week=10, +1185 return_as_dict=True +1186 ) +1187 print(json_data) +1188 +1189 else: +1190 # Alternatively, if the CFBD API key exists in this python environment, +1191 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1192 # you could just call these functions directly, without setting the API key +1193 # in the script. +1194 print("Using the user's API key suposedly loaded into this python environment for this example.") +1195 +1196 # Get player game PPA data for week 10 of the 2020 CFB season. +1197 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1198 json_data = get_cfbd_player_game_ppa_data( +1199 season=2020, +1200 week=10 +1201 ) +1202 print(json_data) +1203 time.sleep(5) +1204 +1205 # Get player game PPA data for players of the +1206 # 2020 University of Cincinnati Football team. +1207 print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") +1208 json_data = get_cfbd_player_game_ppa_data( +1209 season=2020, +1210 team="Cincinnati" +1211 ) +1212 print(json_data) +1213 time.sleep(5) +1214 +1215 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. +1216 print("Get player game PPA data for week 10 of the 2020 CFB season.") +1217 json_data = get_cfbd_player_game_ppa_data( +1218 season=2020, +1219 week=10, +1220 position="QB" +1221 ) +1222 print(json_data) +1223 time.sleep(5) +1224 +1225 # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, +1226 # but exclude plays in garbage time. +1227 print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") +1228 json_data = get_cfbd_player_game_ppa_data( +1229 season=2020, +1230 week=10, +1231 position="QB", +1232 exclude_garbage_time=True +1233 ) +1234 print(json_data) +1235 time.sleep(5) +1236 +1237 # Get player game PPA data for week 10 of the 2020 CFB season, +1238 # where a player touched the ball for at least 25 plays. +1239 print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") +1240 json_data = get_cfbd_player_game_ppa_data( +1241 season=2020, +1242 week=10, +1243 play_threshold=25 +1244 ) +1245 print(json_data) +1246 time.sleep(5) +1247 +1248 # Get player game PPA data the 2020 Alabama Crimson Tide Football team, +1249 # during their postseason. +1250 print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") +1251 json_data = get_cfbd_player_game_ppa_data( +1252 season=2020, +1253 team="Alabama", +1254 season_type="postseason" +1255 ) +1256 print(json_data) +1257 time.sleep(5) +1258 +1259 # You can also tell this function to just return the API call as +1260 # a Dictionary (read: JSON) object. +1261 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1262 json_data = get_cfbd_player_game_ppa_data( +1263 season=2020, +1264 week=10, +1265 return_as_dict=True +1266 ) +1267 print(json_data) +1268 +1269 ``` +1270 Returns +1271 ---------- +1272 A pandas `DataFrame` object with player PPA data, +1273 or (if `return_as_dict` is set to `True`) +1274 a dictionary object with player PPA data. +1275 +1276 """ +1277 +1278 now = datetime.now() +1279 cfb_games_df = pd.DataFrame() +1280 row_df = pd.DataFrame() +1281 url = "https://api.collegefootballdata.com/ppa/players/games" +1282 +1283 ######################################################################################################################################################################################################## +1284 +1285 if api_key != None: +1286 real_api_key = api_key +1287 del api_key +1288 else: +1289 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1290 +1291 if real_api_key == "tigersAreAwsome": +1292 raise ValueError( +1293 "You actually need to change `cfbd_key` to your CFBD API key.") +1294 elif "Bearer " in real_api_key: +1295 pass +1296 elif "Bearer" in real_api_key: +1297 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1298 else: +1299 real_api_key = "Bearer " + real_api_key +1300 +1301 if season == None: +1302 # This should never happen without user tampering, but if it does, +1303 # we need to raise an error, because the CFBD API will refuse this call without a valid season. +1304 raise SystemError( +1305 "I don't know how, I don't know why, but you managed to call this function while `season` was `None` (NULL)," + +1306 " and the function got to this point in the code." + +1307 "\nIf you have a GitHub account, please raise an issue on this python package's GitHub page:\n" + +1308 "https://github.com/armstjc/cfbd-json-py/issues" +1309 ) +1310 elif season > now.year: +1311 raise ValueError(f"`season` cannot be greater than {season}.") +1312 elif season < 1869: +1313 raise ValueError(f"`season` cannot be less than 1869.") +1314 +1315 if week == None and team == None: +1316 raise ValueError( +1317 "To call this function, you must set `week` and/or `team` " + +1318 "to a non-null value." +1319 ) +1320 +1321 if season_type != "regular" and season_type != "postseason": +1322 raise ValueError( +1323 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +1324 +1325 if week != None and week < 0: +1326 raise ValueError( +1327 "`week` must be a positive number." +1328 ) +1329 +1330 if season_type != "regular" and season_type != "postseason": +1331 raise ValueError( +1332 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +1333 +1334 if play_threshold != None and play_threshold < 0: +1335 raise ValueError( +1336 "`play_threshold` must be an integer at or greater than 0." +1337 ) +1338 +1339 gt_str = "" +1340 if exclude_garbage_time == True: +1341 gt_str = "true" +1342 elif exclude_garbage_time == False: +1343 gt_str = "false" +1344 +1345 # URL builder +1346 ######################################################################################################################################################################################################## +1347 url_elements = 0 +1348 +1349 if season != None and url_elements == 0: +1350 url += f"?year={season}" +1351 url_elements += 1 +1352 elif season != None: +1353 url += f"&year={season}" +1354 url_elements += 1 +1355 +1356 if week != None and url_elements == 0: +1357 url += f"?week={week}" +1358 url_elements += 1 +1359 elif week != None: +1360 url += f"&week={week}" +1361 url_elements += 1 +1362 +1363 if team != None and url_elements == 0: +1364 url += f"?team={team}" +1365 url_elements += 1 +1366 elif team != None: +1367 url += f"&team={team}" +1368 url_elements += 1 +1369 +1370 if position != None and url_elements == 0: +1371 url += f"?position={position}" +1372 url_elements += 1 +1373 elif position != None: +1374 url += f"&position={position}" +1375 url_elements += 1 +1376 +1377 if player_id != None and url_elements == 0: +1378 url += f"?playerId={player_id}" +1379 url_elements += 1 +1380 elif player_id != None: +1381 url += f"&playerId={player_id}" +1382 url_elements += 1 +1383 +1384 if play_threshold != None and url_elements == 0: +1385 url += f"?threshold={play_threshold}" +1386 url_elements += 1 +1387 elif play_threshold != None: +1388 url += f"&threshold={play_threshold}" +1389 url_elements += 1 +1390 +1391 if exclude_garbage_time != None and url_elements == 0: +1392 url += f"?excludeGarbageTime={gt_str}" +1393 url_elements += 1 +1394 elif exclude_garbage_time != None: +1395 url += f"&excludeGarbageTime={gt_str}" +1396 url_elements += 1 +1397 +1398 if season_type != None and url_elements == 0: +1399 url += f"?seasonType={season_type}" +1400 url_elements += 1 +1401 elif season_type != None: +1402 url += f"&seasonType={season_type}" +1403 url_elements += 1 +1404 +1405 headers = { +1406 'Authorization': f'{real_api_key}', +1407 'accept': 'application/json' +1408 } +1409 response = requests.get(url, headers=headers) +1410 +1411 if response.status_code == 200: +1412 pass +1413 elif response.status_code == 401: +1414 raise ConnectionRefusedError( +1415 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1416 ) +1417 else: +1418 raise ConnectionError( +1419 f'Could not connect.\nHTTP Status code {response.status_code}' +1420 ) +1421 +1422 json_data = response.json() +1423 +1424 if return_as_dict == True: +1425 return json_data +1426 +1427 for player in tqdm(json_data): +1428 p_season = player['season'] +1429 row_df = pd.DataFrame( +1430 { +1431 "season": p_season +1432 }, +1433 index=[0] +1434 ) +1435 +1436 row_df['week'] = player['week'] +1437 row_df['player_name'] = player['name'] +1438 row_df['player_position'] = player['position'] +1439 row_df['team'] = player['team'] +1440 row_df['opponent'] = player['opponent'] +1441 +1442 row_df['avg_ppa_all'] = player['averagePPA']['all'] +1443 row_df['avg_ppa_pass'] = player['averagePPA']['pass'] +1444 row_df['avg_ppa_rush'] = player['averagePPA']['rush'] +1445 +1446 # Have to do this because of a FutureWarning that is raised +1447 # starting in pandas 2.1.1, when using pd.concat(), +1448 # and a column datatype mismatch is found. +1449 row_df = row_df.astype( +1450 { +1451 "avg_ppa_all": "float", +1452 "avg_ppa_pass": "float", +1453 "avg_ppa_rush": "float", +1454 } +1455 ) +1456 +1457 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +1458 +1459 del row_df +1460 del p_season +1461 +1462 return cfb_games_df+ -Allows you to get player PPA data, +at a game level, +with or without garbage time plays, +for a specificed time period and/or team.
+ +PPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
+ +Parameters
+ ++ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
season
(int, semi-optional): + Semi-Optional argument. + Specifies the season you want player game PPA data information from. + This must be specified, otherwise this package, and by extension + the CFBD API, will not accept the request to get player game PPA data information.+ +
week
(int, semi-optional): + Semi-Optional argument. + Ifweek
is set to an integer, this function will attempt + to load player game PPA data from games in that season, and in that week. +week
and/orteam
must be set to a non-null value for this function + to work.+ +
team
(str, semi-optional): + Semi-Optional argument. + If you only want player game PPA data for players of a specific team, + regardless if they are the home/away team, + setteam
to the name of the team you want player game PPA data from. +week
and/orteam
must be set to a non-null value for this function + to work.+ +
position
(str, optional): + Optional argument. + If you only want player game PPA data for players of a specific position, + setposition
to the position you want player game PPA data from.+ +
player_id
(int, optional): + Optional argument. + If you only want PPA data for a specific player ID, + set this variable to the player ID of the player you want PPA data from.+ +
play_threshold
+ Optional argument. + If you only want PPA data for players + who touched the ball for X number of plays in a game, + setplay_threshold = x
, wherex
is + your specified minimum number of plays.+ +
exclude_garbage_time
(bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + setexclude_garbage_time = True
. + Default behavior is that this variable is set to +False
when this function is called.+ +
season_type
(str, semi-optional): + Semi-optional argument. + By defualt, this will be set to "regular", for the CFB regular season. + If you want player game PPA data for non-regular season games, + setseason_type
to "postseason". + Ifseason_type
is set to anything but "regular" or "postseason", + aValueError()
will be raised.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_player_game_ppa_data + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get player game PPA data for week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for players of the + # 2020 University of Cincinnati Football team. + print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, + # but exclude plays in garbage time. + print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + position="QB", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for week 10 of the 2020 CFB season, + # where a player touched the ball for at least 25 plays. + print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + play_threshold=25 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data the 2020 Alabama Crimson Tide Football team, + # during their postseason. + print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + team="Alabama", + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_game_ppa_data( + api_key=cfbd_key, + season=2020, + week=10, + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get player game PPA data for week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for players of the + # 2020 University of Cincinnati Football team. + print("Get player game PPA data for players of the 2020 University of Cincinnati Football team.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + team="Cincinnati" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season. + print("Get player game PPA data for week 10 of the 2020 CFB season.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, + # but exclude plays in garbage time. + print("Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + position="QB", + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data for week 10 of the 2020 CFB season, + # where a player touched the ball for at least 25 plays. + print("Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + play_threshold=25 + ) + print(json_data) + time.sleep(5) + + # Get player game PPA data the 2020 Alabama Crimson Tide Football team, + # during their postseason. + print("Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + team="Alabama", + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_game_ppa_data( + season=2020, + week=10, + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with player PPA data, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with player PPA data.- + 14 position: str = None, 15 team: str = None, 16 season: int = None, -17 -18 return_as_dict: bool = False): -19 """ -20 -21 """ -22 raise NotImplementedError( -23 'This function has yet to be implemented by this version.' -24 ) +17 return_as_dict: bool = False): +18 """ +19 +20 """ +21 raise NotImplementedError( +22 'This function has yet to be implemented by this version.' +23 )+ def - get_cfbd_season_player_ppa_data( season: int, api_key: str = None, api_key_dir: str = None, team: str = None, conference_abv: str = None, position: str = None, player_id: int = None, play_threshold: int = None, exclude_garbage_time: bool = False, return_as_dict: bool = False): + get_cfbd_player_season_ppa_data( api_key: str = None, api_key_dir: str = None, season: int = None, team: str = None, conference_abv: str = None, position: str = None, player_id: int = None, play_threshold: int = None, exclude_garbage_time: bool = False, return_as_dict: bool = False): - +- --84def get_cfbd_season_player_ppa_data( - 85 season: int, - 86 api_key: str = None, - 87 api_key_dir: str = None, - 88 team: str = None, - 89 conference_abv: str = None, - 90 position: str = None, - 91 player_id: int = None, - 92 play_threshold: int = None, - 93 exclude_garbage_time: bool = False, - 94 - 95 return_as_dict: bool = False): - 96 """ - 97 - 98 """ - 99 raise NotImplementedError( -100 'This function has yet to be implemented by this version.' -101 ) + +- +1465def get_cfbd_player_season_ppa_data( +1466 api_key: str = None, +1467 api_key_dir: str = None, +1468 season: int = None, +1469 team: str = None, +1470 conference_abv: str = None, +1471 position: str = None, +1472 player_id: int = None, +1473 play_threshold: int = None, +1474 exclude_garbage_time: bool = False, +1475 return_as_dict: bool = False): +1476 """ +1477 Allows you to get player PPA data, +1478 at a season level, +1479 with or without garbage time plays, +1480 for a specificed time period and/or team. +1481 +1482 PPA is the CFBD API's equivalent metric to Expected Points Added (EPA). +1483 +1484 Parameters +1485 ---------- +1486 +1487 `api_key` (str, optional): +1488 Semi-optional argument. +1489 If `api_key` is null, this function will attempt to load a CFBD API key +1490 from the python environment, or from a file on this computer. +1491 If `api_key` is not null, this function will automatically assume that the +1492 inputted `api_key` is a valid CFBD API key. +1493 +1494 `api_key_dir` (str, optional): +1495 Optional argument. +1496 If `api_key` is set to am empty string, this variable is ignored. +1497 If `api_key_dir` is null, and `api_key` is null, +1498 this function will try to find a CFBD API key file in this user's home directory. +1499 If `api_key_dir` is set to a string, and `api_key` is null, +1500 this function will assume that `api_key_dir` is a directory, +1501 and will try to find a CFBD API key file in that directory. +1502 +1503 `season` (int, semi-optional): +1504 Semi-Optional argument. +1505 Specifies the season you want player season PPA data information from. +1506 This must be specified, otherwise this package, and by extension +1507 the CFBD API, will not accept the request to get player season PPA data information. +1508 +1509 +1510 `team` (str, semi-optional): +1511 Semi-Optional argument. +1512 If you only want player season PPA data for players of a specific team, +1513 regardless if they are the home/away team, +1514 set `team` to the name of the team you want player season PPA data from. +1515 `week` and/or `team` must be set to a non-null value for this function +1516 to work. +1517 +1518 `conference_abv` (str, optional): +1519 Optional argument. +1520 If you only want player season PPA data from games +1521 involving teams from a specific confrence, +1522 set `conference_abv` to the abbreviation +1523 of the conference you want player season PPA data from. +1524 For a list of confrences, +1525 use the `cfbd_json_py.conferences.get_cfbd_conference_info()` +1526 function. +1527 +1528 `position` (str, optional): +1529 Optional argument. +1530 If you only want player season PPA data for players of a specific position, +1531 set `position` to the position you want player season PPA data from. +1532 +1533 `player_id` (int, optional): +1534 Optional argument. +1535 If you only want PPA data for a specific player ID, +1536 set this variable to the player ID of the player you want PPA data from. +1537 +1538 `play_threshold` +1539 Optional argument. +1540 If you only want PPA data for players +1541 who touched the ball for *X* number of plays in a game, +1542 set `play_threshold = x`, where `x` is +1543 your specified minimum number of plays. +1544 +1545 `exclude_garbage_time` (bool, optional): +1546 Optional argument. +1547 If you want to filter out plays where the result of the game is largely decided, +1548 set `exclude_garbage_time = True`. +1549 Default behavior is that this variable is set to +1550 `False` when this function is called. +1551 +1552 +1553 `return_as_dict` (bool, semi-optional): +1554 Semi-optional argument. +1555 If you want this function to return the data as a dictionary (read: JSON object), +1556 instead of a pandas `DataFrame` object, +1557 set `return_as_dict` to `True`. +1558 +1559 Usage +1560 ---------- +1561 ``` +1562 import time +1563 +1564 from cfbd_json_py.metrics import get_cfbd_player_season_ppa_data +1565 +1566 +1567 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1568 +1569 if cfbd_key != "tigersAreAwsome": +1570 print("Using the user's API key declared in this script for this example.") +1571 +1572 # Get player season PPA data for the 2020 CFB season. +1573 print("Get player season PPA data for the 2020 CFB season.") +1574 json_data = get_cfbd_player_season_ppa_data( +1575 api_key=cfbd_key, +1576 season=2020 +1577 ) +1578 print(json_data) +1579 time.sleep(5) +1580 +1581 # Get player season PPA data from the 2020 Ohio Bobcats Football Team. +1582 print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") +1583 json_data = get_cfbd_player_season_ppa_data( +1584 api_key=cfbd_key, +1585 season=2020, +1586 team="Ohio" +1587 ) +1588 print(json_data) +1589 time.sleep(5) +1590 +1591 # Get player season PPA data for players who played on +1592 # teams within the Southeastern Conference (SEC) for the +1593 # 2020 CFB Season. +1594 print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") +1595 json_data = get_cfbd_player_season_ppa_data( +1596 api_key=cfbd_key, +1597 season=2020, +1598 conference_abv="SEC" +1599 ) +1600 print(json_data) +1601 time.sleep(5) +1602 +1603 # Get player season PPA data from QBs in the 2020 CFB Season. +1604 print("Get player season PPA data from QBs in the 2020 CFB Season.") +1605 json_data = get_cfbd_player_season_ppa_data( +1606 api_key=cfbd_key, +1607 season=2020, +1608 position="QB" +1609 ) +1610 print(json_data) +1611 time.sleep(5) +1612 +1613 # Get player season PPA data from +1614 # former Ohio State and LSU QB Joe Burrow (player ID #3915511). +1615 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") +1616 json_data = get_cfbd_player_season_ppa_data( +1617 api_key=cfbd_key, +1618 player_id=3915511 +1619 ) +1620 print(json_data) +1621 time.sleep(5) +1622 +1623 # Get player season PPA data from +1624 # former Ohio State and LSU QB Joe Burrow (player ID #3915511), +1625 # but exclude plays that occured in garbage time. +1626 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") +1627 json_data = get_cfbd_player_season_ppa_data( +1628 api_key=cfbd_key, +1629 player_id=3915511, +1630 exclude_garbage_time=True +1631 ) +1632 print(json_data) +1633 time.sleep(5) +1634 +1635 # Get player season PPA data from the 2020 CFB Season, +1636 # for players with at least 100 plays/touches. +1637 print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") +1638 json_data = get_cfbd_player_season_ppa_data( +1639 api_key=cfbd_key, +1640 season=2020, +1641 play_threshold=100 +1642 ) +1643 print(json_data) +1644 time.sleep(5) +1645 +1646 # You can also tell this function to just return the API call as +1647 # a Dictionary (read: JSON) object. +1648 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1649 json_data = get_cfbd_player_season_ppa_data( +1650 api_key=cfbd_key, +1651 season=2020, +1652 return_as_dict=True +1653 ) +1654 print(json_data) +1655 +1656 else: +1657 # Alternatively, if the CFBD API key exists in this python environment, +1658 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +1659 # you could just call these functions directly, without setting the API key +1660 # in the script. +1661 print("Using the user's API key suposedly loaded into this python environment for this example.") +1662 +1663 # Get player season PPA data for the 2020 CFB season. +1664 print("Get player season PPA data for the 2020 CFB season.") +1665 json_data = get_cfbd_player_season_ppa_data( +1666 season=2020 +1667 ) +1668 print(json_data) +1669 time.sleep(5) +1670 +1671 # Get player season PPA data from the 2020 Ohio Bobcats Football Team. +1672 print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") +1673 json_data = get_cfbd_player_season_ppa_data( +1674 season=2020, +1675 team="Ohio" +1676 ) +1677 print(json_data) +1678 time.sleep(5) +1679 +1680 # Get player season PPA data for players who played on +1681 # teams within the Southeastern Conference (SEC) for the +1682 # 2020 CFB Season. +1683 print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") +1684 json_data = get_cfbd_player_season_ppa_data( +1685 season=2020, +1686 conference_abv="SEC" +1687 ) +1688 print(json_data) +1689 time.sleep(5) +1690 +1691 # Get player season PPA data from QBs in the 2020 CFB Season. +1692 print("Get player season PPA data from QBs in the 2020 CFB Season.") +1693 json_data = get_cfbd_player_season_ppa_data( +1694 season=2020, +1695 position="QB" +1696 ) +1697 print(json_data) +1698 time.sleep(5) +1699 +1700 # Get player season PPA data from +1701 # former Ohio State and LSU QB Joe Burrow (player ID #3915511). +1702 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") +1703 json_data = get_cfbd_player_season_ppa_data( +1704 player_id=3915511 +1705 ) +1706 print(json_data) +1707 time.sleep(5) +1708 +1709 # Get player season PPA data from +1710 # former Ohio State and LSU QB Joe Burrow (player ID #3915511), +1711 # but exclude plays that occured in garbage time. +1712 print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") +1713 json_data = get_cfbd_player_season_ppa_data( +1714 player_id=3915511, +1715 exclude_garbage_time=True +1716 ) +1717 print(json_data) +1718 time.sleep(5) +1719 +1720 # Get player season PPA data from the 2020 CFB Season, +1721 # for players with at least 100 plays/touches. +1722 print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") +1723 json_data = get_cfbd_player_season_ppa_data( +1724 season=2020, +1725 play_threshold=100 +1726 ) +1727 print(json_data) +1728 time.sleep(5) +1729 +1730 # You can also tell this function to just return the API call as +1731 # a Dictionary (read: JSON) object. +1732 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +1733 json_data = get_cfbd_player_season_ppa_data( +1734 season=2020, +1735 return_as_dict=True +1736 ) +1737 print(json_data) +1738 +1739 ``` +1740 Returns +1741 ---------- +1742 A pandas `DataFrame` object with player PPA data, +1743 or (if `return_as_dict` is set to `True`) +1744 a dictionary object with player PPA data. +1745 +1746 """ +1747 now = datetime.now() +1748 cfb_games_df = pd.DataFrame() +1749 row_df = pd.DataFrame() +1750 url = "https://api.collegefootballdata.com/ppa/players/season" +1751 +1752 ######################################################################################################################################################################################################## +1753 +1754 if api_key != None: +1755 real_api_key = api_key +1756 del api_key +1757 else: +1758 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +1759 +1760 if real_api_key == "tigersAreAwsome": +1761 raise ValueError( +1762 "You actually need to change `cfbd_key` to your CFBD API key.") +1763 elif "Bearer " in real_api_key: +1764 pass +1765 elif "Bearer" in real_api_key: +1766 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +1767 else: +1768 real_api_key = "Bearer " + real_api_key +1769 +1770 if season == None: +1771 pass +1772 elif season > now.year: +1773 raise ValueError(f"`season` cannot be greater than {season}.") +1774 elif season < 1869: +1775 raise ValueError(f"`season` cannot be less than 1869.") +1776 +1777 if play_threshold != None and play_threshold < 0: +1778 raise ValueError( +1779 "`play_threshold` must be an integer at or greater than 0." +1780 ) +1781 +1782 gt_str = "" +1783 if exclude_garbage_time == True: +1784 gt_str = "true" +1785 elif exclude_garbage_time == False: +1786 gt_str = "false" +1787 +1788 # URL builder +1789 ######################################################################################################################################################################################################## +1790 url_elements = 0 +1791 +1792 if season != None and url_elements == 0: +1793 url += f"?year={season}" +1794 url_elements += 1 +1795 elif season != None: +1796 url += f"&year={season}" +1797 url_elements += 1 +1798 +1799 if team != None and url_elements == 0: +1800 url += f"?team={team}" +1801 url_elements += 1 +1802 elif team != None: +1803 url += f"&team={team}" +1804 url_elements += 1 +1805 +1806 if conference_abv != None and url_elements == 0: +1807 url += f"?conference={conference_abv}" +1808 url_elements += 1 +1809 elif conference_abv != None: +1810 url += f"&conference={conference_abv}" +1811 url_elements += 1 +1812 +1813 if position != None and url_elements == 0: +1814 url += f"?position={position}" +1815 url_elements += 1 +1816 elif position != None: +1817 url += f"&position={position}" +1818 url_elements += 1 +1819 +1820 if player_id != None and url_elements == 0: +1821 url += f"?playerId={player_id}" +1822 url_elements += 1 +1823 elif player_id != None: +1824 url += f"&playerId={player_id}" +1825 url_elements += 1 +1826 +1827 if play_threshold != None and url_elements == 0: +1828 url += f"?threshold={play_threshold}" +1829 url_elements += 1 +1830 elif play_threshold != None: +1831 url += f"&threshold={play_threshold}" +1832 url_elements += 1 +1833 +1834 if exclude_garbage_time != None and url_elements == 0: +1835 url += f"?excludeGarbageTime={gt_str}" +1836 url_elements += 1 +1837 elif exclude_garbage_time != None: +1838 url += f"&excludeGarbageTime={gt_str}" +1839 url_elements += 1 +1840 +1841 headers = { +1842 'Authorization': f'{real_api_key}', +1843 'accept': 'application/json' +1844 } +1845 response = requests.get(url, headers=headers) +1846 +1847 if response.status_code == 200: +1848 pass +1849 elif response.status_code == 401: +1850 raise ConnectionRefusedError( +1851 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +1852 ) +1853 else: +1854 raise ConnectionError( +1855 f'Could not connect.\nHTTP Status code {response.status_code}' +1856 ) +1857 +1858 json_data = response.json() +1859 +1860 if return_as_dict == True: +1861 return json_data +1862 +1863 for player in tqdm(json_data): +1864 p_season = player['season'] +1865 row_df = pd.DataFrame( +1866 {"season": p_season}, +1867 index=[0] +1868 ) +1869 row_df['player_id'] = player['id'] +1870 row_df['player_name'] = player['name'] +1871 row_df['player_position'] = player['position'] +1872 row_df['team'] = player['team'] +1873 row_df['conference'] = player['conference'] +1874 row_df['countable_plays'] = player['countablePlays'] +1875 +1876 # Average PPA +1877 row_df['average_ppa_all'] = player['averagePPA']['all'] +1878 row_df['average_ppa_pass'] = player['averagePPA']['pass'] +1879 row_df['average_ppa_rush'] = player['averagePPA']['rush'] +1880 row_df['average_ppa_first_down'] = player['averagePPA']['firstDown'] +1881 row_df['average_ppa_second_down'] = player['averagePPA']['secondDown'] +1882 row_df['average_ppa_third_down'] = player['averagePPA']['thirdDown'] +1883 row_df['average_ppa_standard_downs'] = player['averagePPA']['standardDowns'] +1884 row_df['average_ppa_passing_downs'] = player['averagePPA']['passingDowns'] +1885 +1886 # Total PPA +1887 row_df['total_ppa_all'] = player['totalPPA']['all'] +1888 row_df['total_ppa_pass'] = player['totalPPA']['pass'] +1889 row_df['total_ppa_rush'] = player['totalPPA']['rush'] +1890 row_df['total_ppa_first_down'] = player['totalPPA']['firstDown'] +1891 row_df['total_ppa_second_down'] = player['totalPPA']['secondDown'] +1892 row_df['total_ppa_third_down'] = player['totalPPA']['thirdDown'] +1893 row_df['total_ppa_standard_downs'] = player['totalPPA']['standardDowns'] +1894 row_df['total_ppa_passing_downs'] = player['totalPPA']['passingDowns'] +1895 +1896 # Have to do this because of a FutureWarning that is raised +1897 # starting in pandas 2.1.1, when using pd.concat(), +1898 # and a column datatype mismatch is found. +1899 row_df = row_df.astype( +1900 { +1901 "average_ppa_all": "float", +1902 "average_ppa_pass": "float", +1903 "average_ppa_rush": "float", +1904 "average_ppa_first_down": "float", +1905 "average_ppa_second_down": "float", +1906 "average_ppa_third_down": "float", +1907 "average_ppa_standard_downs": "float", +1908 "average_ppa_passing_downs": "float", +1909 +1910 "total_ppa_all": "float", +1911 "total_ppa_pass": "float", +1912 "total_ppa_rush": "float", +1913 "total_ppa_first_down": "float", +1914 "total_ppa_second_down": "float", +1915 "total_ppa_third_down": "float", +1916 "total_ppa_standard_downs": "float", +1917 "total_ppa_passing_downs": "float" +1918 } +1919 ) +1920 +1921 cfb_games_df = pd.concat([cfb_games_df, row_df], ignore_index=True) +1922 del row_df +1923 del p_season +1924 +1925 return cfb_games_df+Allows you to get player PPA data, +at a season level, +with or without garbage time plays, +for a specificed time period and/or team.
+ +PPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
+ +Parameters
+ ++ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
season
(int, semi-optional): + Semi-Optional argument. + Specifies the season you want player season PPA data information from. + This must be specified, otherwise this package, and by extension + the CFBD API, will not accept the request to get player season PPA data information.+ +
team
(str, semi-optional): + Semi-Optional argument. + If you only want player season PPA data for players of a specific team, + regardless if they are the home/away team, + setteam
to the name of the team you want player season PPA data from. +week
and/orteam
must be set to a non-null value for this function + to work.+ +
conference_abv
(str, optional): + Optional argument. + If you only want player season PPA data from games + involving teams from a specific confrence, + setconference_abv
to the abbreviation + of the conference you want player season PPA data from. + For a list of confrences, + use thecfbd_json_py.conferences.get_cfbd_conference_info()
+ function.+ +
position
(str, optional): + Optional argument. + If you only want player season PPA data for players of a specific position, + setposition
to the position you want player season PPA data from.+ +
player_id
(int, optional): + Optional argument. + If you only want PPA data for a specific player ID, + set this variable to the player ID of the player you want PPA data from.+ +
play_threshold
+ Optional argument. + If you only want PPA data for players + who touched the ball for X number of plays in a game, + setplay_threshold = x
, wherex
is + your specified minimum number of plays.+ +
exclude_garbage_time
(bool, optional): + Optional argument. + If you want to filter out plays where the result of the game is largely decided, + setexclude_garbage_time = True
. + Default behavior is that this variable is set to +False
when this function is called.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_player_season_ppa_data + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get player season PPA data for the 2020 CFB season. + print("Get player season PPA data for the 2020 CFB season.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 Ohio Bobcats Football Team. + print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + team="Ohio" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data for players who played on + # teams within the Southeastern Conference (SEC) for the + # 2020 CFB Season. + print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from QBs in the 2020 CFB Season. + print("Get player season PPA data from QBs in the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511). + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + player_id=3915511 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511), + # but exclude plays that occured in garbage time. + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + player_id=3915511, + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 CFB Season, + # for players with at least 100 plays/touches. + print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + play_threshold=100 + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_season_ppa_data( + api_key=cfbd_key, + season=2020, + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get player season PPA data for the 2020 CFB season. + print("Get player season PPA data for the 2020 CFB season.") + json_data = get_cfbd_player_season_ppa_data( + season=2020 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 Ohio Bobcats Football Team. + print("Get player season PPA data for the 2020 Ohio Bobcats Football Team.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + team="Ohio" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data for players who played on + # teams within the Southeastern Conference (SEC) for the + # 2020 CFB Season. + print("Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + conference_abv="SEC" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from QBs in the 2020 CFB Season. + print("Get player season PPA data from QBs in the 2020 CFB Season.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + position="QB" + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511). + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).") + json_data = get_cfbd_player_season_ppa_data( + player_id=3915511 + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from + # former Ohio State and LSU QB Joe Burrow (player ID #3915511), + # but exclude plays that occured in garbage time. + print("Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.") + json_data = get_cfbd_player_season_ppa_data( + player_id=3915511, + exclude_garbage_time=True + ) + print(json_data) + time.sleep(5) + + # Get player season PPA data from the 2020 CFB Season, + # for players with at least 100 plays/touches. + print("Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + play_threshold=100 + ) + print(json_data) + time.sleep(5) + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_player_season_ppa_data( + season=2020, + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with player PPA data, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with player PPA data.@@ -388,22 +5602,338 @@
-104def get_cfbd_game_win_probability_data( -105 game_id: int, -106 api_key: str = None, -107 api_key_dir: str = None, -108 -109 return_as_dict: bool = False): -110 """ -111 -112 """ -113 raise NotImplementedError( -114 'This function has yet to be implemented by this version.' -115 ) +- +1928def get_cfbd_game_win_probability_data( +1929 game_id: int, +1930 api_key: str = None, +1931 api_key_dir: str = None, +1932 return_as_dict: bool = False): +1933 """ +1934 Allows one to get win probabliity data for a given game ID. +1935 +1936 Parameters +1937 ---------- +1938 +1939 `game_id` (int, mandatory): +1940 Mandatory argument. +1941 This is the game ID for the game you want win probability data from, +1942 at the play-by-play level. +1943 +1944 `api_key` (str, optional): +1945 Semi-optional argument. +1946 If `api_key` is null, this function will attempt to load a CFBD API key +1947 from the python environment, or from a file on this computer. +1948 If `api_key` is not null, this function will automatically assume that the +1949 inputted `api_key` is a valid CFBD API key. +1950 +1951 `api_key_dir` (str, optional): +1952 Optional argument. +1953 If `api_key` is set to am empty string, this variable is ignored. +1954 If `api_key_dir` is null, and `api_key` is null, +1955 this function will try to find a CFBD API key file in this user's home directory. +1956 If `api_key_dir` is set to a string, and `api_key` is null, +1957 this function will assume that `api_key_dir` is a directory, +1958 and will try to find a CFBD API key file in that directory. +1959 +1960 `return_as_dict` (bool, semi-optional): +1961 Semi-optional argument. +1962 If you want this function to return the data as a dictionary (read: JSON object), +1963 instead of a pandas `DataFrame` object, +1964 set `return_as_dict` to `True`. +1965 +1966 Usage +1967 ---------- +1968 ``` +1969 import time +1970 +1971 from cfbd_json_py.metrics import get_cfbd_game_win_probability_data +1972 +1973 +1974 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +1975 +1976 if cfbd_key != "tigersAreAwsome": +1977 print("Using the user's API key declared in this script for this example.") +1978 +1979 # Get the win probablility data for a 2017 game between +1980 # the University of Cincinnati and UConn (game ID #400941851). +1981 print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") +1982 json_data = get_cfbd_game_win_probability_data( +1983 api_key=cfbd_key, +1984 game_id=400941851 +1985 ) +1986 print(json_data) +1987 time.sleep(5) +1988 +1989 # Get the win probablility data for a 2023 game between +1990 # the University of Duke and the University of Louisville (game ID #401525535). +1991 print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") +1992 json_data = get_cfbd_game_win_probability_data( +1993 api_key=cfbd_key, +1994 game_id=401525535 +1995 ) +1996 print(json_data) +1997 time.sleep(5) +1998 +1999 +2000 # You can also tell this function to just return the API call as +2001 # a Dictionary (read: JSON) object. +2002 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2003 json_data = get_cfbd_game_win_probability_data( +2004 api_key=cfbd_key, +2005 game_id=400941851, +2006 return_as_dict=True +2007 ) +2008 print(json_data) +2009 +2010 else: +2011 # Alternatively, if the CFBD API key exists in this python environment, +2012 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +2013 # you could just call these functions directly, without setting the API key +2014 # in the script. +2015 print("Using the user's API key suposedly loaded into this python environment for this example.") +2016 +2017 # Get win probablility data for a 2017 game between +2018 # the University of Cincinnati and UConn (game ID #400941851). +2019 print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") +2020 json_data = get_cfbd_game_win_probability_data( +2021 game_id=400941851 +2022 ) +2023 print(json_data) +2024 time.sleep(5) +2025 +2026 # Get win probablility data for a 2023 game between +2027 # the University of Duke and the University of Louisville (game ID #401525535). +2028 print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") +2029 json_data = get_cfbd_game_win_probability_data( +2030 game_id=401525535 +2031 ) +2032 print(json_data) +2033 time.sleep(5) +2034 +2035 +2036 # You can also tell this function to just return the API call as +2037 # a Dictionary (read: JSON) object. +2038 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2039 json_data = get_cfbd_game_win_probability_data( +2040 game_id=400941851, +2041 return_as_dict=True +2042 ) +2043 print(json_data) +2044 +2045 ``` +2046 Returns +2047 ---------- +2048 A pandas `DataFrame` object with win probability data at the play-by-play level, +2049 or (if `return_as_dict` is set to `True`) +2050 a dictionary object with win probability data at the play-by-play level. +2051 +2052 """ +2053 +2054 wp_df = pd.DataFrame() +2055 row_df = pd.DataFrame() +2056 url = "https://api.collegefootballdata.com/metrics/wp" +2057 +2058 ######################################################################################################################################################################################################## +2059 +2060 if api_key != None: +2061 real_api_key = api_key +2062 del api_key +2063 else: +2064 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +2065 +2066 if real_api_key == "tigersAreAwsome": +2067 raise ValueError( +2068 "You actually need to change `cfbd_key` to your CFBD API key.") +2069 elif "Bearer " in real_api_key: +2070 pass +2071 elif "Bearer" in real_api_key: +2072 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +2073 else: +2074 real_api_key = "Bearer " + real_api_key +2075 # URL builder +2076 ######################################################################################################################################################################################################## +2077 +2078 # Required by API +2079 url += f"?gameId={game_id}" +2080 +2081 headers = { +2082 'Authorization': f'{real_api_key}', +2083 'accept': 'application/json' +2084 } +2085 +2086 response = requests.get(url, headers=headers) +2087 +2088 if response.status_code == 200: +2089 pass +2090 elif response.status_code == 401: +2091 raise ConnectionRefusedError( +2092 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +2093 ) +2094 else: +2095 raise ConnectionError( +2096 f'Could not connect.\nHTTP Status code {response.status_code}' +2097 ) +2098 +2099 json_data = response.json() +2100 +2101 if return_as_dict == True: +2102 return json_data +2103 +2104 for play in tqdm(json_data): +2105 row_df = pd.DataFrame( +2106 {"game_id": game_id}, +2107 index=[0] +2108 ) +2109 row_df['play_id'] = play['playId'] +2110 row_df['play_text'] = play['playText'] +2111 row_df['home_id'] = play['homeId'] +2112 row_df['home_team_name'] = play['home'] +2113 row_df['away_id'] = play['awayId'] +2114 row_df['away_team_name'] = play['away'] +2115 row_df['spread'] = play['spread'] +2116 row_df['home_team_has_ball'] = play['homeBall'] +2117 row_df['home_score'] = play['homeScore'] +2118 row_df['away_score'] = play['awayScore'] +2119 row_df['down'] = play['down'] +2120 row_df['distance'] = play['distance'] +2121 row_df['home_win_probability'] = play['homeWinProb'] +2122 row_df['play_number'] = play['playNumber'] +2123 +2124 wp_df = pd.concat([wp_df, row_df], ignore_index=True) +2125 +2126 if len(wp_df) == 0: +2127 logging.error( +2128 "The CFBD API accepted your inputs, " + +2129 "but found no data within your specified input paramaters." + +2130 " Please double check your input paramaters." +2131 ) +2132 else: +2133 wp_df = wp_df.astype( +2134 {"home_win_probability": "float"} +2135 ) +2136 wp_df['away_win_probability'] = 1 - wp_df['home_win_probability'] +2137 +2138 return wp_df+Allows one to get win probabliity data for a given game ID.
+ +Parameters
+ ++ +
game_id
(int, mandatory): + Mandatory argument. + This is the game ID for the game you want win probability data from, + at the play-by-play level.+ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_game_win_probability_data + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get the win probablility data for a 2017 game between + # the University of Cincinnati and UConn (game ID #400941851). + print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") + json_data = get_cfbd_game_win_probability_data( + api_key=cfbd_key, + game_id=400941851 + ) + print(json_data) + time.sleep(5) + + # Get the win probablility data for a 2023 game between + # the University of Duke and the University of Louisville (game ID #401525535). + print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") + json_data = get_cfbd_game_win_probability_data( + api_key=cfbd_key, + game_id=401525535 + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_game_win_probability_data( + api_key=cfbd_key, + game_id=400941851, + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + + # Get win probablility data for a 2017 game between + # the University of Cincinnati and UConn (game ID #400941851). + print("Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).") + json_data = get_cfbd_game_win_probability_data( + game_id=400941851 + ) + print(json_data) + time.sleep(5) + + # Get win probablility data for a 2023 game between + # the University of Duke and the University of Louisville (game ID #401525535). + print("Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).") + json_data = get_cfbd_game_win_probability_data( + game_id=401525535 + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_game_win_probability_data( + game_id=400941851, + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with win probability data at the play-by-play level, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with win probability data at the play-by-play level.@@ -417,25 +5947,504 @@
@@ -179,14 +178,13 @@118def get_cfbd_pregame_win_probability_data( -119 season: int, -120 api_key: str = None, -121 api_key_dir: str = None, -122 week: int = None, -123 team: str = None, -124 season_type: str = "regular", # "regular" or "postseason" -125 -126 return_as_dict: bool = False): -127 """ -128 -129 """ -130 raise NotImplementedError( -131 'This function has yet to be implemented by this version.' -132 ) +- +2141def get_cfbd_pregame_win_probability_data( +2142 season: int, +2143 api_key: str = None, +2144 api_key_dir: str = None, +2145 week: int = None, +2146 team: str = None, +2147 season_type: str = "regular", # "regular" or "postseason" +2148 return_as_dict: bool = False): +2149 """ +2150 Allows you to get pregame win probability data for games within a timeframe. +2151 +2152 Parameters +2153 ---------- +2154 `api_key` (str, optional): +2155 Semi-optional argument. +2156 If `api_key` is null, this function will attempt to load a CFBD API key +2157 from the python environment, or from a file on this computer. +2158 If `api_key` is not null, this function will automatically assume that the +2159 inputted `api_key` is a valid CFBD API key. +2160 +2161 `api_key_dir` (str, optional): +2162 Optional argument. +2163 If `api_key` is set to am empty string, this variable is ignored. +2164 If `api_key_dir` is null, and `api_key` is null, +2165 this function will try to find a CFBD API key file in this user's home directory. +2166 If `api_key_dir` is set to a string, and `api_key` is null, +2167 this function will assume that `api_key_dir` is a directory, +2168 and will try to find a CFBD API key file in that directory. +2169 +2170 `season` (int, optional): +2171 Semi-optional argument. +2172 Specifies the season you want pregame win probability data. +2173 +2174 `week` (int, optional): +2175 Optional argument. +2176 If `week` is set to an integer, this function will attempt +2177 to load CFB game data from games in that season, and in that week. +2178 +2179 `team` (str, optional): +2180 Semi-ptional argument. +2181 If you only want pregame win probability data for a specific team, +2182 set `team` to the name of the team you want pregame win probability data from. +2183 +2184 `season_type` (str, semi-optional): +2185 Semi-optional argument. +2186 By defualt, this will be set to "regular", for the CFB regular season. +2187 If you want CFB game information for non-regular season games, +2188 set `season_type` to "postseason". +2189 If `season_type` is set to anything but "regular" or "postseason", +2190 a `ValueError()` will be raised. +2191 +2192 `return_as_dict` (bool, semi-optional): +2193 Semi-optional argument. +2194 If you want this function to return the data as a dictionary (read: JSON object), +2195 instead of a pandas `DataFrame` object, +2196 set `return_as_dict` to `True`. +2197 +2198 Usage +2199 ---------- +2200 ``` +2201 import time +2202 +2203 from cfbd_json_py.metrics import get_cfbd_pregame_win_probability_data +2204 +2205 +2206 cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. +2207 +2208 if cfbd_key != "tigersAreAwsome": +2209 print("Using the user's API key declared in this script for this example.") +2210 +2211 # Get pregame win probabilities for games in the 2023 CFB season. +2212 print("Get pregame win probabilities for games in the 2023 CFB season.") +2213 json_data = get_cfbd_pregame_win_probability_data( +2214 api_key=cfbd_key, +2215 season=2023 +2216 ) +2217 print(json_data) +2218 time.sleep(5) +2219 +2220 +2221 # Get pregame win probabilities for games in week 10 of the 2021 CFB season. +2222 print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") +2223 json_data = get_cfbd_pregame_win_probability_data( +2224 api_key=cfbd_key, +2225 season=2021, +2226 week=10 +2227 ) +2228 print(json_data) +2229 time.sleep(5) +2230 +2231 +2232 # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. +2233 print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") +2234 json_data = get_cfbd_pregame_win_probability_data( +2235 api_key=cfbd_key, +2236 season=2021, +2237 week=10 +2238 ) +2239 print(json_data) +2240 time.sleep(5) +2241 +2242 +2243 # Get pregame win probabilities for postseason games in the 2020 CFB season. +2244 print("Get pregame win probabilities for postseason games in the 2020 CFB season.") +2245 json_data = get_cfbd_pregame_win_probability_data( +2246 api_key=cfbd_key, +2247 season=2020, +2248 season_type="postseason" +2249 ) +2250 print(json_data) +2251 time.sleep(5) +2252 +2253 +2254 # You can also tell this function to just return the API call as +2255 # a Dictionary (read: JSON) object. +2256 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2257 json_data = get_cfbd_pregame_win_probability_data( +2258 api_key=cfbd_key, +2259 season=2023, +2260 week=10, +2261 return_as_dict=True +2262 ) +2263 print(json_data) +2264 +2265 else: +2266 # Alternatively, if the CFBD API key exists in this python environment, +2267 # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), +2268 # you could just call these functions directly, without setting the API key +2269 # in the script. +2270 print("Using the user's API key suposedly loaded into this python environment for this example.") +2271 +2272 # Get pregame win probabilities for games in the 2023 CFB season. +2273 print("Get pregame win probabilities for games in the 2023 CFB season.") +2274 json_data = get_cfbd_pregame_win_probability_data( +2275 season=2023 +2276 ) +2277 print(json_data) +2278 time.sleep(5) +2279 +2280 +2281 # Get pregame win probabilities for games in week 10 of the 2021 CFB season. +2282 print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") +2283 json_data = get_cfbd_pregame_win_probability_data( +2284 season=2021, +2285 week=10 +2286 ) +2287 print(json_data) +2288 time.sleep(5) +2289 +2290 +2291 # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. +2292 print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") +2293 json_data = get_cfbd_pregame_win_probability_data( +2294 season=2021, +2295 week=10 +2296 ) +2297 print(json_data) +2298 time.sleep(5) +2299 +2300 +2301 # Get pregame win probabilities for postseason games in the 2020 CFB season. +2302 print("Get pregame win probabilities for postseason games in the 2020 CFB season.") +2303 json_data = get_cfbd_pregame_win_probability_data( +2304 season=2020, +2305 season_type="postseason" +2306 ) +2307 print(json_data) +2308 time.sleep(5) +2309 +2310 +2311 # You can also tell this function to just return the API call as +2312 # a Dictionary (read: JSON) object. +2313 print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") +2314 json_data = get_cfbd_pregame_win_probability_data( +2315 season=2023, +2316 week=10, +2317 return_as_dict=True +2318 ) +2319 print(json_data) +2320 +2321 ``` +2322 Returns +2323 ---------- +2324 A pandas `DataFrame` object with pregame win probability data, +2325 or (if `return_as_dict` is set to `True`) +2326 a dictionary object with a pregame win probability data. +2327 +2328 """ +2329 now = datetime.now() +2330 wp_df = pd.DataFrame() +2331 row_df = pd.DataFrame() +2332 url = "https://api.collegefootballdata.com/metrics/wp/pregame" +2333 +2334 ######################################################################################################################################################################################################## +2335 +2336 if api_key != None: +2337 real_api_key = api_key +2338 del api_key +2339 else: +2340 real_api_key = get_cfbd_api_token(api_key_dir=api_key_dir) +2341 +2342 if real_api_key == "tigersAreAwsome": +2343 raise ValueError( +2344 "You actually need to change `cfbd_key` to your CFBD API key.") +2345 elif "Bearer " in real_api_key: +2346 pass +2347 elif "Bearer" in real_api_key: +2348 real_api_key = real_api_key.replace('Bearer', 'Bearer ') +2349 else: +2350 real_api_key = "Bearer " + real_api_key +2351 +2352 if season == None: +2353 pass +2354 elif season > now.year: +2355 raise ValueError(f"`season` cannot be greater than {season}.") +2356 elif season < 1869: +2357 raise ValueError(f"`season` cannot be less than 1869.") +2358 +2359 if week != None and week < 0: +2360 raise ValueError( +2361 "`week` must be an integer greater than 0." +2362 ) +2363 +2364 if season_type != "regular" and season_type != "postseason": +2365 raise ValueError( +2366 "`season_type` must be set to either \"regular\" or \"postseason\" for this function to work.") +2367 +2368 +2369 +2370 # URL builder +2371 ######################################################################################################################################################################################################## +2372 url_elements = 0 +2373 +2374 if season != None and url_elements == 0: +2375 url += f"?year={season}" +2376 url_elements += 1 +2377 elif season != None: +2378 url += f"&year={season}" +2379 url_elements += 1 +2380 +2381 if week != None and url_elements == 0: +2382 url += f"?week={week}" +2383 url_elements += 1 +2384 elif week != None: +2385 url += f"&week={week}" +2386 url_elements += 1 +2387 +2388 if team != None and url_elements == 0: +2389 url += f"?team={team}" +2390 url_elements += 1 +2391 elif team != None: +2392 url += f"&team={team}" +2393 url_elements += 1 +2394 +2395 if season_type != None and url_elements == 0: +2396 url += f"?seasonType={season_type}" +2397 url_elements += 1 +2398 elif season_type != None: +2399 url += f"&seasonType={season_type}" +2400 url_elements += 1 +2401 +2402 +2403 headers = { +2404 'Authorization': f'{real_api_key}', +2405 'accept': 'application/json' +2406 } +2407 +2408 response = requests.get(url, headers=headers) +2409 +2410 if response.status_code == 200: +2411 pass +2412 elif response.status_code == 401: +2413 raise ConnectionRefusedError( +2414 f'Could not connect. The connection was refused.\nHTTP Status Code 401.' +2415 ) +2416 else: +2417 raise ConnectionError( +2418 f'Could not connect.\nHTTP Status code {response.status_code}' +2419 ) +2420 +2421 json_data = response.json() +2422 +2423 if return_as_dict == True: +2424 return json_data +2425 +2426 for game in tqdm(json_data): +2427 g_season = game['season'] +2428 row_df = pd.DataFrame( +2429 {"season":g_season}, +2430 index=[0] +2431 ) +2432 row_df['week'] = game['week'] +2433 row_df['season_type'] = game['seasonType'] +2434 row_df['game_id'] = game['gameId'] +2435 row_df['home_team_name'] = game['homeTeam'] +2436 row_df['away_team_name'] = game['awayTeam'] +2437 row_df['spread'] = game['spread'] +2438 row_df['home_win_probability'] = game['homeWinProb'] +2439 +2440 wp_df = pd.concat([wp_df,row_df],ignore_index=True) +2441 del row_df +2442 del g_season +2443 +2444 if len(wp_df) == 0: +2445 logging.error( +2446 "The CFBD API accepted your inputs, " + +2447 "but found no data within your specified input paramaters." + +2448 " Please double check your input paramaters." +2449 ) +2450 else: +2451 wp_df = wp_df.astype( +2452 {"home_win_probability": "float"} +2453 ) +2454 wp_df['away_win_probability'] = 1 - wp_df['home_win_probability'] +2455 +2456 return wp_df+ diff --git a/docs/cfbd_json_py/players.html b/docs/cfbd_json_py/players.html index 2cbd08d..4dcb9f4 100644 --- a/docs/cfbd_json_py/players.html +++ b/docs/cfbd_json_py/players.html @@ -81,82 +81,81 @@Allows you to get pregame win probability data for games within a timeframe.
+ +Parameters
+ ++ +
api_key
(str, optional): + Semi-optional argument. + Ifapi_key
is null, this function will attempt to load a CFBD API key + from the python environment, or from a file on this computer. + Ifapi_key
is not null, this function will automatically assume that the + inputtedapi_key
is a valid CFBD API key.+ +
api_key_dir
(str, optional): + Optional argument. + Ifapi_key
is set to am empty string, this variable is ignored. + Ifapi_key_dir
is null, andapi_key
is null, + this function will try to find a CFBD API key file in this user's home directory. + Ifapi_key_dir
is set to a string, andapi_key
is null, + this function will assume thatapi_key_dir
is a directory, + and will try to find a CFBD API key file in that directory.+ +
season
(int, optional): + Semi-optional argument. + Specifies the season you want pregame win probability data.+ +
week
(int, optional): + Optional argument. + Ifweek
is set to an integer, this function will attempt + to load CFB game data from games in that season, and in that week.+ +
team
(str, optional): + Semi-ptional argument. + If you only want pregame win probability data for a specific team, + setteam
to the name of the team you want pregame win probability data from.+ +
season_type
(str, semi-optional): + Semi-optional argument. + By defualt, this will be set to "regular", for the CFB regular season. + If you want CFB game information for non-regular season games, + setseason_type
to "postseason". + Ifseason_type
is set to anything but "regular" or "postseason", + aValueError()
will be raised.+ +
return_as_dict
(bool, semi-optional): + Semi-optional argument. + If you want this function to return the data as a dictionary (read: JSON object), + instead of a pandasDataFrame
object, + setreturn_as_dict
toTrue
.Usage
+ ++ +import time + +from cfbd_json_py.metrics import get_cfbd_pregame_win_probability_data + + +cfbd_key = "tigersAreAwsome" # placeholder for your CFBD API Key. + +if cfbd_key != "tigersAreAwsome": + print("Using the user's API key declared in this script for this example.") + + # Get pregame win probabilities for games in the 2023 CFB season. + print("Get pregame win probabilities for games in the 2023 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2023 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games in week 10 of the 2021 CFB season. + print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. + print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for postseason games in the 2020 CFB season. + print("Get pregame win probabilities for postseason games in the 2020 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_pregame_win_probability_data( + api_key=cfbd_key, + season=2023, + week=10, + return_as_dict=True + ) + print(json_data) + +else: + # Alternatively, if the CFBD API key exists in this python environment, + # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(), + # you could just call these functions directly, without setting the API key + # in the script. + print("Using the user's API key suposedly loaded into this python environment for this example.") + +# Get pregame win probabilities for games in the 2023 CFB season. + print("Get pregame win probabilities for games in the 2023 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + season=2023 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games in week 10 of the 2021 CFB season. + print("Get pregame win probabilities for games in week 10 of the 2021 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team. + print("Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.") + json_data = get_cfbd_pregame_win_probability_data( + season=2021, + week=10 + ) + print(json_data) + time.sleep(5) + + + # Get pregame win probabilities for postseason games in the 2020 CFB season. + print("Get pregame win probabilities for postseason games in the 2020 CFB season.") + json_data = get_cfbd_pregame_win_probability_data( + season=2020, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + + # You can also tell this function to just return the API call as + # a Dictionary (read: JSON) object. + print("You can also tell this function to just return the API call as a Dictionary (read: JSON) object.") + json_data = get_cfbd_pregame_win_probability_data( + season=2023, + week=10, + return_as_dict=True + ) + print(json_data) + +
Returns
+ +A pandas
+DataFrame
object with pregame win probability data, +or (ifreturn_as_dict
is set toTrue
) +a dictionary object with a pregame win probability data.13 position: str = None, 14 team: str = None, 15 season: int = None, -16 -17 return_as_dict: bool = False): -18 """ -19 -20 """ -21 raise NotImplementedError( -22 'This function has yet to be implemented by this version.' -23 ) +16 return_as_dict: bool = False): +17 """ +18 +19 """ +20 raise NotImplementedError( +21 'This function has yet to be implemented by this version.' +22 ) +23 24 -25 -26def get_cfbd_player_usage( -27 season: int, -28 api_key: str = None, -29 api_key_dir: str = None, -30 team: str = None, -31 conference_abv: str = None, -32 position: str = None, -33 player_id: int = None, -34 exclude_garbage_time: bool = False, -35 return_as_dict: bool = False): -36 """ -37 -38 """ -39 raise NotImplementedError( -40 'This function has yet to be implemented by this version.' -41 ) +25def get_cfbd_player_usage( +26 season: int, +27 api_key: str = None, +28 api_key_dir: str = None, +29 team: str = None, +30 conference_abv: str = None, +31 position: str = None, +32 player_id: int = None, +33 exclude_garbage_time: bool = False, +34 return_as_dict: bool = False): +35 """ +36 +37 """ +38 raise NotImplementedError( +39 'This function has yet to be implemented by this version.' +40 ) +41 42 -43 -44def get_cfbd_returning_production( -45 season: int, -46 api_key: str = None, -47 api_key_dir: str = None, -48 team: str = None, -49 conference_abv: str = None, -50 -51 return_as_dict: bool = False): -52 """ -53 -54 """ -55 raise NotImplementedError( -56 'This function has yet to be implemented by this version.' -57 ) +43def get_cfbd_returning_production( +44 season: int, +45 api_key: str = None, +46 api_key_dir: str = None, +47 team: str = None, +48 conference_abv: str = None, +49 +50 return_as_dict: bool = False): +51 """ +52 +53 """ +54 raise NotImplementedError( +55 'This function has yet to be implemented by this version.' +56 ) +57 58 -59 -60def get_cfbd_player_season_stats( -61 season: int, -62 api_key: str = None, -63 api_key_dir: str = None, -64 team: str = None, -65 conference_abv: str = None, -66 start_week: int = None, -67 end_week: int = None, -68 season_type: str = 'regular', # "regular", "postseason", or "both" -69 stat_category: str = None, -70 -71 return_as_dict: bool = False): -72 """ -73 -74 """ -75 raise NotImplementedError( -76 'This function has yet to be implemented by this version.' -77 ) +59def get_cfbd_player_season_stats( +60 season: int, +61 api_key: str = None, +62 api_key_dir: str = None, +63 team: str = None, +64 conference_abv: str = None, +65 start_week: int = None, +66 end_week: int = None, +67 season_type: str = 'regular', # "regular", "postseason", or "both" +68 stat_category: str = None, +69 +70 return_as_dict: bool = False): +71 """ +72 +73 """ +74 raise NotImplementedError( +75 'This function has yet to be implemented by this version.' +76 ) +77 78 -79 -80def get_cfbd_transfer_portal_data( -81 season: int, -82 api_key: str = None, -83 api_key_dir: str = None, -84 -85 return_as_dict: bool = False): -86 """ -87 -88 """ -89 raise NotImplementedError( -90 'This function has yet to be implemented by this version.' -91 ) +79def get_cfbd_transfer_portal_data( +80 season: int, +81 api_key: str = None, +82 api_key_dir: str = None, +83 +84 return_as_dict: bool = False): +85 """ +86 +87 """ +88 raise NotImplementedError( +89 'This function has yet to be implemented by this version.' +90 )
-27def get_cfbd_player_usage( -28 season: int, -29 api_key: str = None, -30 api_key_dir: str = None, -31 team: str = None, -32 conference_abv: str = None, -33 position: str = None, -34 player_id: int = None, -35 exclude_garbage_time: bool = False, -36 return_as_dict: bool = False): -37 """ -38 -39 """ -40 raise NotImplementedError( -41 'This function has yet to be implemented by this version.' -42 ) +@@ -237,20 +235,20 @@26def get_cfbd_player_usage( +27 season: int, +28 api_key: str = None, +29 api_key_dir: str = None, +30 team: str = None, +31 conference_abv: str = None, +32 position: str = None, +33 player_id: int = None, +34 exclude_garbage_time: bool = False, +35 return_as_dict: bool = False): +36 """ +37 +38 """ +39 raise NotImplementedError( +40 'This function has yet to be implemented by this version.' +41 )
-45def get_cfbd_returning_production( -46 season: int, -47 api_key: str = None, -48 api_key_dir: str = None, -49 team: str = None, -50 conference_abv: str = None, -51 -52 return_as_dict: bool = False): -53 """ -54 -55 """ -56 raise NotImplementedError( -57 'This function has yet to be implemented by this version.' -58 ) +@@ -268,24 +266,24 @@44def get_cfbd_returning_production( +45 season: int, +46 api_key: str = None, +47 api_key_dir: str = None, +48 team: str = None, +49 conference_abv: str = None, +50 +51 return_as_dict: bool = False): +52 """ +53 +54 """ +55 raise NotImplementedError( +56 'This function has yet to be implemented by this version.' +57 )
-61def get_cfbd_player_season_stats( -62 season: int, -63 api_key: str = None, -64 api_key_dir: str = None, -65 team: str = None, -66 conference_abv: str = None, -67 start_week: int = None, -68 end_week: int = None, -69 season_type: str = 'regular', # "regular", "postseason", or "both" -70 stat_category: str = None, -71 -72 return_as_dict: bool = False): -73 """ -74 -75 """ -76 raise NotImplementedError( -77 'This function has yet to be implemented by this version.' -78 ) +@@ -303,18 +301,18 @@60def get_cfbd_player_season_stats( +61 season: int, +62 api_key: str = None, +63 api_key_dir: str = None, +64 team: str = None, +65 conference_abv: str = None, +66 start_week: int = None, +67 end_week: int = None, +68 season_type: str = 'regular', # "regular", "postseason", or "both" +69 stat_category: str = None, +70 +71 return_as_dict: bool = False): +72 """ +73 +74 """ +75 raise NotImplementedError( +76 'This function has yet to be implemented by this version.' +77 )
@@ -353,30 +363,34 @@81def get_cfbd_transfer_portal_data( -82 season: int, -83 api_key: str = None, -84 api_key_dir: str = None, -85 -86 return_as_dict: bool = False): -87 """ -88 -89 """ -90 raise NotImplementedError( -91 'This function has yet to be implemented by this version.' -92 ) +diff --git a/docs/cfbd_json_py/utls.html b/docs/cfbd_json_py/utls.html index 9b91f4b..c75b196 100644 --- a/docs/cfbd_json_py/utls.html +++ b/docs/cfbd_json_py/utls.html @@ -78,264 +78,274 @@80def get_cfbd_transfer_portal_data( +81 season: int, +82 api_key: str = None, +83 api_key_dir: str = None, +84 +85 return_as_dict: bool = False): +86 """ +87 +88 """ +89 raise NotImplementedError( +90 'This function has yet to be implemented by this version.' +91 )13 14def reverse_cipher_encrypt(plain_text_str: str): 15 """ - 16 Implements a reverse cipher encription to a plain text string. + 16 NOT INTENDED TO BE CALLED BY THE USER! 17 - 18 Parameters - 19 ---------- - 20 `plain_text_str` (mandatory, str): - 21 The string you want to encrypt through reverse cipher encryption. - 22 - 23 Returns - 24 ---------- - 25 A string encrypted through reverse cipher encryption. - 26 """ - 27 translated_text = '' - 28 str_len = len(plain_text_str) - 1 - 29 while str_len >= 0: - 30 translated_text = translated_text + plain_text_str[str_len] - 31 str_len = str_len - 1 - 32 - 33 del plain_text_str + 18 Implements a reverse cipher encription to a plain text string. + 19 + 20 Parameters + 21 ---------- + 22 `plain_text_str` (mandatory, str): + 23 The string you want to encrypt through reverse cipher encryption. + 24 + 25 Returns + 26 ---------- + 27 A string encrypted through reverse cipher encryption. + 28 """ + 29 translated_text = '' + 30 str_len = len(plain_text_str) - 1 + 31 while str_len >= 0: + 32 translated_text = translated_text + plain_text_str[str_len] + 33 str_len = str_len - 1 34 - 35 return translated_text + 35 del plain_text_str 36 - 37 - 38def reverse_cipher_decrypt(encrypted_text_str: str): - 39 """ - 40 Decrypts a string that was presumed to be encrypted by a reverse cipher encryption. - 41 - 42 Parameters - 43 ---------- - 44 `encrypted_text_str` (mandatory, str): - 45 The string you presume that is encrypted through reverse cipher encryption, - 46 that you want decrypted. - 47 - 48 Returns - 49 ---------- - 50 A decrypted string. + 37 return translated_text + 38 + 39 + 40def reverse_cipher_decrypt(encrypted_text_str: str): + 41 """ + 42 NOT INTENDED TO BE CALLED BY THE USER! + 43 + 44 Decrypts a string that was presumed to be encrypted by a reverse cipher encryption. + 45 + 46 Parameters + 47 ---------- + 48 `encrypted_text_str` (mandatory, str): + 49 The string you presume that is encrypted through reverse cipher encryption, + 50 that you want decrypted. 51 - 52 """ - 53 translated_text = '' - 54 str_len = len(encrypted_text_str) - 1 + 52 Returns + 53 ---------- + 54 A decrypted string. 55 - 56 while str_len >= 0: - 57 translated_text = translated_text + encrypted_text_str[str_len] - 58 str_len = str_len - 1 + 56 """ + 57 translated_text = '' + 58 str_len = len(encrypted_text_str) - 1 59 - 60 del encrypted_text_str - 61 - 62 return translated_text + 60 while str_len >= 0: + 61 translated_text = translated_text + encrypted_text_str[str_len] + 62 str_len = str_len - 1 63 - 64 - 65def get_cfbd_api_token(api_key_dir: str = None): - 66 """ - 67 If the CFBD API key exists in the environment, - 68 or is in a file, this function retrives the CFBD API key, - 69 and returns it as a string. - 70 - 71 If this package is being used in a GitHub Actions action, - 72 set the key in the environment by - 73 creating a repository secret nammed `CFBD_API_KEY`. - 74 - 75 Parameters - 76 ---------- - 77 `api_key_dir` (str, optional): - 78 Optional argument. If `api_key_dir` is set to a non-null string, - 79 `set_cfbd_api_token()` will attempt to save the key file in that directory, - 80 instead of this user's home directory. - 81 - 82 Returns - 83 ---------- - 84 A CFBD API key that exists within this python environment, - 85 or within this computer. - 86 """ - 87 # raise NotImplementedError('it ain\'t ready') - 88 - 89 try: - 90 key = os.environ['CFBD_API_KEY'] - 91 return key - 92 except: - 93 logging.info( - 94 "CFBD key not found in this python environment.\nAttempting to load the API key from a file.") - 95 - 96 if api_key_dir != None: - 97 with open(f"{api_key_dir}/.cfbd/cfbd.json", "r") as f: - 98 json_str = f.read() - 99 -100 json_data = json.loads(json_str) -101 -102 return_key = json_data['cfbd_api_token'] -103 return_key = reverse_cipher_decrypt(return_key) -104 return_key = return_key[10:] -105 return_key = return_key[:-10] -106 -107 del api_key_dir, json_str, json_data -108 -109 return return_key -110 else: -111 home_dir = os.path.expanduser('~') -112 -113 with open(f"{home_dir}/.cfbd/cfbd.json", "r") as f: -114 json_str = f.read() -115 -116 json_data = json.loads(json_str) -117 -118 return_key = json_data['cfbd_api_token'] -119 return_key = reverse_cipher_decrypt(return_key) -120 return_key = return_key[10:] -121 return_key = return_key[:-10] + 64 del encrypted_text_str + 65 + 66 return translated_text + 67 + 68 + 69def get_cfbd_api_token(api_key_dir: str = None): + 70 """ + 71 NOT INTENDED TO BE CALLED BY THE USER! + 72 + 73 If you've already set the API key using + 74 `cfbd_json_py.utls.set_cfbd_api_token()`, + 75 you don't need to use this function. + 76 + 77 If the CFBD API key exists in the environment, + 78 or is in a file, this function retrives the CFBD API key, + 79 and returns it as a string. + 80 + 81 If this package is being used in a GitHub Actions action, + 82 set the key in the environment by + 83 creating a repository secret nammed `CFBD_API_KEY`. + 84 + 85 Parameters + 86 ---------- + 87 `api_key_dir` (str, optional): + 88 Optional argument. If `api_key_dir` is set to a non-null string, + 89 `set_cfbd_api_token()` will attempt to save the key file in that directory, + 90 instead of this user's home directory. + 91 + 92 Returns + 93 ---------- + 94 A CFBD API key that exists within this python environment, + 95 or within this computer. + 96 """ + 97 # raise NotImplementedError('it ain\'t ready') + 98 + 99 try: +100 key = os.environ['CFBD_API_KEY'] +101 return key +102 except: +103 logging.info( +104 "CFBD key not found in this python environment.\nAttempting to load the API key from a file.") +105 +106 if api_key_dir != None: +107 with open(f"{api_key_dir}/.cfbd/cfbd.json", "r") as f: +108 json_str = f.read() +109 +110 json_data = json.loads(json_str) +111 +112 return_key = json_data['cfbd_api_token'] +113 return_key = reverse_cipher_decrypt(return_key) +114 return_key = return_key[10:] +115 return_key = return_key[:-10] +116 +117 del api_key_dir, json_str, json_data +118 +119 return return_key +120 else: +121 home_dir = os.path.expanduser('~') 122 -123 del api_key_dir, json_str, json_data -124 -125 return return_key -126 +123 with open(f"{home_dir}/.cfbd/cfbd.json", "r") as f: +124 json_str = f.read() +125 +126 json_data = json.loads(json_str) 127 -128def set_cfbd_api_token(api_key: str, api_key_dir: str = None): -129 """ -130 Sets the CFBD API key into a file that exists -131 either in `{home_dir}/.cfbd/cfbd_key.json`, or in a custom directory. +128 return_key = json_data['cfbd_api_token'] +129 return_key = reverse_cipher_decrypt(return_key) +130 return_key = return_key[10:] +131 return_key = return_key[:-10] 132 -133 Parameters -134 ---------- -135 `api_key` (str, mandatory): -136 The CFBD API key you have. -137 DO NOT input `Bearer {your CFBD API key}`, -138 this package will take care of that for you. -139 -140 `api_key_dir` (str, optional): -141 Optional argument. If `api_key_dir` is set to a non-null string, -142 `set_cfbd_api_token()` will attempt to save the key file in that directory, -143 instead of this user's home directory. -144 -145 Returns -146 ---------- -147 Nothing. -148 This function only sets up the API key file that this package can reference later. -149 """ -150 -151 alph_letters = [ -152 "a", -153 "b", -154 "c", -155 "d", -156 "e", -157 "f", -158 "g", -159 "h", -160 "i", -161 "j", -162 "k", -163 "l", -164 "m", -165 "n", -166 "o", -167 "p", -168 "q", -169 "r", -170 "s", -171 "t", -172 "u", -173 "v", -174 "w", -175 "x", -176 "y", -177 "z", -178 "0", -179 "1", -180 "2", -181 "3", -182 "4", -183 "5", -184 "6", -185 "7", -186 "8", -187 "9", -188 "A", -189 "B", -190 "C", -191 "D", -192 "E", -193 "F", -194 "G", -195 "H", -196 "I", -197 "J", -198 "K", -199 "L", -200 "M", -201 "N", -202 "O", -203 "P", -204 "Q", -205 "R", -206 "S", -207 "T", -208 "U", -209 "V", -210 "W", -211 "X", -212 "Y", -213 "Z", -214 ] -215 -216 front_hash = '' -217 back_hash = '' -218 -219 for i in range(0, 10): -220 r_str = secrets.choice(alph_letters) -221 front_hash += r_str -222 del r_str -223 -224 for i in range(0, 10): -225 r_str = secrets.choice(alph_letters) -226 back_hash += r_str -227 del r_str +133 del api_key_dir, json_str, json_data +134 +135 return return_key +136 +137 +138def set_cfbd_api_token(api_key: str, api_key_dir: str = None): +139 """ +140 Sets the CFBD API key into a file that exists +141 either in `{home_dir}/.cfbd/cfbd_key.json`, or in a custom directory. +142 +143 Parameters +144 ---------- +145 `api_key` (str, mandatory): +146 The CFBD API key you have. +147 DO NOT input `Bearer {your CFBD API key}`, +148 this package will take care of that for you. +149 +150 `api_key_dir` (str, optional): +151 Optional argument. If `api_key_dir` is set to a non-null string, +152 `set_cfbd_api_token()` will attempt to save the key file in that directory, +153 instead of this user's home directory. +154 +155 Returns +156 ---------- +157 Nothing. +158 This function only sets up the API key file that this package can reference later. +159 """ +160 +161 alph_letters = [ +162 "a", +163 "b", +164 "c", +165 "d", +166 "e", +167 "f", +168 "g", +169 "h", +170 "i", +171 "j", +172 "k", +173 "l", +174 "m", +175 "n", +176 "o", +177 "p", +178 "q", +179 "r", +180 "s", +181 "t", +182 "u", +183 "v", +184 "w", +185 "x", +186 "y", +187 "z", +188 "0", +189 "1", +190 "2", +191 "3", +192 "4", +193 "5", +194 "6", +195 "7", +196 "8", +197 "9", +198 "A", +199 "B", +200 "C", +201 "D", +202 "E", +203 "F", +204 "G", +205 "H", +206 "I", +207 "J", +208 "K", +209 "L", +210 "M", +211 "N", +212 "O", +213 "P", +214 "Q", +215 "R", +216 "S", +217 "T", +218 "U", +219 "V", +220 "W", +221 "X", +222 "Y", +223 "Z", +224 ] +225 +226 front_hash = '' +227 back_hash = '' 228 -229 encrypted_key = reverse_cipher_encrypt(api_key) -230 -231 json_str = f"{{\n\t\"cfbd_api_token\":\"{front_hash}{encrypted_key}{back_hash}\"\n}}" -232 del encrypted_key -233 # print(json_str) -234 -235 if api_key_dir != None: -236 try: -237 os.mkdir(f"{api_key_dir}/.cfbd") -238 except: -239 pass +229 for i in range(0, 10): +230 r_str = secrets.choice(alph_letters) +231 front_hash += r_str +232 del r_str +233 +234 for i in range(0, 10): +235 r_str = secrets.choice(alph_letters) +236 back_hash += r_str +237 del r_str +238 +239 encrypted_key = reverse_cipher_encrypt(api_key) 240 -241 with open(f"{api_key_dir}/.cfbd/cfbd.json", "w+") as f: -242 f.write(json_str) -243 else: -244 home_dir = os.path.expanduser('~') -245 +241 json_str = f"{{\n\t\"cfbd_api_token\":\"{front_hash}{encrypted_key}{back_hash}\"\n}}" +242 del encrypted_key +243 # print(json_str) +244 +245 if api_key_dir != None: 246 try: -247 os.mkdir(f"{home_dir}/.cfbd") +247 os.mkdir(f"{api_key_dir}/.cfbd") 248 except: 249 pass 250 -251 with open(f"{home_dir}/.cfbd/cfbd.json", "w+") as f: +251 with open(f"{api_key_dir}/.cfbd/cfbd.json", "w+") as f: 252 f.write(json_str) -253 -254 del json_str +253 else: +254 home_dir = os.path.expanduser('~') 255 -256 -257# if __name__ == "__main__": -258# text = "Hello World" -259# e_text = reverse_cipher_encrypt(text) -260# ue_text = reverse_cipher_decrypt(e_text) -261 -262# print(f"Original Text:\t{text}") -263# print(f"Encrypted Text:\t{e_text}") -264# print(f"Decrypted Text:\t{ue_text}") +256 try: +257 os.mkdir(f"{home_dir}/.cfbd") +258 except: +259 pass +260 +261 with open(f"{home_dir}/.cfbd/cfbd.json", "w+") as f: +262 f.write(json_str) +263 +264 del json_str 265 -266# print(f'remove first 2 characters from string: {text[2:]}') -267# print(f'remove last 2 characters from string: {text[:-2]}') -268 -269# key = "hello world" -270# set_cfbd_api_token(key) -271# return_key = get_cfbd_api_token() -272# print(key) -273# print(return_key) +266 +267# if __name__ == "__main__": +268# text = "Hello World" +269# e_text = reverse_cipher_encrypt(text) +270# ue_text = reverse_cipher_decrypt(e_text) +271 +272# print(f"Original Text:\t{text}") +273# print(f"Encrypted Text:\t{e_text}") +274# print(f"Decrypted Text:\t{ue_text}") +275 +276# print(f'remove first 2 characters from string: {text[2:]}') +277# print(f'remove last 2 characters from string: {text[:-2]}') +278 +279# key = "hello world" +280# set_cfbd_api_token(key) +281# return_key = get_cfbd_api_token() +282# print(key) +283# print(return_key)
-15def reverse_cipher_encrypt(plain_text_str: str): 16 """ -17 Implements a reverse cipher encription to a plain text string. +17 NOT INTENDED TO BE CALLED BY THE USER! 18 -19 Parameters -20 ---------- -21 `plain_text_str` (mandatory, str): -22 The string you want to encrypt through reverse cipher encryption. -23 -24 Returns -25 ---------- -26 A string encrypted through reverse cipher encryption. -27 """ -28 translated_text = '' -29 str_len = len(plain_text_str) - 1 -30 while str_len >= 0: -31 translated_text = translated_text + plain_text_str[str_len] -32 str_len = str_len - 1 -33 -34 del plain_text_str +19 Implements a reverse cipher encription to a plain text string. +20 +21 Parameters +22 ---------- +23 `plain_text_str` (mandatory, str): +24 The string you want to encrypt through reverse cipher encryption. +25 +26 Returns +27 ---------- +28 A string encrypted through reverse cipher encryption. +29 """ +30 translated_text = '' +31 str_len = len(plain_text_str) - 1 +32 while str_len >= 0: +33 translated_text = translated_text + plain_text_str[str_len] +34 str_len = str_len - 1 35 -36 return translated_text +36 del plain_text_str +37 +38 return translated_textImplements a reverse cipher encription to a plain text string.
+-NOT INTENDED TO BE CALLED BY THE USER!
+ +Implements a reverse cipher encription to a plain text string.
Parameters
@@ -401,35 +415,39 @@Returns
39def reverse_cipher_decrypt(encrypted_text_str: str): -40 """ -41 Decrypts a string that was presumed to be encrypted by a reverse cipher encryption. -42 -43 Parameters -44 ---------- -45 `encrypted_text_str` (mandatory, str): -46 The string you presume that is encrypted through reverse cipher encryption, -47 that you want decrypted. -48 -49 Returns -50 ---------- -51 A decrypted string. +-41def reverse_cipher_decrypt(encrypted_text_str: str): +42 """ +43 NOT INTENDED TO BE CALLED BY THE USER! +44 +45 Decrypts a string that was presumed to be encrypted by a reverse cipher encryption. +46 +47 Parameters +48 ---------- +49 `encrypted_text_str` (mandatory, str): +50 The string you presume that is encrypted through reverse cipher encryption, +51 that you want decrypted. 52 -53 """ -54 translated_text = '' -55 str_len = len(encrypted_text_str) - 1 +53 Returns +54 ---------- +55 A decrypted string. 56 -57 while str_len >= 0: -58 translated_text = translated_text + encrypted_text_str[str_len] -59 str_len = str_len - 1 +57 """ +58 translated_text = '' +59 str_len = len(encrypted_text_str) - 1 60 -61 del encrypted_text_str -62 -63 return translated_text +61 while str_len >= 0: +62 translated_text = translated_text + encrypted_text_str[str_len] +63 str_len = str_len - 1 +64 +65 del encrypted_text_str +66 +67 return translated_textDecrypts a string that was presumed to be encrypted by a reverse cipher encryption.
+-NOT INTENDED TO BE CALLED BY THE USER!
+ +Decrypts a string that was presumed to be encrypted by a reverse cipher encryption.
Parameters
@@ -455,71 +473,83 @@Returns
66def get_cfbd_api_token(api_key_dir: str = None): - 67 """ - 68 If the CFBD API key exists in the environment, - 69 or is in a file, this function retrives the CFBD API key, - 70 and returns it as a string. - 71 - 72 If this package is being used in a GitHub Actions action, - 73 set the key in the environment by - 74 creating a repository secret nammed `CFBD_API_KEY`. - 75 - 76 Parameters - 77 ---------- - 78 `api_key_dir` (str, optional): - 79 Optional argument. If `api_key_dir` is set to a non-null string, - 80 `set_cfbd_api_token()` will attempt to save the key file in that directory, - 81 instead of this user's home directory. - 82 - 83 Returns - 84 ---------- - 85 A CFBD API key that exists within this python environment, - 86 or within this computer. - 87 """ - 88 # raise NotImplementedError('it ain\'t ready') - 89 - 90 try: - 91 key = os.environ['CFBD_API_KEY'] - 92 return key - 93 except: - 94 logging.info( - 95 "CFBD key not found in this python environment.\nAttempting to load the API key from a file.") - 96 - 97 if api_key_dir != None: - 98 with open(f"{api_key_dir}/.cfbd/cfbd.json", "r") as f: - 99 json_str = f.read() -100 -101 json_data = json.loads(json_str) -102 -103 return_key = json_data['cfbd_api_token'] -104 return_key = reverse_cipher_decrypt(return_key) -105 return_key = return_key[10:] -106 return_key = return_key[:-10] -107 -108 del api_key_dir, json_str, json_data -109 -110 return return_key -111 else: -112 home_dir = os.path.expanduser('~') -113 -114 with open(f"{home_dir}/.cfbd/cfbd.json", "r") as f: -115 json_str = f.read() -116 -117 json_data = json.loads(json_str) -118 -119 return_key = json_data['cfbd_api_token'] -120 return_key = reverse_cipher_decrypt(return_key) -121 return_key = return_key[10:] -122 return_key = return_key[:-10] +-70def get_cfbd_api_token(api_key_dir: str = None): + 71 """ + 72 NOT INTENDED TO BE CALLED BY THE USER! + 73 + 74 If you've already set the API key using + 75 `cfbd_json_py.utls.set_cfbd_api_token()`, + 76 you don't need to use this function. + 77 + 78 If the CFBD API key exists in the environment, + 79 or is in a file, this function retrives the CFBD API key, + 80 and returns it as a string. + 81 + 82 If this package is being used in a GitHub Actions action, + 83 set the key in the environment by + 84 creating a repository secret nammed `CFBD_API_KEY`. + 85 + 86 Parameters + 87 ---------- + 88 `api_key_dir` (str, optional): + 89 Optional argument. If `api_key_dir` is set to a non-null string, + 90 `set_cfbd_api_token()` will attempt to save the key file in that directory, + 91 instead of this user's home directory. + 92 + 93 Returns + 94 ---------- + 95 A CFBD API key that exists within this python environment, + 96 or within this computer. + 97 """ + 98 # raise NotImplementedError('it ain\'t ready') + 99 +100 try: +101 key = os.environ['CFBD_API_KEY'] +102 return key +103 except: +104 logging.info( +105 "CFBD key not found in this python environment.\nAttempting to load the API key from a file.") +106 +107 if api_key_dir != None: +108 with open(f"{api_key_dir}/.cfbd/cfbd.json", "r") as f: +109 json_str = f.read() +110 +111 json_data = json.loads(json_str) +112 +113 return_key = json_data['cfbd_api_token'] +114 return_key = reverse_cipher_decrypt(return_key) +115 return_key = return_key[10:] +116 return_key = return_key[:-10] +117 +118 del api_key_dir, json_str, json_data +119 +120 return return_key +121 else: +122 home_dir = os.path.expanduser('~') 123 -124 del api_key_dir, json_str, json_data -125 -126 return return_key +124 with open(f"{home_dir}/.cfbd/cfbd.json", "r") as f: +125 json_str = f.read() +126 +127 json_data = json.loads(json_str) +128 +129 return_key = json_data['cfbd_api_token'] +130 return_key = reverse_cipher_decrypt(return_key) +131 return_key = return_key[10:] +132 return_key = return_key[:-10] +133 +134 del api_key_dir, json_str, json_data +135 +136 return return_keyIf the CFBD API key exists in the environment, +
-NOT INTENDED TO BE CALLED BY THE USER!
+ +If you've already set the API key using +
+ +set_cfbd_api_token()
, +you don't need to use this function.If the CFBD API key exists in the environment, or is in a file, this function retrives the CFBD API key, and returns it as a string.
@@ -553,133 +583,133 @@Returns
129def set_cfbd_api_token(api_key: str, api_key_dir: str = None): -130 """ -131 Sets the CFBD API key into a file that exists -132 either in `{home_dir}/.cfbd/cfbd_key.json`, or in a custom directory. -133 -134 Parameters -135 ---------- -136 `api_key` (str, mandatory): -137 The CFBD API key you have. -138 DO NOT input `Bearer {your CFBD API key}`, -139 this package will take care of that for you. -140 -141 `api_key_dir` (str, optional): -142 Optional argument. If `api_key_dir` is set to a non-null string, -143 `set_cfbd_api_token()` will attempt to save the key file in that directory, -144 instead of this user's home directory. -145 -146 Returns -147 ---------- -148 Nothing. -149 This function only sets up the API key file that this package can reference later. -150 """ -151 -152 alph_letters = [ -153 "a", -154 "b", -155 "c", -156 "d", -157 "e", -158 "f", -159 "g", -160 "h", -161 "i", -162 "j", -163 "k", -164 "l", -165 "m", -166 "n", -167 "o", -168 "p", -169 "q", -170 "r", -171 "s", -172 "t", -173 "u", -174 "v", -175 "w", -176 "x", -177 "y", -178 "z", -179 "0", -180 "1", -181 "2", -182 "3", -183 "4", -184 "5", -185 "6", -186 "7", -187 "8", -188 "9", -189 "A", -190 "B", -191 "C", -192 "D", -193 "E", -194 "F", -195 "G", -196 "H", -197 "I", -198 "J", -199 "K", -200 "L", -201 "M", -202 "N", -203 "O", -204 "P", -205 "Q", -206 "R", -207 "S", -208 "T", -209 "U", -210 "V", -211 "W", -212 "X", -213 "Y", -214 "Z", -215 ] -216 -217 front_hash = '' -218 back_hash = '' -219 -220 for i in range(0, 10): -221 r_str = secrets.choice(alph_letters) -222 front_hash += r_str -223 del r_str -224 -225 for i in range(0, 10): -226 r_str = secrets.choice(alph_letters) -227 back_hash += r_str -228 del r_str +diff --git a/docs/cfbd_json_py/venues.html b/docs/cfbd_json_py/venues.html index 7667240..ab134c0 100644 --- a/docs/cfbd_json_py/venues.html +++ b/docs/cfbd_json_py/venues.html @@ -55,7 +55,7 @@139def set_cfbd_api_token(api_key: str, api_key_dir: str = None): +140 """ +141 Sets the CFBD API key into a file that exists +142 either in `{home_dir}/.cfbd/cfbd_key.json`, or in a custom directory. +143 +144 Parameters +145 ---------- +146 `api_key` (str, mandatory): +147 The CFBD API key you have. +148 DO NOT input `Bearer {your CFBD API key}`, +149 this package will take care of that for you. +150 +151 `api_key_dir` (str, optional): +152 Optional argument. If `api_key_dir` is set to a non-null string, +153 `set_cfbd_api_token()` will attempt to save the key file in that directory, +154 instead of this user's home directory. +155 +156 Returns +157 ---------- +158 Nothing. +159 This function only sets up the API key file that this package can reference later. +160 """ +161 +162 alph_letters = [ +163 "a", +164 "b", +165 "c", +166 "d", +167 "e", +168 "f", +169 "g", +170 "h", +171 "i", +172 "j", +173 "k", +174 "l", +175 "m", +176 "n", +177 "o", +178 "p", +179 "q", +180 "r", +181 "s", +182 "t", +183 "u", +184 "v", +185 "w", +186 "x", +187 "y", +188 "z", +189 "0", +190 "1", +191 "2", +192 "3", +193 "4", +194 "5", +195 "6", +196 "7", +197 "8", +198 "9", +199 "A", +200 "B", +201 "C", +202 "D", +203 "E", +204 "F", +205 "G", +206 "H", +207 "I", +208 "J", +209 "K", +210 "L", +211 "M", +212 "N", +213 "O", +214 "P", +215 "Q", +216 "R", +217 "S", +218 "T", +219 "U", +220 "V", +221 "W", +222 "X", +223 "Y", +224 "Z", +225 ] +226 +227 front_hash = '' +228 back_hash = '' 229 -230 encrypted_key = reverse_cipher_encrypt(api_key) -231 -232 json_str = f"{{\n\t\"cfbd_api_token\":\"{front_hash}{encrypted_key}{back_hash}\"\n}}" -233 del encrypted_key -234 # print(json_str) -235 -236 if api_key_dir != None: -237 try: -238 os.mkdir(f"{api_key_dir}/.cfbd") -239 except: -240 pass +230 for i in range(0, 10): +231 r_str = secrets.choice(alph_letters) +232 front_hash += r_str +233 del r_str +234 +235 for i in range(0, 10): +236 r_str = secrets.choice(alph_letters) +237 back_hash += r_str +238 del r_str +239 +240 encrypted_key = reverse_cipher_encrypt(api_key) 241 -242 with open(f"{api_key_dir}/.cfbd/cfbd.json", "w+") as f: -243 f.write(json_str) -244 else: -245 home_dir = os.path.expanduser('~') -246 +242 json_str = f"{{\n\t\"cfbd_api_token\":\"{front_hash}{encrypted_key}{back_hash}\"\n}}" +243 del encrypted_key +244 # print(json_str) +245 +246 if api_key_dir != None: 247 try: -248 os.mkdir(f"{home_dir}/.cfbd") +248 os.mkdir(f"{api_key_dir}/.cfbd") 249 except: 250 pass 251 -252 with open(f"{home_dir}/.cfbd/cfbd.json", "w+") as f: +252 with open(f"{api_key_dir}/.cfbd/cfbd.json", "w+") as f: 253 f.write(json_str) -254 -255 del json_str +254 else: +255 home_dir = os.path.expanduser('~') +256 +257 try: +258 os.mkdir(f"{home_dir}/.cfbd") +259 except: +260 pass +261 +262 with open(f"{home_dir}/.cfbd/cfbd.json", "w+") as f: +263 f.write(json_str) +264 +265 del json_str
1# Creation Date: 08/30/2023 01:13 EDT - 2# Last Updated Date: 10/06/2023 07:54 PM EDT + 2# Last Updated Date: 10/15/2023 06:57 PM EDT 3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com) 4# File Name: venues.py 5# Purpose: Houses functions pertaining to CFB team venues/stadium data within the CFBD API. diff --git a/docs/search.js b/docs/search.js index f0b526e..9f1eb0f 100644 --- a/docs/search.js +++ b/docs/search.js @@ -1,6 +1,6 @@ window.pdocSearch = (function(){ /** elasticlunr - http://weixsong.github.io * Copyright (C) 2017 Oliver Nightingale * Copyright (C) 2017 Wei Song * MIT Licensed */!function(){function e(e){if(null===e||"object"!=typeof e)return e;var t=e.constructor();for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.9.5",lunr=t,t.utils={},t.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),t.utils.toString=function(e){return void 0===e||null===e?"":e.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new TypeError("last argument must be a function");n.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},t.EventEmitter.prototype.removeListener=function(e,t){if(this.hasHandler(e)){var n=this.events[e].indexOf(t);-1!==n&&(this.events[e].splice(n,1),0==this.events[e].length&&delete this.events[e])}},t.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){var t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)},this)}},t.EventEmitter.prototype.hasHandler=function(e){return e in this.events},t.tokenizer=function(e){if(!arguments.length||null===e||void 0===e)return[];if(Array.isArray(e)){var n=e.filter(function(e){return null===e||void 0===e?!1:!0});n=n.map(function(e){return t.utils.toString(e).toLowerCase()});var i=[];return n.forEach(function(e){var n=e.split(t.tokenizer.seperator);i=i.concat(n)},this),i}return e.toString().trim().toLowerCase().split(t.tokenizer.seperator)},t.tokenizer.defaultSeperator=/[\s\-]+/,t.tokenizer.seperator=t.tokenizer.defaultSeperator,t.tokenizer.setSeperator=function(e){null!==e&&void 0!==e&&"object"==typeof e&&(t.tokenizer.seperator=e)},t.tokenizer.resetSeperator=function(){t.tokenizer.seperator=t.tokenizer.defaultSeperator},t.tokenizer.getSeperator=function(){return t.tokenizer.seperator},t.Pipeline=function(){this._queue=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in t.Pipeline.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[n]=e},t.Pipeline.getRegisteredFunction=function(e){return e in t.Pipeline.registeredFunctions!=!0?null:t.Pipeline.registeredFunctions[e]},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.getRegisteredFunction(e);if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i+1,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i,0,n)},t.Pipeline.prototype.remove=function(e){var t=this._queue.indexOf(e);-1!==t&&this._queue.splice(t,1)},t.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,i=this._queue.length,o=0;n>o;o++){for(var r=e[o],s=0;i>s&&(r=this._queue[s](r,o,e),void 0!==r&&null!==r);s++);void 0!==r&&null!==r&&t.push(r)}return t},t.Pipeline.prototype.reset=function(){this._queue=[]},t.Pipeline.prototype.get=function(){return this._queue},t.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.DocumentStore,this.index={},this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},t.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;n._fields=e.fields,n._ref=e.ref,n.documentStore=t.DocumentStore.load(e.documentStore),n.pipeline=t.Pipeline.load(e.pipeline),n.index={};for(var i in e.index)n.index[i]=t.InvertedIndex.load(e.index[i]);return n},t.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new t.InvertedIndex,this},t.Index.prototype.setRef=function(e){return this._ref=e,this},t.Index.prototype.saveDocument=function(e){return this.documentStore=new t.DocumentStore(e),this},t.Index.prototype.addDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.addDoc(i,e),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));this.documentStore.addFieldLength(i,n,o.length);var r={};o.forEach(function(e){e in r?r[e]+=1:r[e]=1},this);for(var s in r){var u=r[s];u=Math.sqrt(u),this.index[n].addToken(s,{ref:i,tf:u})}},this),n&&this.eventEmitter.emit("add",e,this)}},t.Index.prototype.removeDocByRef=function(e){if(e&&this.documentStore.isDocStored()!==!1&&this.documentStore.hasDoc(e)){var t=this.documentStore.getDoc(e);this.removeDoc(t,!1)}},t.Index.prototype.removeDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.hasDoc(i)&&(this.documentStore.removeDoc(i),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));o.forEach(function(e){this.index[n].removeToken(e,i)},this)},this),n&&this.eventEmitter.emit("remove",e,this))}},t.Index.prototype.updateDoc=function(e,t){var t=void 0===t?!0:t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},t.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];var i=this.index[t].getDocFreq(e),o=1+Math.log(this.documentStore.length/(i+1));return this._idfCache[n]=o,o},t.Index.prototype.getFields=function(){return this._fields.slice()},t.Index.prototype.search=function(e,n){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var i=null;null!=n&&(i=JSON.stringify(n));for(var o=new t.Configuration(i,this.getFields()).get(),r={},s=Object.keys(e),u=0;u0&&t.push(e);for(var i in n)"docs"!==i&&"df"!==i&&this.expandToken(e+i,t,n[i]);return t},t.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},t.Configuration=function(e,n){var e=e||"";if(void 0==n||null==n)throw new Error("fields should not be null");this.config={};var i;try{i=JSON.parse(e),this.buildUserConfig(i,n)}catch(o){t.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(n)}},t.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},t.Configuration.prototype.buildUserConfig=function(e,n){var i="OR",o=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(o=e.expand||o),"fields"in e)for(var r in e.fields)if(n.indexOf(r)>-1){var s=e.fields[r],u=o;void 0!=s.expand&&(u=s.expand),this.config[r]={boost:s.boost||0===s.boost?s.boost:1,bool:s.bool||i,expand:u}}else t.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,o,n)},t.Configuration.prototype.addAllFields2UserConfig=function(e,t,n){n.forEach(function(n){this.config[n]={boost:1,bool:e,expand:t}},this)},t.Configuration.prototype.get=function(){return this.config},t.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){var e,t;for(e=0;e 1;){if(r===e)return o;e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o]}return r===e?o:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;)e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o];return r>e?o:e>r?o+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,i=0,o=this.length,r=e.length,s=this.elements,u=e.elements;;){if(n>o-1||i>r-1)break;s[n]!==u[i]?s[n]u[i]&&i++:(t.add(s[n]),n++,i++)}return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var o=0,r=n.toArray();o \n"}, {"fullname": "cfbd_json_py.betting", "modulename": "cfbd_json_py.betting", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.betting.get_cfbd_betting_lines", "modulename": "cfbd_json_py.betting", "qualname": "get_cfbd_betting_lines", "kind": "function", "doc": " Retrives betting information from the CFBD API for a given season, \nor you could only get betting information for a single game.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n The season you want to retrive betting information from.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
game_id
(int, optional):\n Optional argument. \n Ifgame_id
is set to a game ID,get_cfb_betting_lines()
will try to get \n all betting informaiton for that game ID.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load betting data from games in that season, and that week.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want postseason betting data, setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
team
(str, optional):\n Optional argument.\n If you only want betting information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want game-level betting data from.\n\n
home_team
(str, optional):\n Optional argument.\n If you only want betting information for a team, \n where that team was the home team in this season,\n sethome_team
to the name of the team you want game-level betting data from.\n\n
away_team
(str, optional):\n Optional argument.\n If you only want betting information for a team, \n where that team was the away team in this season,\n setaway_team
to the name of the team you want game-level betting data from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want betting information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want betting informaiton from.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.betting import get_cfbd_betting_lines\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets all available betting info for the 2020 CFB season.\n print(\"Gets all available betting info for the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Gets all available betting info for the 2020 CFB season, in week 2.\n print(\"Gets all available betting info for the 2020 CFB season, in week 2.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n week=2\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\n print(\"Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\n print(\"Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\n print(\"Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n home_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\n print(\"Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n away_team=\"Ohio State\"\n )\n\n # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\n print(\"Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets all available betting info for the 2020 CFB season.\n print(\"Gets all available betting info for the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n # Gets all available betting info for the 2020 CFB season, in week 2.\n print(\"Gets all available betting info for the 2020 CFB season, in week 2.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n week=2\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\n print(\"Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\n print(\"Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\n print(\"Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n home_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\n print(\"Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n\n season=2020,\n away_team=\"Ohio State\"\n )\n\n # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\n print(\"Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tgame_id: int = None,\tweek: int = None,\tseason_type: str = 'regular',\tteam: str = None,\thome_team: str = None,\taway_team: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.coaches", "modulename": "cfbd_json_py.coaches", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.coaches.get_cfbd_coaches_info", "modulename": "cfbd_json_py.coaches", "qualname": "get_cfbd_coaches_info", "kind": "function", "doc": "DataFrame
object with college football betting data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football betting data.Retrives information from the CFBD API on CFB Head Coaches.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
first_name
(str, optional):\n Optional argument.\n If you want to only look up coaches with a specific first name, \n set this variable to that specific first name, and this function \n will attempt to look up coaches with that specific first name.\n\n
last_name
(str, optional):\n Optional argument.\n If you want to only look up coaches with a specific last name, \n set this variable to that specific first name, and this function \n will attempt to look up coaches with that specific last name.\n\n
team
(str, optional):\n Optional argument.\n If you want to filter and drill down to coaches who coached a specific\n CFB team, set this\n\n
season
(int, optional):\n Optional argument.\n If you only want coaches from a specific season, set this variable to that season.\n\n
min_season
(int, optional):\n Optional argument.\n Similar toyear
, but used in tandem withmax_season
to get coaches who coached with in a range of seasons.\n\n
max_season
(int, optional):\n Optional argument.\n Similar toyear
, but used in tandem withmin_season
to get coaches who coached with in a range of seasons.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.coaches import get_cfbd_coaches_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Getting all coaches in the 2020 CFB season\n print(\"Getting every coach in the 2020 CFB season.\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n # Getting all coaches in the 2020 CFB season, with a first name of \"Luke\"\n print(\"Getting every coach in the 2020 CFB season, with a first name of \"Luke\".\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020,\n first_name=\"Luke\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting all coaches in the 2020 CFB season, with a last name of \"Day\"\n print(\"Getting all coaches in the 2020 CFB season, with a last name of \"Day\".\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020,\n last_name=\"Day\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach for the 2020 Southern Mississippi Golden Eagles\n print(\"Getting every head coach for the 2020 Southern Mississippi Golden Eagles.\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020,\n team=\"Southern Mississippi\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach between the 2019 and 2022 CFB seasons\n print(\"Getting every head coach between the 2019 and 2022 CFB seasons\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n min_season=2019,\n max_season=2022\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2022,\n team=\"Cincinnati\",\n return_as_dict=True\n )\n print(f\"{json_data}\")\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Getting every coach in the 2020 CFB season.\n print(\"Getting every coach in the 2020 CFB season.\")\n json_data = get_cfbd_coaches_info(season=2020)\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every coach in the 2020 CFB season, with a first name of \"Luke\".\n print(\"Getting every coach in the 2020 CFB season, with a first name of \"Luke\".\")\n json_data = get_cfbd_coaches_info(\n season=2020,\n first_name=\"Luke\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every coach in the 2020 CFB season, with a last name of \"Day\".\n print(\"Getting every coach in the 2020 CFB season, with a last name of \"Day\".\")\n json_data = get_cfbd_coaches_info(\n season=2020,\n last_name=\"Day\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach for the 2020 Southern Mississippi Golden Eagles.\n print(\"Getting every head coach for the 2020 Southern Mississippi Golden Eagles.\")\n json_data = get_cfbd_coaches_info(\n season=2020,\n team=\"Southern Mississippi\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach between the 2019 and 2022 CFB seasons.\n print(\"Getting every head coach between the 2019 and 2022 CFB seasons.\")\n json_data = get_cfbd_coaches_info(\n min_season=2019,\n max_season=2022\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_coaches_info(\n season=2022,\n team=\"Cincinnati\",\n return_as_dict=True\n )\n print(f\"{json_data}\")\n\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tfirst_name: str = None,\tlast_name: str = None,\tteam: str = None,\tseason: int = None,\tmin_season: int = None,\tmax_season: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.conferences", "modulename": "cfbd_json_py.conferences", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.conferences.get_cfbd_conference_info", "modulename": "cfbd_json_py.conferences", "qualname": "get_cfbd_conference_info", "kind": "function", "doc": "DataFrame
object with CFB head coach data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with CFB head coach data.Retrives a list of CFB conferences from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.conferences import get_cfbd_conference_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets CFB confrence info from the CFBD API.\n print(\"Gets CFB confrence info from the CFBD API.\")\n json_data = get_cfbd_conference_info(api_key=cfbd_key)\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_conference_info(\n api_key=cfbd_key,\n return_as_dict=True)\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets CFB confrence info from the CFBD API.\n print(\"Gets CFB confrence info from the CFBD API.\")\n json_data = get_cfbd_conference_info()\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_conference_info(return_as_dict=True)\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.draft", "modulename": "cfbd_json_py.draft", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.draft.get_cfbd_nfl_teams", "modulename": "cfbd_json_py.draft", "qualname": "get_cfbd_nfl_teams", "kind": "function", "doc": "DataFrame
object with CFB conference data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with CFB conference data.Retrives a list of NFL teams from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.draft import get_cfbd_nfl_teams\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets NFL team info from the CFBD API.\n print(\"Gets NFL team info from the CFBD API.\")\n json_data = get_cfbd_nfl_teams(api_key=cfbd_key)\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_teams(\n api_key=cfbd_key,\n return_as_dict=True)\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets NFL team info from the CFBD API.\n print(\"Gets NFL team info from the CFBD API.\")\n json_data = get_cfbd_nfl_teams()\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_teams(return_as_dict=True)\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.draft.get_cfbd_nfl_positions", "modulename": "cfbd_json_py.draft", "qualname": "get_cfbd_nfl_positions", "kind": "function", "doc": "DataFrame
object with NFL team data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with NFL team data.Retrives a list of player positions for the NFL Draft from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.draft import get_cfbd_nfl_positions\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets a list of player positions for the NFL Draft from the CFBD API.\n print(\"Gets a list of player positions for the NFL Draft from the CFBD API.\")\n json_data = get_cfbd_nfl_positions(api_key=cfbd_key)\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_positions(\n api_key=cfbd_key,\n return_as_dict=True)\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets a list of player positions for the NFL Draft from the CFBD API.\n print(\"Gets a list of player positions for the NFL Draft from the CFBD API.\")\n json_data = get_cfbd_nfl_positions()\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_positions(return_as_dict=True)\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.draft.get_cfbd_nfl_draft_info", "modulename": "cfbd_json_py.draft", "qualname": "get_cfbd_nfl_draft_info", "kind": "function", "doc": "DataFrame
object with player position data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with player position data.Retrives a list of actual NFL Draft selections from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.The following paramaters are optional, but it is highly reccomended to not call this function\nwithiout settting one of these five optional paramaters to a non-null value.
\n\n\n\n
season
(int, semi-optional):\n Semi-Optional argument. \n This is the season you want NFL Draft information for. For example, if you only want \n data for the 2020 NFL Draft, setseason
to2020
.\n\n
nfl_team
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections from a specific NFL team, setnfl_team
to the \n name of that team. For example, if you want to only get NFL Draft information for \n draft picks made by the Cincinnati Bengals, setnfl_team
toCincinnati
.\n\n
college
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections from a specific CFB team, setcollege
to the \n name of that team. For example, if you want to only get NFL Draft information for \n draft picks from the Clemson Tigers Football Program, setcollege
toClemson
.\n\n
conference
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections from a specific CFB confrence, setconference
to the abbreviation of that confrence. \n A list of CFBD API confrence abbreviations can be found in theconference_abbreviation
column from \n the pandas DataFrame that is returned by callingcfbd_json_py.conferences.get_cfbd_conference_info()
.\n For example, if you want to only get NFL Draft information for \n draft picks that played in the Big 12, setconfrence
toB12
.\n\n
position
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections who played a specific position, \n setposition
to that position's abbreviation. \n A list of CFBD API positions can be found in theposition_abbreviation
column from \n the pandas DataFrame that is returned by callingcfbd_json_py.draft.get_cfbd_nfl_positions()
.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.draft import get_cfbd_nfl_draft_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get NFL Draft selections from the 2020 NFL Draft.\n print(\"Get NFL Draft selections from the 2020 NFL Draft.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made by the\n # 2020 Cincinnati Bengals.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n nfl_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # Clemson Tigers football players.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n college=\"Clemson\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # players who played in the Southeastern Confrence (SEC).\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n conference=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made\n # where the selected player was a QB in college.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n position=\"QB\",\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get NFL Draft selections from the 2020 NFL Draft.\n print(\"Get NFL Draft selections from the 2020 NFL Draft.\")\n json_data = get_cfbd_nfl_draft_info(season=2020)\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made by the\n # 2020 Cincinnati Bengals.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n nfl_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # Clemson Tigers football players.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n college=\"Clemson\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # players who played in the Southeastern Confrence (SEC).\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n conference=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made\n # where the selected player was a QB in college.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n position=\"QB\",\n return_as_dict=True\n )\n print(json_data)\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tnfl_team: str = None,\tcollege: str = None,\tconference_abv: str = None,\tposition: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.drives", "modulename": "cfbd_json_py.drives", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.drives.get_cfbd_drives_info", "modulename": "cfbd_json_py.drives", "qualname": "get_cfbd_drives_info", "kind": "function", "doc": "DataFrame
object with NFL Draft selection data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with NFL Draft selection data.Retrives a list of CFB drives from the CFBD API.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB drive information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB drive information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB drive data for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB drive data from games in that season, and that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB drive data for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB drive data from.\n\n
offensive_team
(str, optional):\n Optional argument.\n If you only want CFB drive data from a team, while they are on offense, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB drive data from.\n\n
defensive_team
(str, optional):\n Optional argument.\n If you only want CFB drive data from a team, while they are on defense,\n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB drive data from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want CFB drive data from games \n involving teams from a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want CFB drive data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
offensive_conference_abv
(str, optional):\n Optional argument.\n If you only want CFB drive data from games \n where the offensive team is from a specific confrenece,\n setconference_abv
to the abbreviation \n of the conference you want CFB drive data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
defensive_conference_abv
(str, optional):\n Optional argument.\n If you only want CFB drive data from games \n where the defensive team is from a specific confrenece,\n setconference_abv
to the abbreviation \n of the conference you want CFB drive data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
ncaa_division
(str, semi-optional):\n Semi-optional argument.\n By default,ncaa_division
will be set to \"fbs\", \n short for the Football Bowl Subdivision (FBS), \n formerly known as D1-A (read as \"division one single A\"),\n the highest level in the NCAA football pyramid,\n where teams can scolarship up to 85 players \n on their football team soley for athletic ability, \n and often have the largest athletics budgets\n within the NCAA.\n\nOther valid inputs are:\n- \"fcs\": Football Championship Subdivision (FCS), \n formerly known as D1-AA (read as \"division one double A\").\n An FCS school is still in the 1st division of the NCAA,\n making them elligable for the March Madness tournament,\n but may not have the resources to compete at the FBS level\n at this time. FCS schools are limited to 63 athletic scolarships\n for football.\n- \"ii\": NCAA Division II. Schools in this and D3 are not\n elligable for the March Madness tournament, \n and are limited to 36 athletic scolarships for their football team.\n- \"iii\": NCAA Division III. The largest single division within the \n NCAA football pyramid. \n D3 schools have the distinction of being part of \n the only NCAA division that cannot give out scolarships soley \n for athletic ability.\n
\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.drives import get_cfbd_drives_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get CFB Drive data from the 2020 CFB season.\n print(\"Get CFB Drive data from the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from week 10 of the 2020 CFB season.\n print(\"Get CFB Drive data from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats\n # Football Team.\n print(\"Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio Bobcats\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n offensive_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n defensive_team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 12 games in the 2020 CFB season.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"B12\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,\n # where the Big 10 team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n offensive_conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Mid-American Conference (MAC) games\n # in the 2020 CFB season, where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n defensive_conference_abv=\"MAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Football Championship Subdivision (FCS) games\n # in week 3 ofthe 2020 CFB season,\n # where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n week=3,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get CFB Drive data from the 2020 CFB season.\n print(\"Get CFB Drive data from the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from week 10 of the 2020 CFB season.\n print(\"Get CFB Drive data from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats\n # Football Team.\n print(\"Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio Bobcats\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n offensive_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n defensive_team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 12 games in the 2020 CFB season.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n conference_abv=\"B12\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,\n # where the Big 10 team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n offensive_conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Mid-American Conference (MAC) games\n # in the 2020 CFB season, where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n defensive_conference_abv=\"MAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Football Championship Subdivision (FCS) games\n # in week 3 ofthe 2020 CFB season,\n # where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=3,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\toffensive_team: str = None,\tdefensive_team: str = None,\tconference_abv: str = None,\toffensive_conference_abv: str = None,\tdefensive_conference_abv: str = None,\tncaa_division: str = 'fbs',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games", "modulename": "cfbd_json_py.games", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.games.get_cfbd_games", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_games", "kind": "function", "doc": "DataFrame
object with CFB drive data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with CFB drive data.Retrives game schedule data from the CFBD API.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB game information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB game information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB game information for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB game data from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB game information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB game information from.\n\n
home_team
(str, optional):\n Optional argument.\n If you only want game information for a team, \n where that team was the home team in this season,\n sethome_team
to the name of the team you want game information for.\n\n
away_team
(str, optional):\n Optional argument.\n If you only want game information for a team, \n where that team was the away team in this season,\n setaway_team
to the name of the team you want game information for.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want game information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want game information from.\n\n
ncaa_division
(str, semi-optional):\n Semi-optional argument.\n By default,ncaa_division
will be set to \"fbs\", \n short for the Football Bowl Subdivision (FBS), \n formerly known as D1-A (read as \"division one single A\"),\n the highest level in the NCAA football pyramid,\n where teams can scolarship up to 85 players \n on their football team soley for athletic ability, \n and often have the largest athletics budgets\n within the NCAA.\n\nOther valid inputs are:\n- \"fcs\": Football Championship Subdivision (FCS), \n formerly known as D1-AA (read as \"division one double A\").\n An FCS school is still in the 1st division of the NCAA,\n making them elligable for the March Madness tournament,\n but may not have the resources to compete at the FBS level\n at this time. FCS schools are limited to 63 athletic scolarships\n for football.\n- \"ii\": NCAA Division II. Schools in this and D3 are not\n elligable for the March Madness tournament, \n and are limited to 36 athletic scolarships for their football team.\n- \"iii\": NCAA Division III. The largest single division within the \n NCAA football pyramid. \n D3 schools have the distinction of being part of \n the only NCAA division that cannot give out scolarships soley \n for athletic ability.\n
\n\n
game_id
(int, optional):\n Optional argument. \n Ifgame_id
is set to a game ID,get_cfb_betting_lines()
will try to get \n game information just for that game ID.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_games\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get CFB games from the 2020 CFB season.\n print(\"Get CFB games from the 2020 CFB season.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from week 10 of the 2020 CFB season.\n print(\"Get CFB games from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\n print(\"Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2019,\n team=\"LSU\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\n print(\"Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2021,\n home_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2019,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2022 college football games where one or more teams competing\n # was a Football Championship Subdivision team.\n print(\"Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get game information for the\n # 2021 American Athletic Confrence (AAC) Championship Game.\n print(\"Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2018,\n game_id=401331162\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_games(\n season=2020,\n week=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get CFB games from the 2020 CFB season.\n print(\"Get CFB games from the 2020 CFB season.\")\n json_data = get_cfbd_games(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from week 10 of the 2020 CFB season.\n print(\"Get CFB games from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_games(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\n print(\"Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\")\n json_data = get_cfbd_games(\n season=2019,\n team=\"LSU\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\n print(\"Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\")\n json_data = get_cfbd_games(\n season=2021,\n home_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n season=2019,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2022 college football games where one or more teams competing\n # was a Football Championship Subdivision team.\n print(\"Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.\")\n json_data = get_cfbd_games(\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get game information for the\n # 2021 American Athletic Confrence (AAC) Championship Game.\n print(\"Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.\")\n json_data = get_cfbd_games(\n season=2018,\n game_id=401331162\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_games(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\thome_team: str = None,\taway_team: str = None,\tconference_abv: str = None,\tncaa_division: str = 'fbs',\tgame_id: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_team_records", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_team_records", "kind": "function", "doc": "DataFrame
object with college football game information, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football game information.Get a team, or multiple team's record (wins, losses, ties) for home games, away games, \nconfrence games, and the team's record for that season.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season
(int, optional):\n Semi-optional argument. \n Specifies the season you want CFB team records data from.\n You MUST setseason
orteam
to a non-null value for \n this function to work. If you don't, aValueError()
\n will be raised.\n\n
team
(str, optional):\n Semi-ptional argument.\n If you only want CFB team records data for a specific team,\n setteam
to the name of the team you want CFB drive data from.\n You MUST setseason
orteam
to a non-null value for \n this function to work. If you don't, aValueError()
\n will be raised.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want CFB team records data from games \n involving teams from a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want CFB team records data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_team_records\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get CFB team records from the 2020 CFB season.\n print(\"Get CFB team records from the 2020 CFB season.\")\n json_data = get_cfbd_team_records(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams fielded by the University of Cincinnati.\n print(\"Get team records from football teams fielded by the University of Cincinnati.\")\n json_data = get_cfbd_team_records(\n api_key=cfbd_key,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams that played in the Big 10 (B1G) Confrence\n # in the 2017 CFB season\n print(\"Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season\")\n json_data = get_cfbd_team_records(\n api_key=cfbd_key,\n season=2017,\n conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_records(\n season=2020,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get CFB team records from the 2020 CFB season.\n print(\"Get CFB team records from the 2020 CFB season.\")\n json_data = get_cfbd_team_records(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams fielded by the University of Cincinnati.\n print(\"Get team records from football teams fielded by the University of Cincinnati.\")\n json_data = get_cfbd_team_records(\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams that played in the Big 10 (B1G) Confrence\n # in the 2017 CFB season\n print(\"Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season\")\n json_data = get_cfbd_team_records(\n season=2017,\n conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_records(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_season_weeks", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_season_weeks", "kind": "function", "doc": "DataFrame
object with CFB team records data, \nor (ifreturn_as_dict
is set toTrue
)\na dictionary object with CFB team records data.Retrives a list of weeks that occured in a given CFB season.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want a list of weeks that occured in a given CFB season information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get a list of weeks that occured in a given CFB season information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_season_weeks\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get a list of weeks in the 2020 CFB season.\n print(\"Get a list of weeks in the 2020 CFB season.\")\n json_data = get_cfbd_season_weeks(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_season_weeks(\n season=2020,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get a list of weeks in the 2020 CFB season.\n print(\"Get a list of weeks in the 2020 CFB season.\")\n json_data = get_cfbd_season_weeks(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_season_weeks(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_game_media_info", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_game_media_info", "kind": "function", "doc": "DataFrame
object with a list of valid weeks in a given CFB season, \nor (ifreturn_as_dict
is set toTrue
)\na dictionary object with a list of valid weeks in a given CFB season.Gets known media information for CFB games in a given CFB season.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB media information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB media information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB media information for non-regular season games, \n setseason_type
to \"postseason\".\n If you want both \"regular\" and \"postseason\" games retunred, \n setseason_type
to \"both\"\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB media information from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB media information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB media information from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want media information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want game information from.\n\n
media_type
(str, semi-optional):\n Semi-optional argument.\n If you only want game broadcast information for a specific type of broadcast,\n set this to the type of broadcast.\n\nValid inputs are: \n- `all` (default): Returns all games, and all known broadcasters for those games.\n- `tv`: Returns all known TV broadcasters for CFB games in the requested timeframe.\n- `radio`: Returns all known radio broadcasters \n for CFB games in the requested timeframe.\n- `web`: Returns all known web broadcasts (like ESPN+) \n for CFB games in the requested timeframe.\n- `ppv`: Returns all known Pay Per View (PPV) broadcasts \n for CFB games in the requested timeframe.\n- `mobile`: Returns all known broadcasters that only broadcasted \n games on mobile devices (?)\n
\n\n
ncaa_division
(str, semi-optional):\n Semi-optional argument.\n By default,ncaa_division
will be set to \"fbs\", \n short for the Football Bowl Subdivision (FBS), \n formerly known as D1-A (read as \"division one single A\"),\n the highest level in the NCAA football pyramid,\n where teams can scolarship up to 85 players \n on their football team soley for athletic ability, \n and often have the largest athletics budgets\n within the NCAA.\n\nOther valid inputs are:\n- \"fcs\": Football Championship Subdivision (FCS), \n formerly known as D1-AA (read as \"division one double A\").\n An FCS school is still in the 1st division of the NCAA,\n making them elligable for the March Madness tournament,\n but may not have the resources to compete at the FBS level\n at this time. FCS schools are limited to 63 athletic scolarships\n for football.\n- \"ii\": NCAA Division II. Schools in this and D3 are not\n elligable for the March Madness tournament, \n and are limited to 36 athletic scolarships for their football team.\n- \"iii\": NCAA Division III. The largest single division within the \n NCAA football pyramid. \n D3 schools have the distinction of being part of \n the only NCAA division that cannot give out scolarships soley \n for athletic ability.\n
\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_game_media_info\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get a media information for the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for postseason games in the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for week 10 games in the 2020 CFB season.\n print(\"Get a media information for week 10 games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\n print(\"Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\n print(\"Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"AAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games in the the 2020 CFB season.\n print(\"Get all known radio broadcasters for games in the the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n media_type=\"radio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\n print(\"Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get a media information for the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for postseason games in the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for week 10 games in the 2020 CFB season.\n print(\"Get a media information for week 10 games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\n print(\"Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\n print(\"Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n conference_abv=\"AAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games in the the 2020 CFB season.\n print(\"Get all known radio broadcasters for games in the the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n media_type=\"radio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\n print(\"Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\tconference_abv: str = None,\tmedia_type: str = 'all',\tncaa_division: str = 'fbs',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_player_game_stats", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_player_game_stats", "kind": "function", "doc": "DataFrame
object with college football media information, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football media information.Retrives player game stats for a given time frame.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB media information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB media information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB media information for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.For the following three variables, \nat least one must be set to a non-null variable when calling this function.
\n\n\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB media information from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB media information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB media information from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want media information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want game information from.\n\n
stat_category
(str, optional):\n Optional argument.\n If only want stats for a specific stat category, \n set this variable to that category.\n\nValid inputs are:\n- `passing`\n- `rushing`\n- `receiving`\n- `fumbles`\n- `defensive`\n- `interceptions`\n- `punting`\n- `kicking`\n- `kickReturns`\n- `puntReturns`\n
\n\n
game_id
(int, optional):\n Optional argument. \n Ifgame_id
is set to a game ID,get_cfbd_player_game_stats()
will try to get \n player game stats just for that game ID.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_player_game_stats\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get player game stats for week 10 of the 2020 CFB season.\n print(\"Get player game stats for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get postseason player game stats for the 2020 CFB season.\n print(\"Get postseason player game stats for the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\",\n week=1\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\n print(\"Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2018,\n team=\"Alabama\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\n print(\"Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get get passing stats from players who played in week 7 of the 2017 CFB season.\n print(\"Get get passing stats from players who played in week 7 of the 2017 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2017,\n week=7,\n stat_category=\"pasing\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats from the 2021 Virbo Citrus Bowl, \n # a bowl game that happened in the 2020 CFB season.\n print(\"Get player game stats from the 2021 Virbo Citrus Bowl, a bowl game that happened in the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n game_id=401256199\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n week=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get player game stats for week 10 of the 2020 CFB season.\n print(\"Get player game stats for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get postseason player game stats for the 2020 CFB season.\n print(\"Get postseason player game stats for the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n season_type=\"postseason\",\n week=1\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\n print(\"Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2018,\n team=\"Alabama\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\n print(\"Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get get passing stats from players who played in week 7 of the 2017 CFB season.\n print(\"Get get passing stats from players who played in week 7 of the 2017 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2017,\n week=7,\n stat_category=\"passing\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats from the 2021 Virbo Citrus Bowl, \n # a bowl game that happened in the 2020 CFB season,\n # between the Aubrun Tigers, and the Northwestern Wildcats.\n print(\"Get player game stats from the 2021 Virbo Citrus Bowl, \"+\n \"a bowl game that happened in the 2020 CFB season between the Aubrun Tigers, and the Northwestern Wildcats.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n game_id=401256199\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\tconference_abv: str = None,\tstat_category: str = None,\tgame_id: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_player_advanced_game_stats", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_player_advanced_game_stats", "kind": "function", "doc": "DataFrame
object with player game stats data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with player game stats data.Retrives advanced game stats from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to a string non-empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_player_advanced_game_stats\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, \n # and the Oklahoma Sooners Football Program.\n print(\"Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, and the Oklahoma Sooners Football Program.\")\n json_data = get_cfbd_player_advanced_game_stats(\n api_key=cfbd_key,\n game_id=401135278\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_advanced_game_stats(\n api_key=cfbd_key,\n game_id=401135278,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, \n # and the Oklahoma Sooners Football Program.\n print(\"Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, and the Oklahoma Sooners Football Program.\")\n json_data = get_cfbd_player_advanced_game_stats(\n game_id=401135278\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_advanced_game_stats(\n game_id=401135278,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tgame_id: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_live_scoreboard", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_live_scoreboard", "kind": "function", "doc": "DataFrame
object with college football game information, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football game information.YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK!\nTo view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tncaa_division: str = 'fbs',\tconference: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_weather_info", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_weather_info", "kind": "function", "doc": "YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK!\nTo view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tncaa_division: str = 'fbs',\tgame_id: int = None,\tseason: int = None,\tweek: int = None,\tseason_type: str = 'regular',\tconference: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics", "modulename": "cfbd_json_py.metrics", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_predicted_ppa_from_down_distance", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_predicted_ppa_from_down_distance", "kind": "function", "doc": "\n", "signature": "(\tdown: int,\tdistance: int,\tapi_key: str = None,\tapi_key_dir: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_team_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_team_ppa_data", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\texclude_garbage_time: bool = False,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_game_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_game_ppa_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tconference_abv: str = None,\texclude_garbage_time: bool = False,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_game_player_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_game_player_ppa_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tposition: str = None,\tplayer_id: int = None,\tplay_threshold: int = None,\texclude_garbage_time: bool = False,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_season_player_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_season_player_ppa_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\tposition: str = None,\tplayer_id: int = None,\tplay_threshold: int = None,\texclude_garbage_time: bool = False,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_game_win_probability_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_game_win_probability_data", "kind": "function", "doc": "\n", "signature": "(\tgame_id: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_pregame_win_probability_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_pregame_win_probability_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players", "modulename": "cfbd_json_py.players", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.players.cfbd_player_search", "modulename": "cfbd_json_py.players", "qualname": "cfbd_player_search", "kind": "function", "doc": "\n", "signature": "(\tsearch_str: str,\tapi_key: str = None,\tapi_key_dir: str = None,\tposition: str = None,\tteam: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_player_usage", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_player_usage", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\tposition: str = None,\tplayer_id: int = None,\texclude_garbage_time: bool = False,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_returning_production", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_returning_production", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_player_season_stats", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_player_season_stats", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\tstart_week: int = None,\tend_week: int = None,\tseason_type: str = 'regular',\tstat_category: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_transfer_portal_data", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_transfer_portal_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays", "modulename": "cfbd_json_py.plays", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_data", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\toffensive_team: str = None,\tdefensive_team: str = None,\tconference_abv: str = None,\toffensive_conference_abv: str = None,\tdefensive_conference_abv: str = None,\tplay_type: int = None,\tncaa_division: str = 'fbs',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_play_types", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_play_types", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_stats", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_stats", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tgame_id: int = None,\tathlete_id: int = None,\tstat_type_id: int = None,\tseason_type: str = 'regular',\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_stat_types", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_stat_types", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_live_pbp_data", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_live_pbp_data", "kind": "function", "doc": "\n", "signature": "(\tgame_id: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.rankings", "modulename": "cfbd_json_py.rankings", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.rankings.get_cfbd_poll_rankings", "modulename": "cfbd_json_py.rankings", "qualname": "get_cfbd_poll_rankings", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings", "modulename": "cfbd_json_py.ratings", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_sp_plus_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_sp_plus_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_srs_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_srs_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: int = None,\tconferenece: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_sp_plus_conference_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_sp_plus_conference_ratings", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_elo_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_elo_ratings", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tseason_type: str = 'regular',\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.recruiting", "modulename": "cfbd_json_py.recruiting", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.recruiting.get_cfbd_player_recruit_ratings", "modulename": "cfbd_json_py.recruiting", "qualname": "get_cfbd_player_recruit_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\trecruit_classification: str = 'HighSchool',\tposition: str = None,\tstate: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.recruiting.get_cfbd_team_recruiting_ratings", "modulename": "cfbd_json_py.recruiting", "qualname": "get_cfbd_team_recruiting_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.recruiting.get_cfbd_team_recruiting_group_ratings", "modulename": "cfbd_json_py.recruiting", "qualname": "get_cfbd_team_recruiting_group_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tstart_season: int = None,\tend_season: int = None,\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats", "modulename": "cfbd_json_py.stats", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.stats.get_cfbd_team_season_stats", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_team_season_stats", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\tstart_week: int = None,\tend_week: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats.get_cfbd_advanced_team_season_stats", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_advanced_team_season_stats", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\texclude_garbage_time: bool = False,\tstart_week: int = None,\tend_week: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats.get_cfbd_advanced_team_game_stats", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_advanced_team_game_stats", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tweek: int = None,\topponent: str = None,\texclude_garbage_time: bool = False,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats.get_cfbd_team_stat_categories", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_team_stat_categories", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams", "modulename": "cfbd_json_py.teams", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_information", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_information", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_fbs_team_list", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_fbs_team_list", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_rosters", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_rosters", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_talent_rankings", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_talent_rankings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_matchup_history", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_matchup_history", "kind": "function", "doc": "\n", "signature": "(\tteam_1: str,\tteam_2: str,\tapi_key: str = None,\tapi_key_dir: str = None,\tmin_season: int = None,\tmax_season: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls", "modulename": "cfbd_json_py.utls", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.utls.reverse_cipher_encrypt", "modulename": "cfbd_json_py.utls", "qualname": "reverse_cipher_encrypt", "kind": "function", "doc": "Implements a reverse cipher encription to a plain text string.
\n\nParameters
\n\n\n\n
plain_text_str
(mandatory, str):\n The string you want to encrypt through reverse cipher encryption.Returns
\n\nA string encrypted through reverse cipher encryption.
\n", "signature": "(plain_text_str: str):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls.reverse_cipher_decrypt", "modulename": "cfbd_json_py.utls", "qualname": "reverse_cipher_decrypt", "kind": "function", "doc": "Decrypts a string that was presumed to be encrypted by a reverse cipher encryption.
\n\nParameters
\n\n\n\n
encrypted_text_str
(mandatory, str):\n The string you presume that is encrypted through reverse cipher encryption, \n that you want decrypted.Returns
\n\nA decrypted string.
\n", "signature": "(encrypted_text_str: str):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls.get_cfbd_api_token", "modulename": "cfbd_json_py.utls", "qualname": "get_cfbd_api_token", "kind": "function", "doc": "If the CFBD API key exists in the environment, \nor is in a file, this function retrives the CFBD API key, \nand returns it as a string.
\n\nIf this package is being used in a GitHub Actions action,\nset the key in the environment by \ncreating a repository secret nammed
\n\nCFBD_API_KEY
.Parameters
\n\n\n\n
api_key_dir
(str, optional):\n Optional argument. Ifapi_key_dir
is set to a non-null string, \nset_cfbd_api_token()
will attempt to save the key file in that directory,\n instead of this user's home directory.Returns
\n\nA CFBD API key that exists within this python environment,\nor within this computer.
\n", "signature": "(api_key_dir: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls.set_cfbd_api_token", "modulename": "cfbd_json_py.utls", "qualname": "set_cfbd_api_token", "kind": "function", "doc": "Sets the CFBD API key into a file that exists \neither in
\n\n{home_dir}/.cfbd/cfbd_key.json
, or in a custom directory.Parameters
\n\n\n\n
api_key
(str, mandatory):\n The CFBD API key you have. \n DO NOT inputBearer {your CFBD API key}
,\n this package will take care of that for you.\n\n
api_key_dir
(str, optional):\n Optional argument. Ifapi_key_dir
is set to a non-null string, \nset_cfbd_api_token()
will attempt to save the key file in that directory,\n instead of this user's home directory.Returns
\n\nNothing. \nThis function only sets up the API key file that this package can reference later.
\n", "signature": "(api_key: str, api_key_dir: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.venues", "modulename": "cfbd_json_py.venues", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.venues.get_cfbd_venues", "modulename": "cfbd_json_py.venues", "qualname": "get_cfbd_venues", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}]; + /** pdoc search index */const docs = [{"fullname": "cfbd_json_py", "modulename": "cfbd_json_py", "kind": "module", "doc": "Welcome!
\n\nThis is the official docs page for the
\n\ncfbd_json_py
python package.To the left of this page are various endpoints for this python package.
\n\n\n
\n\n- \n
cfbd_json_py.betting
: \nHolds functions for betting lines and betting data from the CFBD API.- \n
cfbd_json_py.coaches
: \nHolds functions for you to get coaching data (past and present).- \n
cfbd_json_py.conferences
: \nHolds functions for you to get information for CFB confrences.- \n
cfbd_json_py.draft
: \nHolds functions for you to get NFL draft information/data for \nvarious players in the CFBD API- \n
cfbd_json_py.drives
: \nHolds functions for you to get data for offensive and/or defensive drives \nwithin the CFBD API.- \n
cfbd_json_py.games
: \nHolds functions for you to get various datapoints pertaining to \nactual CFB games within the CFBD API.- \n
cfbd_json_py.metrics
: \nHolds functions to allow you to calculate or retrive various advanced metrics \nfrom the CFBD API.- \n
cfbd_json_py.players
: \nHolds functions for you to get various \ndata endpoints related to player stats, \nplayer information, and player data.- \n
cfbd_json_py.plays
: \nHolds functions for play-by-play (PBP) data for CFB games, \nas well as a way to calculate stats from PBP data.- \n
cfbd_json_py.rankings
: \nHolds functions for various CFB team ranking polls, \nand their results.- \n
cfbd_json_py.ratings
: \nHolds functions to allow you to get various team ratings data \n(like SP+, SRS, and Elo team ratings) from the CFBD API.- \n
cfbd_json_py.recruiting
: \nHolds functions for you to access CFB recruting data and information, \nas well as team and player ratings for recruiting.- \n
cfbd_json_py.stats
: \nHolds functions for you to get various team stats from the CFBD API.- \n
cfbd_json_py.teams
: \nHolds functions for you to get team information and data, \nas well as head-to-head records and matchup history.- \n
cfbd_json_py.utls
: \nVarious utilities that can be used from this package.\nOutside ofcfbd_json_py.utls.set_cfbd_api_token()
, \nyou don't need to call any of these functions directly.- \n
cfbd_json_py.venues
: \nHolds functions for you to get information on \nvarious venues/stadiums within the college football world.Basic Setup
\n\nIf you have a CFBD API key, you have three ways to set it for this python package to use:
\n\n\n
\n\n- Declare the API key as a string variable in a python script (not reccomended, extreme security risk).
\n- Declare the API key in your environment as
\nCFBD_API_KEY
.\n\n
- \n
cfbd_json_py
will first look for your environment, \nif you don't declare the API key as a string variable, \nwhen calling any function in this python package that uses a CFBD API call.- If you're using GitHub Actions with this package, \njust set a repository secret with the name
\nCFBD_API_KEY
. \nAgain, this package will automatically know where to look, \nif you've set your API key in the environment- Use
\ncfbd_json_py.utls.set_cfbd_api_token()
to store the API key in an encrypted file on your machine.\n\n
- To set the API key for this package with this function, \nrun this code in a python script, \nreplacing
\n\"TigersAreAwesome\"
with your API key:\n\nfrom cfbd_api_key.utls import set_cfbd_api_token\n\ncfbd_api_key = \"TigersAreAwesome\" # replace this with your actual API key\nset_cfbd_api_token(api_key=cfbd_api_key)\n
\n\n\nNOTE: In a future version, \n there will be an executable application seperate from this package\n for Windows, Mac, and Linux users to effectively do the same thing \n as the above code block, but with a graphical user interface (GUI).
\nIf you want to see how to use this python package after setting up your API key,\nclick on one of the submodules on the left \nto view the various functions within each submodule.\nEach function has a tutorial script on the various ways you can call that function.
\n\nOther Notes
\n\n\n
\n"}, {"fullname": "cfbd_json_py.betting", "modulename": "cfbd_json_py.betting", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.betting.get_cfbd_betting_lines", "modulename": "cfbd_json_py.betting", "qualname": "get_cfbd_betting_lines", "kind": "function", "doc": "- If you want to see all CFBD API endpoints that are currently supported, \nclick here\nto access the current Swagger docs for the entire API.
\n- If you want to see the source code for this package, \nclick here to see the current stable build of this python package on GitHub.
\n- If you want to see the active changelog for this python package, \nclick here to view the changelog of this python package on GitHub.
\nRetrives betting information from the CFBD API for a given season, \nor you could only get betting information for a single game.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n The season you want to retrive betting information from.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
game_id
(int, optional):\n Optional argument. \n Ifgame_id
is set to a game ID,get_cfb_betting_lines()
will try to get \n all betting informaiton for that game ID.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load betting data from games in that season, and that week.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want postseason betting data, setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
team
(str, optional):\n Optional argument.\n If you only want betting information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want game-level betting data from.\n\n
home_team
(str, optional):\n Optional argument.\n If you only want betting information for a team, \n where that team was the home team in this season,\n sethome_team
to the name of the team you want game-level betting data from.\n\n
away_team
(str, optional):\n Optional argument.\n If you only want betting information for a team, \n where that team was the away team in this season,\n setaway_team
to the name of the team you want game-level betting data from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want betting information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want betting informaiton from.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.betting import get_cfbd_betting_lines\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets all available betting info for the 2020 CFB season.\n print(\"Gets all available betting info for the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Gets all available betting info for the 2020 CFB season, in week 2.\n print(\"Gets all available betting info for the 2020 CFB season, in week 2.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n week=2\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\n print(\"Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\n print(\"Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\n print(\"Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n home_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\n print(\"Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n away_team=\"Ohio State\"\n )\n\n # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\n print(\"Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_betting_lines(\n api_key=cfbd_key,\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets all available betting info for the 2020 CFB season.\n print(\"Gets all available betting info for the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n # Gets all available betting info for the 2020 CFB season, in week 2.\n print(\"Gets all available betting info for the 2020 CFB season, in week 2.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n week=2\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\n print(\"Gets all betting info for the 2020 CFB season, in the postseason (bowls, playoffs, etc.).\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\n print(\"Gets all betting info for Cincinnati Bearcats Football games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\n print(\"Gets all betting info for Ohio Bobcats home games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n home_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n # Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\n print(\"Gets all betting info for Ohio State Buckeyes away games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n\n season=2020,\n away_team=\"Ohio State\"\n )\n\n # Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\n print(\"Gets all betting info for Atlantic Coast Conference (ACC) games the 2020 CFB season.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_betting_lines(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tgame_id: int = None,\tweek: int = None,\tseason_type: str = 'regular',\tteam: str = None,\thome_team: str = None,\taway_team: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.coaches", "modulename": "cfbd_json_py.coaches", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.coaches.get_cfbd_coaches_info", "modulename": "cfbd_json_py.coaches", "qualname": "get_cfbd_coaches_info", "kind": "function", "doc": "DataFrame
object with college football betting data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football betting data.Retrives information from the CFBD API on CFB Head Coaches.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
first_name
(str, optional):\n Optional argument.\n If you want to only look up coaches with a specific first name, \n set this variable to that specific first name, and this function \n will attempt to look up coaches with that specific first name.\n\n
last_name
(str, optional):\n Optional argument.\n If you want to only look up coaches with a specific last name, \n set this variable to that specific first name, and this function \n will attempt to look up coaches with that specific last name.\n\n
team
(str, optional):\n Optional argument.\n If you want to filter and drill down to coaches who coached a specific\n CFB team, set this\n\n
season
(int, optional):\n Optional argument.\n If you only want coaches from a specific season, set this variable to that season.\n\n
min_season
(int, optional):\n Optional argument.\n Similar toyear
, but used in tandem withmax_season
to get coaches who coached with in a range of seasons.\n\n
max_season
(int, optional):\n Optional argument.\n Similar toyear
, but used in tandem withmin_season
to get coaches who coached with in a range of seasons.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.coaches import get_cfbd_coaches_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Getting all coaches in the 2020 CFB season\n print(\"Getting every coach in the 2020 CFB season.\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n # Getting all coaches in the 2020 CFB season, with a first name of \"Luke\"\n print(\"Getting every coach in the 2020 CFB season, with a first name of \"Luke\".\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020,\n first_name=\"Luke\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting all coaches in the 2020 CFB season, with a last name of \"Day\"\n print(\"Getting all coaches in the 2020 CFB season, with a last name of \"Day\".\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020,\n last_name=\"Day\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach for the 2020 Southern Mississippi Golden Eagles\n print(\"Getting every head coach for the 2020 Southern Mississippi Golden Eagles.\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2020,\n team=\"Southern Mississippi\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach between the 2019 and 2022 CFB seasons\n print(\"Getting every head coach between the 2019 and 2022 CFB seasons\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n min_season=2019,\n max_season=2022\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_coaches_info(\n api_key=cfbd_key,\n season=2022,\n team=\"Cincinnati\",\n return_as_dict=True\n )\n print(f\"{json_data}\")\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Getting every coach in the 2020 CFB season.\n print(\"Getting every coach in the 2020 CFB season.\")\n json_data = get_cfbd_coaches_info(season=2020)\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every coach in the 2020 CFB season, with a first name of \"Luke\".\n print(\"Getting every coach in the 2020 CFB season, with a first name of \"Luke\".\")\n json_data = get_cfbd_coaches_info(\n season=2020,\n first_name=\"Luke\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every coach in the 2020 CFB season, with a last name of \"Day\".\n print(\"Getting every coach in the 2020 CFB season, with a last name of \"Day\".\")\n json_data = get_cfbd_coaches_info(\n season=2020,\n last_name=\"Day\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach for the 2020 Southern Mississippi Golden Eagles.\n print(\"Getting every head coach for the 2020 Southern Mississippi Golden Eagles.\")\n json_data = get_cfbd_coaches_info(\n season=2020,\n team=\"Southern Mississippi\"\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # Getting every head coach between the 2019 and 2022 CFB seasons.\n print(\"Getting every head coach between the 2019 and 2022 CFB seasons.\")\n json_data = get_cfbd_coaches_info(\n min_season=2019,\n max_season=2022\n )\n print(f\"{json_data}\")\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_coaches_info(\n season=2022,\n team=\"Cincinnati\",\n return_as_dict=True\n )\n print(f\"{json_data}\")\n\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tfirst_name: str = None,\tlast_name: str = None,\tteam: str = None,\tseason: int = None,\tmin_season: int = None,\tmax_season: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.conferences", "modulename": "cfbd_json_py.conferences", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.conferences.get_cfbd_conference_info", "modulename": "cfbd_json_py.conferences", "qualname": "get_cfbd_conference_info", "kind": "function", "doc": "DataFrame
object with CFB head coach data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with CFB head coach data.Retrives a list of CFB conferences from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.conferences import get_cfbd_conference_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets CFB confrence info from the CFBD API.\n print(\"Gets CFB confrence info from the CFBD API.\")\n json_data = get_cfbd_conference_info(api_key=cfbd_key)\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_conference_info(\n api_key=cfbd_key,\n return_as_dict=True)\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets CFB confrence info from the CFBD API.\n print(\"Gets CFB confrence info from the CFBD API.\")\n json_data = get_cfbd_conference_info()\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_conference_info(return_as_dict=True)\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.draft", "modulename": "cfbd_json_py.draft", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.draft.get_cfbd_nfl_teams", "modulename": "cfbd_json_py.draft", "qualname": "get_cfbd_nfl_teams", "kind": "function", "doc": "DataFrame
object with CFB conference data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with CFB conference data.Retrives a list of NFL teams from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.draft import get_cfbd_nfl_teams\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets NFL team info from the CFBD API.\n print(\"Gets NFL team info from the CFBD API.\")\n json_data = get_cfbd_nfl_teams(api_key=cfbd_key)\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_teams(\n api_key=cfbd_key,\n return_as_dict=True)\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets NFL team info from the CFBD API.\n print(\"Gets NFL team info from the CFBD API.\")\n json_data = get_cfbd_nfl_teams()\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_teams(return_as_dict=True)\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.draft.get_cfbd_nfl_positions", "modulename": "cfbd_json_py.draft", "qualname": "get_cfbd_nfl_positions", "kind": "function", "doc": "DataFrame
object with NFL team data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with NFL team data.Retrives a list of player positions for the NFL Draft from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.draft import get_cfbd_nfl_positions\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Gets a list of player positions for the NFL Draft from the CFBD API.\n print(\"Gets a list of player positions for the NFL Draft from the CFBD API.\")\n json_data = get_cfbd_nfl_positions(api_key=cfbd_key)\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_positions(\n api_key=cfbd_key,\n return_as_dict=True)\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Gets a list of player positions for the NFL Draft from the CFBD API.\n print(\"Gets a list of player positions for the NFL Draft from the CFBD API.\")\n json_data = get_cfbd_nfl_positions()\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_positions(return_as_dict=True)\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.draft.get_cfbd_nfl_draft_info", "modulename": "cfbd_json_py.draft", "qualname": "get_cfbd_nfl_draft_info", "kind": "function", "doc": "DataFrame
object with player position data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with player position data.Retrives a list of actual NFL Draft selections from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.The following paramaters are optional, but it is highly reccomended to not call this function\nwithiout settting one of these five optional paramaters to a non-null value.
\n\n\n\n
season
(int, semi-optional):\n Semi-Optional argument. \n This is the season you want NFL Draft information for. For example, if you only want \n data for the 2020 NFL Draft, setseason
to2020
.\n\n
nfl_team
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections from a specific NFL team, setnfl_team
to the \n name of that team. For example, if you want to only get NFL Draft information for \n draft picks made by the Cincinnati Bengals, setnfl_team
toCincinnati
.\n\n
college
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections from a specific CFB team, setcollege
to the \n name of that team. For example, if you want to only get NFL Draft information for \n draft picks from the Clemson Tigers Football Program, setcollege
toClemson
.\n\n
conference
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections from a specific CFB confrence, setconference
to the abbreviation of that confrence. \n A list of CFBD API confrence abbreviations can be found in theconference_abbreviation
column from \n the pandas DataFrame that is returned by callingcfbd_json_py.conferences.get_cfbd_conference_info()
.\n For example, if you want to only get NFL Draft information for \n draft picks that played in the Big 12, setconfrence
toB12
.\n\n
position
(str, optional):\n Semi-Optional argument.\n If you only want NFL Draft selections who played a specific position, \n setposition
to that position's abbreviation. \n A list of CFBD API positions can be found in theposition_abbreviation
column from \n the pandas DataFrame that is returned by callingcfbd_json_py.draft.get_cfbd_nfl_positions()
.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.draft import get_cfbd_nfl_draft_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get NFL Draft selections from the 2020 NFL Draft.\n print(\"Get NFL Draft selections from the 2020 NFL Draft.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made by the\n # 2020 Cincinnati Bengals.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n nfl_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # Clemson Tigers football players.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n college=\"Clemson\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # players who played in the Southeastern Confrence (SEC).\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n conference=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made\n # where the selected player was a QB in college.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.\")\n json_data = get_cfbd_nfl_draft_info(\n api_key=cfbd_key,\n season=2020,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n position=\"QB\",\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get NFL Draft selections from the 2020 NFL Draft.\n print(\"Get NFL Draft selections from the 2020 NFL Draft.\")\n json_data = get_cfbd_nfl_draft_info(season=2020)\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made by the\n # 2020 Cincinnati Bengals.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made by the 2020 Cincinnati Bengals.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n nfl_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # Clemson Tigers football players.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving Clemson Tigers football players.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n college=\"Clemson\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made involving\n # players who played in the Southeastern Confrence (SEC).\n print(\"Get NFL Draft selections from the 2020 NFL Draft made involving players who played in the Southeastern Confrence (SEC).\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n conference=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get NFL Draft selections from the 2020 NFL Draft made\n # where the selected player was a QB in college.\n print(\"Get NFL Draft selections from the 2020 NFL Draft made where the selected player was a QB in college.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_nfl_draft_info(\n season=2020,\n position=\"QB\",\n return_as_dict=True\n )\n print(json_data)\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tnfl_team: str = None,\tcollege: str = None,\tconference_abv: str = None,\tposition: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.drives", "modulename": "cfbd_json_py.drives", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.drives.get_cfbd_drives_info", "modulename": "cfbd_json_py.drives", "qualname": "get_cfbd_drives_info", "kind": "function", "doc": "DataFrame
object with NFL Draft selection data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with NFL Draft selection data.Retrives a list of CFB drives from the CFBD API.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB drive information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB drive information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB drive data for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB drive data from games in that season, and that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB drive data for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB drive data from.\n\n
offensive_team
(str, optional):\n Optional argument.\n If you only want CFB drive data from a team, while they are on offense, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB drive data from.\n\n
defensive_team
(str, optional):\n Optional argument.\n If you only want CFB drive data from a team, while they are on defense,\n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB drive data from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want CFB drive data from games \n involving teams from a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want CFB drive data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
offensive_conference_abv
(str, optional):\n Optional argument.\n If you only want CFB drive data from games \n where the offensive team is from a specific confrenece,\n setconference_abv
to the abbreviation \n of the conference you want CFB drive data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
defensive_conference_abv
(str, optional):\n Optional argument.\n If you only want CFB drive data from games \n where the defensive team is from a specific confrenece,\n setconference_abv
to the abbreviation \n of the conference you want CFB drive data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
ncaa_division
(str, semi-optional):\n Semi-optional argument.\n By default,ncaa_division
will be set to \"fbs\", \n short for the Football Bowl Subdivision (FBS), \n formerly known as D1-A (read as \"division one single A\"),\n the highest level in the NCAA football pyramid,\n where teams can scolarship up to 85 players \n on their football team soley for athletic ability, \n and often have the largest athletics budgets\n within the NCAA.\n\nOther valid inputs are:\n- \"fcs\": Football Championship Subdivision (FCS), \n formerly known as D1-AA (read as \"division one double A\").\n An FCS school is still in the 1st division of the NCAA,\n making them elligable for the March Madness tournament,\n but may not have the resources to compete at the FBS level\n at this time. FCS schools are limited to 63 athletic scolarships\n for football.\n- \"ii\": NCAA Division II. Schools in this and D3 are not\n elligable for the March Madness tournament, \n and are limited to 36 athletic scolarships for their football team.\n- \"iii\": NCAA Division III. The largest single division within the \n NCAA football pyramid. \n D3 schools have the distinction of being part of \n the only NCAA division that cannot give out scolarships soley \n for athletic ability.\n
\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.drives import get_cfbd_drives_info\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get CFB Drive data from the 2020 CFB season.\n print(\"Get CFB Drive data from the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from week 10 of the 2020 CFB season.\n print(\"Get CFB Drive data from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats\n # Football Team.\n print(\"Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio Bobcats\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n offensive_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n defensive_team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 12 games in the 2020 CFB season.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"B12\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,\n # where the Big 10 team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n offensive_conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Mid-American Conference (MAC) games\n # in the 2020 CFB season, where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n defensive_conference_abv=\"MAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Football Championship Subdivision (FCS) games\n # in week 3 ofthe 2020 CFB season,\n # where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n api_key=cfbd_key,\n season=2020,\n week=3,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get CFB Drive data from the 2020 CFB season.\n print(\"Get CFB Drive data from the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from week 10 of the 2020 CFB season.\n print(\"Get CFB Drive data from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Cincinnati Bearcats\n # Football Team.\n print(\"Get CFB Drive data from games involving the 2020 Cincinnati Bearcats Football Team.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio Bobcats\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio Bobcats Football Team, when Ohio was on offense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n offensive_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from games involving the 2020 Ohio State Buckeyes\n # Football Team, when Ohio was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n defensive_team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 12 games in the 2020 CFB season.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n conference_abv=\"B12\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Big 10 (B1G) games in the 2020 CFB season,\n # where the Big 10 team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n offensive_conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Mid-American Conference (MAC) games\n # in the 2020 CFB season, where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n defensive_conference_abv=\"MAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB Drive data from Football Championship Subdivision (FCS) games\n # in week 3 ofthe 2020 CFB season,\n # where the MAC team was on offense.\n print(\"Get CFB Drive data from games involving the 2020 Ohio State Buckeyes Football Team, when Ohio State was on defense.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=3,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_drives_info(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\toffensive_team: str = None,\tdefensive_team: str = None,\tconference_abv: str = None,\toffensive_conference_abv: str = None,\tdefensive_conference_abv: str = None,\tncaa_division: str = 'fbs',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games", "modulename": "cfbd_json_py.games", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.games.get_cfbd_games", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_games", "kind": "function", "doc": "DataFrame
object with CFB drive data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with CFB drive data.Retrives game schedule data from the CFBD API.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB game information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB game information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB game information for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB game data from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB game information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB game information from.\n\n
home_team
(str, optional):\n Optional argument.\n If you only want game information for a team, \n where that team was the home team in this season,\n sethome_team
to the name of the team you want game information for.\n\n
away_team
(str, optional):\n Optional argument.\n If you only want game information for a team, \n where that team was the away team in this season,\n setaway_team
to the name of the team you want game information for.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want game information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want game information from.\n\n
ncaa_division
(str, semi-optional):\n Semi-optional argument.\n By default,ncaa_division
will be set to \"fbs\", \n short for the Football Bowl Subdivision (FBS), \n formerly known as D1-A (read as \"division one single A\"),\n the highest level in the NCAA football pyramid,\n where teams can scolarship up to 85 players \n on their football team soley for athletic ability, \n and often have the largest athletics budgets\n within the NCAA.\n\nOther valid inputs are:\n- \"fcs\": Football Championship Subdivision (FCS), \n formerly known as D1-AA (read as \"division one double A\").\n An FCS school is still in the 1st division of the NCAA,\n making them elligable for the March Madness tournament,\n but may not have the resources to compete at the FBS level\n at this time. FCS schools are limited to 63 athletic scolarships\n for football.\n- \"ii\": NCAA Division II. Schools in this and D3 are not\n elligable for the March Madness tournament, \n and are limited to 36 athletic scolarships for their football team.\n- \"iii\": NCAA Division III. The largest single division within the \n NCAA football pyramid. \n D3 schools have the distinction of being part of \n the only NCAA division that cannot give out scolarships soley \n for athletic ability.\n
\n\n
game_id
(int, optional):\n Optional argument. \n Ifgame_id
is set to a game ID,get_cfb_betting_lines()
will try to get \n game information just for that game ID.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_games\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get CFB games from the 2020 CFB season.\n print(\"Get CFB games from the 2020 CFB season.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from week 10 of the 2020 CFB season.\n print(\"Get CFB games from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\n print(\"Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2019,\n team=\"LSU\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\n print(\"Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2021,\n home_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2019,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2022 college football games where one or more teams competing\n # was a Football Championship Subdivision team.\n print(\"Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get game information for the\n # 2021 American Athletic Confrence (AAC) Championship Game.\n print(\"Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.\")\n json_data = get_cfbd_games(\n api_key=cfbd_key,\n season=2018,\n game_id=401331162\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_games(\n season=2020,\n week=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get CFB games from the 2020 CFB season.\n print(\"Get CFB games from the 2020 CFB season.\")\n json_data = get_cfbd_games(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from week 10 of the 2020 CFB season.\n print(\"Get CFB games from week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_games(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\n print(\"Get CFB games from the 2019 CFB season that involved the 2019 LSU Tigers.\")\n json_data = get_cfbd_games(\n season=2019,\n team=\"LSU\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\n print(\"Get 2021 Cincinnati Bearcats Football games where the Bearcats were the home team.\")\n json_data = get_cfbd_games(\n season=2021,\n home_team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n season=2019,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\n print(\"Get 2018 Ohio Bobcats Football games where the Bobcats were the away team.\")\n json_data = get_cfbd_games(\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get 2022 college football games where one or more teams competing\n # was a Football Championship Subdivision team.\n print(\"Get 2022 college football games where one or more teams competing was a Football Championship Subdivision team.\")\n json_data = get_cfbd_games(\n season=2018,\n away_team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get game information for the\n # 2021 American Athletic Confrence (AAC) Championship Game.\n print(\"Get game information for the 2021 American Athletic Confrence (AAC) Championship Game.\")\n json_data = get_cfbd_games(\n season=2018,\n game_id=401331162\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_games(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\thome_team: str = None,\taway_team: str = None,\tconference_abv: str = None,\tncaa_division: str = 'fbs',\tgame_id: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_team_records", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_team_records", "kind": "function", "doc": "DataFrame
object with college football game information, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football game information.Get a team, or multiple team's record (wins, losses, ties) for home games, away games, \nconfrence games, and the team's record for that season.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season
(int, optional):\n Semi-optional argument. \n Specifies the season you want CFB team records data from.\n You MUST setseason
orteam
to a non-null value for \n this function to work. If you don't, aValueError()
\n will be raised.\n\n
team
(str, optional):\n Semi-ptional argument.\n If you only want CFB team records data for a specific team,\n setteam
to the name of the team you want CFB drive data from.\n You MUST setseason
orteam
to a non-null value for \n this function to work. If you don't, aValueError()
\n will be raised.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want CFB team records data from games \n involving teams from a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want CFB team records data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_team_records\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get CFB team records from the 2020 CFB season.\n print(\"Get CFB team records from the 2020 CFB season.\")\n json_data = get_cfbd_team_records(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams fielded by the University of Cincinnati.\n print(\"Get team records from football teams fielded by the University of Cincinnati.\")\n json_data = get_cfbd_team_records(\n api_key=cfbd_key,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams that played in the Big 10 (B1G) Confrence\n # in the 2017 CFB season\n print(\"Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season\")\n json_data = get_cfbd_team_records(\n api_key=cfbd_key,\n season=2017,\n conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_records(\n season=2020,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get CFB team records from the 2020 CFB season.\n print(\"Get CFB team records from the 2020 CFB season.\")\n json_data = get_cfbd_team_records(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams fielded by the University of Cincinnati.\n print(\"Get team records from football teams fielded by the University of Cincinnati.\")\n json_data = get_cfbd_team_records(\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team records from football teams that played in the Big 10 (B1G) Confrence\n # in the 2017 CFB season\n print(\"Get team records from football teams that played in the Big 10 (B1G) Confrence in the 2017 CFB season\")\n json_data = get_cfbd_team_records(\n season=2017,\n conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_records(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_season_weeks", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_season_weeks", "kind": "function", "doc": "DataFrame
object with CFB team records data, \nor (ifreturn_as_dict
is set toTrue
)\na dictionary object with CFB team records data.Retrives a list of weeks that occured in a given CFB season.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want a list of weeks that occured in a given CFB season information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get a list of weeks that occured in a given CFB season information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_season_weeks\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get a list of weeks in the 2020 CFB season.\n print(\"Get a list of weeks in the 2020 CFB season.\")\n json_data = get_cfbd_season_weeks(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_season_weeks(\n season=2020,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get a list of weeks in the 2020 CFB season.\n print(\"Get a list of weeks in the 2020 CFB season.\")\n json_data = get_cfbd_season_weeks(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_season_weeks(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_game_media_info", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_game_media_info", "kind": "function", "doc": "DataFrame
object with a list of valid weeks in a given CFB season, \nor (ifreturn_as_dict
is set toTrue
)\na dictionary object with a list of valid weeks in a given CFB season.Gets known media information for CFB games in a given CFB season.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB media information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB media information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB media information for non-regular season games, \n setseason_type
to \"postseason\".\n If you want both \"regular\" and \"postseason\" games retunred, \n setseason_type
to \"both\"\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB media information from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB media information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB media information from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want media information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want game information from.\n\n
media_type
(str, semi-optional):\n Semi-optional argument.\n If you only want game broadcast information for a specific type of broadcast,\n set this to the type of broadcast.\n\nValid inputs are: \n- `all` (default): Returns all games, and all known broadcasters for those games.\n- `tv`: Returns all known TV broadcasters for CFB games in the requested timeframe.\n- `radio`: Returns all known radio broadcasters \n for CFB games in the requested timeframe.\n- `web`: Returns all known web broadcasts (like ESPN+) \n for CFB games in the requested timeframe.\n- `ppv`: Returns all known Pay Per View (PPV) broadcasts \n for CFB games in the requested timeframe.\n- `mobile`: Returns all known broadcasters that only broadcasted \n games on mobile devices (?)\n
\n\n
ncaa_division
(str, semi-optional):\n Semi-optional argument.\n By default,ncaa_division
will be set to \"fbs\", \n short for the Football Bowl Subdivision (FBS), \n formerly known as D1-A (read as \"division one single A\"),\n the highest level in the NCAA football pyramid,\n where teams can scolarship up to 85 players \n on their football team soley for athletic ability, \n and often have the largest athletics budgets\n within the NCAA.\n\nOther valid inputs are:\n- \"fcs\": Football Championship Subdivision (FCS), \n formerly known as D1-AA (read as \"division one double A\").\n An FCS school is still in the 1st division of the NCAA,\n making them elligable for the March Madness tournament,\n but may not have the resources to compete at the FBS level\n at this time. FCS schools are limited to 63 athletic scolarships\n for football.\n- \"ii\": NCAA Division II. Schools in this and D3 are not\n elligable for the March Madness tournament, \n and are limited to 36 athletic scolarships for their football team.\n- \"iii\": NCAA Division III. The largest single division within the \n NCAA football pyramid. \n D3 schools have the distinction of being part of \n the only NCAA division that cannot give out scolarships soley \n for athletic ability.\n
\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_game_media_info\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get a media information for the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for postseason games in the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for week 10 games in the 2020 CFB season.\n print(\"Get a media information for week 10 games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\n print(\"Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\n print(\"Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"AAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games in the the 2020 CFB season.\n print(\"Get all known radio broadcasters for games in the the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n media_type=\"radio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\n print(\"Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n api_key=cfbd_key,\n season=2020,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get a media information for the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for postseason games in the 2020 CFB season.\n print(\"Get a media information for the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get a media information for week 10 games in the 2020 CFB season.\n print(\"Get a media information for week 10 games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\n print(\"Get all known broadcasters for games played by the Ohio State Football Program in the the 2019 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\n print(\"Get all known radio broadcasters for games played by teams within the American Athletic Confrence (AAC) in the the 2021 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n conference_abv=\"AAC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known radio broadcasters for games in the the 2020 CFB season.\n print(\"Get all known radio broadcasters for games in the the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n media_type=\"radio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\n print(\"Get all known broadcasters for Football Championship Subdivision (FCS) games in the 2020 CFB season.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n ncaa_division=\"fcs\"\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_game_media_info(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\tconference_abv: str = None,\tmedia_type: str = 'all',\tncaa_division: str = 'fbs',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_player_game_stats", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_player_game_stats", "kind": "function", "doc": "DataFrame
object with college football media information, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football media information.Retrives player game stats for a given time frame.
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want CFB media information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get CFB media information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB media information for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.For the following three variables, \nat least one must be set to a non-null variable when calling this function.
\n\n\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB media information from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want CFB media information for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want CFB media information from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want media information from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want game information from.\n\n
stat_category
(str, optional):\n Optional argument.\n If only want stats for a specific stat category, \n set this variable to that category.\n\nValid inputs are:\n- `passing`\n- `rushing`\n- `receiving`\n- `fumbles`\n- `defensive`\n- `interceptions`\n- `punting`\n- `kicking`\n- `kickReturns`\n- `puntReturns`\n
\n\n
game_id
(int, optional):\n Optional argument. \n Ifgame_id
is set to a game ID,get_cfbd_player_game_stats()
will try to get \n player game stats just for that game ID.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_player_game_stats\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get player game stats for week 10 of the 2020 CFB season.\n print(\"Get player game stats for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get postseason player game stats for the 2020 CFB season.\n print(\"Get postseason player game stats for the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\",\n week=1\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\n print(\"Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2018,\n team=\"Alabama\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\n print(\"Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get get passing stats from players who played in week 7 of the 2017 CFB season.\n print(\"Get get passing stats from players who played in week 7 of the 2017 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2017,\n week=7,\n stat_category=\"pasing\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats from the 2021 Virbo Citrus Bowl, \n # a bowl game that happened in the 2020 CFB season.\n print(\"Get player game stats from the 2021 Virbo Citrus Bowl, a bowl game that happened in the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n api_key=cfbd_key,\n season=2020,\n game_id=401256199\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n week=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get player game stats for week 10 of the 2020 CFB season.\n print(\"Get player game stats for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get postseason player game stats for the 2020 CFB season.\n print(\"Get postseason player game stats for the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n season_type=\"postseason\",\n week=1\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\n print(\"Get player game stats for the Alabma Crimson Tide Football Team for the 2018 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2018,\n team=\"Alabama\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\n print(\"Get player game stats for players of teams in the Atlantic Coast Conference (ACC) in the 2020 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n conference_abv=\"ACC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get get passing stats from players who played in week 7 of the 2017 CFB season.\n print(\"Get get passing stats from players who played in week 7 of the 2017 CFB season.\")\n json_data = get_cfbd_player_game_stats(\n season=2017,\n week=7,\n stat_category=\"passing\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game stats from the 2021 Virbo Citrus Bowl, \n # a bowl game that happened in the 2020 CFB season,\n # between the Aubrun Tigers, and the Northwestern Wildcats.\n print(\"Get player game stats from the 2021 Virbo Citrus Bowl, \"+\n \"a bowl game that happened in the 2020 CFB season between the Aubrun Tigers, and the Northwestern Wildcats.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n game_id=401256199\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_game_stats(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tseason_type: str = 'regular',\tweek: int = None,\tteam: str = None,\tconference_abv: str = None,\tstat_category: str = None,\tgame_id: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_player_advanced_game_stats", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_player_advanced_game_stats", "kind": "function", "doc": "DataFrame
object with player game stats data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with player game stats data.Retrives advanced game stats from the CFBD API.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.games import get_cfbd_player_advanced_game_stats\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, \n # and the Oklahoma Sooners Football Program.\n print(\"Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, and the Oklahoma Sooners Football Program.\")\n json_data = get_cfbd_player_advanced_game_stats(\n api_key=cfbd_key,\n game_id=401135278\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_advanced_game_stats(\n api_key=cfbd_key,\n game_id=401135278,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, \n # and the Oklahoma Sooners Football Program.\n print(\"Get advanced player stats for a 2019 CFB game between the LSU Tigers Football Program, and the Oklahoma Sooners Football Program.\")\n json_data = get_cfbd_player_advanced_game_stats(\n game_id=401135278\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_advanced_game_stats(\n game_id=401135278,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tgame_id: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_live_scoreboard", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_live_scoreboard", "kind": "function", "doc": "DataFrame
object with college football game information, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with college football game information.YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK!\nTo view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tncaa_division: str = 'fbs',\tconference: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.games.get_cfbd_weather_info", "modulename": "cfbd_json_py.games", "qualname": "get_cfbd_weather_info", "kind": "function", "doc": "YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK!\nTo view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tncaa_division: str = 'fbs',\tgame_id: int = None,\tseason: int = None,\tweek: int = None,\tseason_type: str = 'regular',\tconference: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics", "modulename": "cfbd_json_py.metrics", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_predicted_ppa_from_down_distance", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_predicted_ppa_from_down_distance", "kind": "function", "doc": "Given a down and distance, \nthis function will attempt to get the predicted\nPPA value for that down and distance, \nat every yard line possible for that down and distance.
\n\nPPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
\n\nFor this endpoint, \n[
\n\nyardLine
] is the number of yards from 1 (offense has the ball on their side, \nat their 1 yard line), to 99 \n(offense with the ball with a X and goal situation on the opponent's 1 yard line.Parameters
\n\n\n\n
down
(int, mandatory):\n Mandatory argument.\n This is the down (a number between 1 and 4 in normal situations)\n for this play you want PPA for.\n\n
distance
(int, mandatory):\n Mandatory argument.\n This variable should be set to the number of yards between \n the line of scrimage (LOS), and the first down line on the field.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_predicted_ppa_from_down_distance\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get the predicted PPA for a 1st and 10 play, \n # in every possible situation.\n print(\"Get the predicted PPA for a 1st and 10 play, in every possible situation.\")\n json_data = get_cfbd_predicted_ppa_from_down_distance(\n down=1,\n distance=10,\n api_key=cfbd_key\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_predicted_ppa_from_down_distance(\n down=1,\n distance=10,\n api_key=cfbd_key,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n\n # Get the predicted PPA for a 1st and 10 play, \n # in every possible situation.\n print(\"Get the predicted PPA for a 1st and 10 play, in every possible situation.\")\n json_data = get_cfbd_predicted_ppa_from_down_distance(\n down=1,\n distance=10\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_predicted_ppa_from_down_distance(\n down=1,\n distance=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tdown: int,\tdistance: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_team_season_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_team_season_ppa_data", "kind": "function", "doc": "DataFrame
object with a calculated PPA from a dwon and distance, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with a calculated PPA from a dwon and distance.Allows you to get team PPA data, \nover an entire season,\nwith or without garbage time plays, \nfor a specificed team and/or time period.
\n\nPPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season
(int, optional):\n Semi-optional argument. \n Specifies the season you want team PPA data from.\n You MUST setseason
orteam
to a non-null value for \n this function to work. If you don't, aValueError()
\n will be raised.\n\n
team
(str, optional):\n Semi-ptional argument.\n If you only want team PPA data for a specific team,\n setteam
to the name of the team you want team PPA data from.\n You MUST setseason
orteam
to a non-null value for \n this function to work. If you don't, aValueError()
\n will be raised.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want team PPA data from games \n involving teams from a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want team PPA data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
exclude_garbage_time
(bool, optional):\n Optional argument.\n If you want to filter out plays where the result of the game is largely decided,\n setexclude_garbage_time = True
.\n Default behavior is that this variable is set to \nFalse
when this function is called.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_team_ppa_data\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get team season PPA data for the 2020 CFB season.\n print(\"Get team PPA data for the 2020 CFB season.\")\n json_data = get_cfbd_team_ppa_data(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team season PPA data for the 2020 Ohio State Buckeyes.\n print(\"Get team season PPA data for the 2020 Ohio State Buckeyes.\")\n json_data = get_cfbd_team_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team season PPA data for the 2020 Ohio State Buckeyes, \n # but exclude garbage time plays when making the PPA calculations.\n print(\"Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.\")\n json_data = get_cfbd_team_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Ohio State\",\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.\n print(\"Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.\")\n json_data = get_cfbd_team_ppa_data(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_ppa_data(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"B1G\",\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get team season PPA data for the 2020 CFB season.\n print(\"Get team PPA data for the 2020 CFB season.\")\n json_data = get_cfbd_team_ppa_data(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team season PPA data for the 2020 Ohio State Buckeyes.\n print(\"Get team season PPA data for the 2020 Ohio State Buckeyes.\")\n json_data = get_cfbd_team_ppa_data(\n season=2020,\n team=\"Ohio State\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team season PPA data for the 2020 Ohio State Buckeyes, \n # but exclude garbage time plays when making the PPA calculations.\n print(\"Get team season PPA data for the 2020 Ohio State Buckeyes, but exclude garbage time plays when making the PPA calculations.\")\n json_data = get_cfbd_team_ppa_data(\n season=2020,\n team=\"Ohio State\",\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.\n print(\"Get team season PPA data for teams in the Big 10 (B1G) Conference in the 2020 CFB Season.\")\n json_data = get_cfbd_team_ppa_data(\n season=2020,\n conference_abv=\"B1G\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_ppa_data(\n season=2020,\n conference_abv=\"B1G\",\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\texclude_garbage_time: bool = False,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_team_game_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_team_game_ppa_data", "kind": "function", "doc": "DataFrame
object with team season PPA data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with a team season PPA data.Allows you to get team PPA data, \nat a game level,\nwith or without garbage time plays, \nfor a specificed team and/or time period.
\n\nPPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
\n\nParameters
\n\n\n\n
season
(int, mandatory):\n Required argument.\n Specifies the season you want team game PPA data information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get team game PPA data information.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load team game PPA data from games in that season, and in that week.\n\n
team
(str, optional):\n Optional argument.\n If you only want team game PPA data for a team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want team game PPA data from.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want team game PPA data from games \n involving teams a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want team game PPA data from.\n\n
exclude_garbage_time
(bool, optional):\n Optional argument.\n If you want to filter out plays where the result of the game is largely decided,\n setexclude_garbage_time = True
.\n Default behavior is that this variable is set to \nFalse
when this function is called.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want team game PPA data for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_team_game_ppa_data\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get team PPA data for individual games within the 2020 CFB season.\n print(\"Get team PPA data for individual games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for week 10 games within the 2020 CFB season.\n print(\"Get team PPA data for week 10 games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for \n # University of Cincinnati football games within the 2020 CFB season.\n print(\"Get team PPA data for University of Cincinnati football games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for Southeastern Conference (SEC) \n # games within the 2020 CFB season.\n print(\"Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for Southeastern Conference (SEC) \n # games within the 2020 CFB season, but exclude plays that occur in garbage time.\n print(\"Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"SEC\",\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for postseason games in the 2020 CFB season.\n print(\"Get team PPA data for postseason games in the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\",\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get team PPA data for individual games within the 2020 CFB season.\n print(\"Get team PPA data for individual games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for week 10 games within the 2020 CFB season.\n print(\"Get team PPA data for week 10 games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for \n # University of Cincinnati football games within the 2020 CFB season.\n print(\"Get team PPA data for University of Cincinnati football games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for Southeastern Conference (SEC) \n # games within the 2020 CFB season.\n print(\"Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020,\n conference_abv=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for Southeastern Conference (SEC) \n # games within the 2020 CFB season, but exclude plays that occur in garbage time.\n print(\"Get team PPA data for Southeastern Conference (SEC) games within the 2020 CFB season, but exclude plays that occur in garbage time.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020,\n conference_abv=\"SEC\",\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get team PPA data for postseason games in the 2020 CFB season.\n print(\"Get team PPA data for postseason games in the 2020 CFB season.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_team_game_ppa_data(\n season=2020,\n team=\"Cincinnati\",\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tconference_abv: str = None,\texclude_garbage_time: bool = False,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_player_game_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_player_game_ppa_data", "kind": "function", "doc": "DataFrame
object with team PPA data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with team PPA data.Allows you to get player PPA data, \nat a game level,\nwith or without garbage time plays, \nfor a specificed time period and/or team.
\n\nPPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season
(int, semi-optional):\n Semi-Optional argument.\n Specifies the season you want player game PPA data information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get player game PPA data information.\n\n
week
(int, semi-optional):\n Semi-Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load player game PPA data from games in that season, and in that week.\nweek
and/orteam
must be set to a non-null value for this function \n to work.\n\n
team
(str, semi-optional):\n Semi-Optional argument.\n If you only want player game PPA data for players of a specific team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want player game PPA data from.\nweek
and/orteam
must be set to a non-null value for this function \n to work.\n\n
position
(str, optional):\n Optional argument.\n If you only want player game PPA data for players of a specific position, \n setposition
to the position you want player game PPA data from.\n\n
player_id
(int, optional):\n Optional argument.\n If you only want PPA data for a specific player ID, \n set this variable to the player ID of the player you want PPA data from.\n\n
play_threshold
\n Optional argument.\n If you only want PPA data for players \n who touched the ball for X number of plays in a game,\n setplay_threshold = x
, wherex
is \n your specified minimum number of plays.\n\n
exclude_garbage_time
(bool, optional):\n Optional argument.\n If you want to filter out plays where the result of the game is largely decided,\n setexclude_garbage_time = True
.\n Default behavior is that this variable is set to \nFalse
when this function is called.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want player game PPA data for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_player_game_ppa_data\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get player game PPA data for week 10 of the 2020 CFB season.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for players of the \n # 2020 University of Cincinnati Football team.\n print(\"Get player game PPA data for players of the 2020 University of Cincinnati Football team.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n week=10,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, \n # but exclude plays in garbage time.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n week=10,\n position=\"QB\",\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for week 10 of the 2020 CFB season,\n # where a player touched the ball for at least 25 plays.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n week=10,\n play_threshold=25\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data the 2020 Alabama Crimson Tide Football team, \n # during their postseason.\n print(\"Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Alabama\",\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_game_ppa_data(\n api_key=cfbd_key,\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get player game PPA data for week 10 of the 2020 CFB season.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for players of the \n # 2020 University of Cincinnati Football team.\n print(\"Get player game PPA data for players of the 2020 University of Cincinnati Football team.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n team=\"Cincinnati\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n week=10,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for QBs who played in week 10 of the 2020 CFB season, \n # but exclude plays in garbage time.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season, but exclude plays in garbage time.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n week=10,\n position=\"QB\",\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data for week 10 of the 2020 CFB season,\n # where a player touched the ball for at least 25 plays.\n print(\"Get player game PPA data for week 10 of the 2020 CFB season, where a player touched the ball for at least 25 plays.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n week=10,\n play_threshold=25\n )\n print(json_data)\n time.sleep(5)\n\n # Get player game PPA data the 2020 Alabama Crimson Tide Football team, \n # during their postseason.\n print(\"Get player game PPA data the 2020 Alabama Crimson Tide Football team, during their postseason.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n team=\"Alabama\",\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_game_ppa_data(\n season=2020,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tweek: int = None,\tteam: str = None,\tposition: str = None,\tplayer_id: int = None,\tplay_threshold: int = None,\texclude_garbage_time: bool = False,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_player_season_ppa_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_player_season_ppa_data", "kind": "function", "doc": "DataFrame
object with player PPA data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with player PPA data.Allows you to get player PPA data, \nat a season level,\nwith or without garbage time plays, \nfor a specificed time period and/or team.
\n\nPPA is the CFBD API's equivalent metric to Expected Points Added (EPA).
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season
(int, semi-optional):\n Semi-Optional argument.\n Specifies the season you want player season PPA data information from.\n This must be specified, otherwise this package, and by extension\n the CFBD API, will not accept the request to get player season PPA data information.\n\n
team
(str, semi-optional):\n Semi-Optional argument.\n If you only want player season PPA data for players of a specific team, \n regardless if they are the home/away team,\n setteam
to the name of the team you want player season PPA data from.\nweek
and/orteam
must be set to a non-null value for this function \n to work.\n\n
conference_abv
(str, optional):\n Optional argument.\n If you only want player season PPA data from games \n involving teams from a specific confrence, \n setconference_abv
to the abbreviation \n of the conference you want player season PPA data from.\n For a list of confrences, \n use thecfbd_json_py.conferences.get_cfbd_conference_info()
\n function.\n\n
position
(str, optional):\n Optional argument.\n If you only want player season PPA data for players of a specific position, \n setposition
to the position you want player season PPA data from.\n\n
player_id
(int, optional):\n Optional argument.\n If you only want PPA data for a specific player ID, \n set this variable to the player ID of the player you want PPA data from.\n\n
play_threshold
\n Optional argument.\n If you only want PPA data for players \n who touched the ball for X number of plays in a game,\n setplay_threshold = x
, wherex
is \n your specified minimum number of plays.\n\n
exclude_garbage_time
(bool, optional):\n Optional argument.\n If you want to filter out plays where the result of the game is largely decided,\n setexclude_garbage_time = True
.\n Default behavior is that this variable is set to \nFalse
when this function is called.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_player_season_ppa_data\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get player season PPA data for the 2020 CFB season.\n print(\"Get player season PPA data for the 2020 CFB season.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from the 2020 Ohio Bobcats Football Team.\n print(\"Get player season PPA data for the 2020 Ohio Bobcats Football Team.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n season=2020,\n team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data for players who played on\n # teams within the Southeastern Conference (SEC) for the\n # 2020 CFB Season.\n print(\"Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n season=2020,\n conference_abv=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from QBs in the 2020 CFB Season.\n print(\"Get player season PPA data from QBs in the 2020 CFB Season.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n season=2020,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from\n # former Ohio State and LSU QB Joe Burrow (player ID #3915511).\n print(\"Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n player_id=3915511\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from\n # former Ohio State and LSU QB Joe Burrow (player ID #3915511),\n # but exclude plays that occured in garbage time.\n print(\"Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n player_id=3915511,\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from the 2020 CFB Season,\n # for players with at least 100 plays/touches.\n print(\"Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n season=2020,\n play_threshold=100\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_season_ppa_data(\n api_key=cfbd_key,\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get player season PPA data for the 2020 CFB season.\n print(\"Get player season PPA data for the 2020 CFB season.\")\n json_data = get_cfbd_player_season_ppa_data(\n season=2020\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from the 2020 Ohio Bobcats Football Team.\n print(\"Get player season PPA data for the 2020 Ohio Bobcats Football Team.\")\n json_data = get_cfbd_player_season_ppa_data(\n season=2020,\n team=\"Ohio\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data for players who played on\n # teams within the Southeastern Conference (SEC) for the\n # 2020 CFB Season.\n print(\"Get player season PPA data for players who played on teams within the Southeastern Conference (SEC) for the 2020 CFB Season.\")\n json_data = get_cfbd_player_season_ppa_data(\n season=2020,\n conference_abv=\"SEC\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from QBs in the 2020 CFB Season.\n print(\"Get player season PPA data from QBs in the 2020 CFB Season.\")\n json_data = get_cfbd_player_season_ppa_data(\n season=2020,\n position=\"QB\"\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from\n # former Ohio State and LSU QB Joe Burrow (player ID #3915511).\n print(\"Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511).\")\n json_data = get_cfbd_player_season_ppa_data(\n player_id=3915511\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from\n # former Ohio State and LSU QB Joe Burrow (player ID #3915511),\n # but exclude plays that occured in garbage time.\n print(\"Get player season PPA data from former Ohio State and LSU QB Joe Burrow (player ID #3915511), but exclude plays that occured in garbage time.\")\n json_data = get_cfbd_player_season_ppa_data(\n player_id=3915511,\n exclude_garbage_time=True\n )\n print(json_data)\n time.sleep(5)\n\n # Get player season PPA data from the 2020 CFB Season,\n # for players with at least 100 plays/touches.\n print(\"Get player season PPA data from the 2020 CFB Season, for players with at least 100 plays/touches.\")\n json_data = get_cfbd_player_season_ppa_data(\n season=2020,\n play_threshold=100\n )\n print(json_data)\n time.sleep(5)\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_player_season_ppa_data(\n season=2020,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\tposition: str = None,\tplayer_id: int = None,\tplay_threshold: int = None,\texclude_garbage_time: bool = False,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_game_win_probability_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_game_win_probability_data", "kind": "function", "doc": "DataFrame
object with player PPA data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with player PPA data.Allows one to get win probabliity data for a given game ID.
\n\nParameters
\n\n\n\n
game_id
(int, mandatory):\n Mandatory argument.\n This is the game ID for the game you want win probability data from,\n at the play-by-play level.\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_game_win_probability_data\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get the win probablility data for a 2017 game between \n # the University of Cincinnati and UConn (game ID #400941851).\n print(\"Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).\")\n json_data = get_cfbd_game_win_probability_data(\n api_key=cfbd_key,\n game_id=400941851\n )\n print(json_data)\n time.sleep(5)\n\n # Get the win probablility data for a 2023 game between \n # the University of Duke and the University of Louisville (game ID #401525535).\n print(\"Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).\")\n json_data = get_cfbd_game_win_probability_data(\n api_key=cfbd_key,\n game_id=401525535\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_game_win_probability_data(\n api_key=cfbd_key,\n game_id=400941851,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n # Get win probablility data for a 2017 game between \n # the University of Cincinnati and UConn (game ID #400941851).\n print(\"Get the win probablility data for a 2017 game between the University of Cincinnati and UConn (game ID #400941851).\")\n json_data = get_cfbd_game_win_probability_data(\n game_id=400941851\n )\n print(json_data)\n time.sleep(5)\n\n # Get win probablility data for a 2023 game between \n # the University of Duke and the University of Louisville (game ID #401525535).\n print(\"Get the win probablility data for a 2023 game between the University of Duke and the University of Louisville (game ID #401525535).\")\n json_data = get_cfbd_game_win_probability_data(\n game_id=401525535\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_game_win_probability_data(\n game_id=400941851,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tgame_id: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.metrics.get_cfbd_pregame_win_probability_data", "modulename": "cfbd_json_py.metrics", "qualname": "get_cfbd_pregame_win_probability_data", "kind": "function", "doc": "DataFrame
object with win probability data at the play-by-play level,\nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with win probability data at the play-by-play level.Allows you to get pregame win probability data for games within a timeframe.
\n\nParameters
\n\n\n\n
api_key
(str, optional):\n Semi-optional argument. \n Ifapi_key
is null, this function will attempt to load a CFBD API key\n from the python environment, or from a file on this computer.\n Ifapi_key
is not null, this function will automatically assume that the\n inputtedapi_key
is a valid CFBD API key.\n\n
api_key_dir
(str, optional):\n Optional argument.\n Ifapi_key
is set to am empty string, this variable is ignored.\n Ifapi_key_dir
is null, andapi_key
is null, \n this function will try to find a CFBD API key file in this user's home directory.\n Ifapi_key_dir
is set to a string, andapi_key
is null,\n this function will assume thatapi_key_dir
is a directory, \n and will try to find a CFBD API key file in that directory.\n\n
season
(int, optional):\n Semi-optional argument. \n Specifies the season you want pregame win probability data.\n\n
week
(int, optional):\n Optional argument.\n Ifweek
is set to an integer, this function will attempt \n to load CFB game data from games in that season, and in that week.\n\n
team
(str, optional):\n Semi-ptional argument.\n If you only want pregame win probability data for a specific team,\n setteam
to the name of the team you want pregame win probability data from.\n\n
season_type
(str, semi-optional):\n Semi-optional argument.\n By defualt, this will be set to \"regular\", for the CFB regular season.\n If you want CFB game information for non-regular season games, \n setseason_type
to \"postseason\".\n Ifseason_type
is set to anything but \"regular\" or \"postseason\", \n aValueError()
will be raised.\n\n
return_as_dict
(bool, semi-optional):\n Semi-optional argument.\n If you want this function to return the data as a dictionary (read: JSON object), \n instead of a pandasDataFrame
object,\n setreturn_as_dict
toTrue
.Usage
\n\n\n\nimport time\n\nfrom cfbd_json_py.metrics import get_cfbd_pregame_win_probability_data\n\n\ncfbd_key = \"tigersAreAwsome\" # placeholder for your CFBD API Key.\n\nif cfbd_key != \"tigersAreAwsome\":\n print(\"Using the user's API key declared in this script for this example.\")\n\n # Get pregame win probabilities for games in the 2023 CFB season.\n print(\"Get pregame win probabilities for games in the 2023 CFB season.\")\n json_data = get_cfbd_pregame_win_probability_data(\n api_key=cfbd_key,\n season=2023\n )\n print(json_data)\n time.sleep(5)\n\n\n # Get pregame win probabilities for games in week 10 of the 2021 CFB season.\n print(\"Get pregame win probabilities for games in week 10 of the 2021 CFB season.\")\n json_data = get_cfbd_pregame_win_probability_data(\n api_key=cfbd_key,\n season=2021,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n\n # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.\n print(\"Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.\")\n json_data = get_cfbd_pregame_win_probability_data(\n api_key=cfbd_key,\n season=2021,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n\n # Get pregame win probabilities for postseason games in the 2020 CFB season.\n print(\"Get pregame win probabilities for postseason games in the 2020 CFB season.\")\n json_data = get_cfbd_pregame_win_probability_data(\n api_key=cfbd_key,\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_pregame_win_probability_data(\n api_key=cfbd_key,\n season=2023,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\nelse:\n # Alternatively, if the CFBD API key exists in this python environment,\n # or it's been set by cfbd_json_py.utls.set_cfbd_api_token(),\n # you could just call these functions directly, without setting the API key\n # in the script.\n print(\"Using the user's API key suposedly loaded into this python environment for this example.\")\n\n# Get pregame win probabilities for games in the 2023 CFB season.\n print(\"Get pregame win probabilities for games in the 2023 CFB season.\")\n json_data = get_cfbd_pregame_win_probability_data(\n season=2023\n )\n print(json_data)\n time.sleep(5)\n\n\n # Get pregame win probabilities for games in week 10 of the 2021 CFB season.\n print(\"Get pregame win probabilities for games in week 10 of the 2021 CFB season.\")\n json_data = get_cfbd_pregame_win_probability_data(\n season=2021,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n\n # Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.\n print(\"Get pregame win probabilities for games involving the 2021 Cincinnati Bearcats Football Team.\")\n json_data = get_cfbd_pregame_win_probability_data(\n season=2021,\n week=10\n )\n print(json_data)\n time.sleep(5)\n\n\n # Get pregame win probabilities for postseason games in the 2020 CFB season.\n print(\"Get pregame win probabilities for postseason games in the 2020 CFB season.\")\n json_data = get_cfbd_pregame_win_probability_data(\n season=2020,\n season_type=\"postseason\"\n )\n print(json_data)\n time.sleep(5)\n\n\n # You can also tell this function to just return the API call as\n # a Dictionary (read: JSON) object.\n print(\"You can also tell this function to just return the API call as a Dictionary (read: JSON) object.\")\n json_data = get_cfbd_pregame_win_probability_data(\n season=2023,\n week=10,\n return_as_dict=True\n )\n print(json_data)\n\n
Returns
\n\nA pandas
\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players", "modulename": "cfbd_json_py.players", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.players.cfbd_player_search", "modulename": "cfbd_json_py.players", "qualname": "cfbd_player_search", "kind": "function", "doc": "\n", "signature": "(\tsearch_str: str,\tapi_key: str = None,\tapi_key_dir: str = None,\tposition: str = None,\tteam: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_player_usage", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_player_usage", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\tposition: str = None,\tplayer_id: int = None,\texclude_garbage_time: bool = False,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_returning_production", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_returning_production", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_player_season_stats", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_player_season_stats", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tconference_abv: str = None,\tstart_week: int = None,\tend_week: int = None,\tseason_type: str = 'regular',\tstat_category: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.players.get_cfbd_transfer_portal_data", "modulename": "cfbd_json_py.players", "qualname": "get_cfbd_transfer_portal_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays", "modulename": "cfbd_json_py.plays", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_data", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_data", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\toffensive_team: str = None,\tdefensive_team: str = None,\tconference_abv: str = None,\toffensive_conference_abv: str = None,\tdefensive_conference_abv: str = None,\tplay_type: int = None,\tncaa_division: str = 'fbs',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_play_types", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_play_types", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_stats", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_stats", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tteam: str = None,\tgame_id: int = None,\tathlete_id: int = None,\tstat_type_id: int = None,\tseason_type: str = 'regular',\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_pbp_stat_types", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_pbp_stat_types", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.plays.get_cfbd_live_pbp_data", "modulename": "cfbd_json_py.plays", "qualname": "get_cfbd_live_pbp_data", "kind": "function", "doc": "\n", "signature": "(\tgame_id: int,\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.rankings", "modulename": "cfbd_json_py.rankings", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.rankings.get_cfbd_poll_rankings", "modulename": "cfbd_json_py.rankings", "qualname": "get_cfbd_poll_rankings", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings", "modulename": "cfbd_json_py.ratings", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_sp_plus_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_sp_plus_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_srs_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_srs_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: int = None,\tconferenece: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_sp_plus_conference_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_sp_plus_conference_ratings", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.ratings.get_cfbd_elo_ratings", "modulename": "cfbd_json_py.ratings", "qualname": "get_cfbd_elo_ratings", "kind": "function", "doc": "\n", "signature": "(\tseason: int,\tapi_key: str = None,\tapi_key_dir: str = None,\tweek: int = None,\tseason_type: str = 'regular',\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.recruiting", "modulename": "cfbd_json_py.recruiting", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.recruiting.get_cfbd_player_recruit_ratings", "modulename": "cfbd_json_py.recruiting", "qualname": "get_cfbd_player_recruit_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\trecruit_classification: str = 'HighSchool',\tposition: str = None,\tstate: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.recruiting.get_cfbd_team_recruiting_ratings", "modulename": "cfbd_json_py.recruiting", "qualname": "get_cfbd_team_recruiting_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.recruiting.get_cfbd_team_recruiting_group_ratings", "modulename": "cfbd_json_py.recruiting", "qualname": "get_cfbd_team_recruiting_group_ratings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tstart_season: int = None,\tend_season: int = None,\tteam: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats", "modulename": "cfbd_json_py.stats", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.stats.get_cfbd_team_season_stats", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_team_season_stats", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tconference_abv: str = None,\tstart_week: int = None,\tend_week: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats.get_cfbd_advanced_team_season_stats", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_advanced_team_season_stats", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\texclude_garbage_time: bool = False,\tstart_week: int = None,\tend_week: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats.get_cfbd_advanced_team_game_stats", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_advanced_team_game_stats", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\tteam: str = None,\tweek: int = None,\topponent: str = None,\texclude_garbage_time: bool = False,\tseason_type: str = 'regular',\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.stats.get_cfbd_team_stat_categories", "modulename": "cfbd_json_py.stats", "qualname": "get_cfbd_team_stat_categories", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams", "modulename": "cfbd_json_py.teams", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_information", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_information", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tconference_abv: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_fbs_team_list", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_fbs_team_list", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_rosters", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_rosters", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tteam: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_talent_rankings", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_talent_rankings", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\tseason: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.teams.get_cfbd_team_matchup_history", "modulename": "cfbd_json_py.teams", "qualname": "get_cfbd_team_matchup_history", "kind": "function", "doc": "\n", "signature": "(\tteam_1: str,\tteam_2: str,\tapi_key: str = None,\tapi_key_dir: str = None,\tmin_season: int = None,\tmax_season: int = None,\treturn_as_dict: bool = False):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls", "modulename": "cfbd_json_py.utls", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.utls.reverse_cipher_encrypt", "modulename": "cfbd_json_py.utls", "qualname": "reverse_cipher_encrypt", "kind": "function", "doc": "DataFrame
object with pregame win probability data, \nor (ifreturn_as_dict
is set toTrue
) \na dictionary object with a pregame win probability data.NOT INTENDED TO BE CALLED BY THE USER!
\n\nImplements a reverse cipher encription to a plain text string.
\n\nParameters
\n\n\n\n
plain_text_str
(mandatory, str):\n The string you want to encrypt through reverse cipher encryption.Returns
\n\nA string encrypted through reverse cipher encryption.
\n", "signature": "(plain_text_str: str):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls.reverse_cipher_decrypt", "modulename": "cfbd_json_py.utls", "qualname": "reverse_cipher_decrypt", "kind": "function", "doc": "NOT INTENDED TO BE CALLED BY THE USER!
\n\nDecrypts a string that was presumed to be encrypted by a reverse cipher encryption.
\n\nParameters
\n\n\n\n
encrypted_text_str
(mandatory, str):\n The string you presume that is encrypted through reverse cipher encryption, \n that you want decrypted.Returns
\n\nA decrypted string.
\n", "signature": "(encrypted_text_str: str):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls.get_cfbd_api_token", "modulename": "cfbd_json_py.utls", "qualname": "get_cfbd_api_token", "kind": "function", "doc": "NOT INTENDED TO BE CALLED BY THE USER!
\n\nIf you've already set the API key using \n
\n\ncfbd_json_py.utls.set_cfbd_api_token()
,\nyou don't need to use this function.If the CFBD API key exists in the environment, \nor is in a file, this function retrives the CFBD API key, \nand returns it as a string.
\n\nIf this package is being used in a GitHub Actions action,\nset the key in the environment by \ncreating a repository secret nammed
\n\nCFBD_API_KEY
.Parameters
\n\n\n\n
api_key_dir
(str, optional):\n Optional argument. Ifapi_key_dir
is set to a non-null string, \nset_cfbd_api_token()
will attempt to save the key file in that directory,\n instead of this user's home directory.Returns
\n\nA CFBD API key that exists within this python environment,\nor within this computer.
\n", "signature": "(api_key_dir: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.utls.set_cfbd_api_token", "modulename": "cfbd_json_py.utls", "qualname": "set_cfbd_api_token", "kind": "function", "doc": "Sets the CFBD API key into a file that exists \neither in
\n\n{home_dir}/.cfbd/cfbd_key.json
, or in a custom directory.Parameters
\n\n\n\n
api_key
(str, mandatory):\n The CFBD API key you have. \n DO NOT inputBearer {your CFBD API key}
,\n this package will take care of that for you.\n\n
api_key_dir
(str, optional):\n Optional argument. Ifapi_key_dir
is set to a non-null string, \nset_cfbd_api_token()
will attempt to save the key file in that directory,\n instead of this user's home directory.Returns
\n\nNothing. \nThis function only sets up the API key file that this package can reference later.
\n", "signature": "(api_key: str, api_key_dir: str = None):", "funcdef": "def"}, {"fullname": "cfbd_json_py.venues", "modulename": "cfbd_json_py.venues", "kind": "module", "doc": "\n"}, {"fullname": "cfbd_json_py.venues.get_cfbd_venues", "modulename": "cfbd_json_py.venues", "qualname": "get_cfbd_venues", "kind": "function", "doc": "\n", "signature": "(\tapi_key: str = None,\tapi_key_dir: str = None,\treturn_as_dict: bool = False):", "funcdef": "def"}]; // mirrored in build-search-index.js (part 1) // Also split on html tags. this is a cheap heuristic, but good enough. diff --git a/pyproject.toml b/pyproject.toml index f06f8d6..fab3b43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cfbd_json_py" -version = "0.0.9" +version = "0.0.10" readme = "README.md" requires-python = ">=3.10" license = {text = "MIT"}