From 889e389676f0a408e0b1cdf9c38f4ba4858c59ed Mon Sep 17 00:00:00 2001 From: Joseph Armstrong <70788681+armstjc@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:10:38 -0400 Subject: [PATCH] 0.2.0 The "Patreon" Update - Re-implemented the process of storing a user's API key. If you have used `cfbd_json_py.utls.set_cfbd_api_token()` in the past, you do not need to do anything to migrate your API key to this new process. - The following functions require a user to subscribe to the [CFBD Patreon](https://www.patreon.com/collegefootballdata): - Implemented `cfbd_json_py.games.get_cfbd_live_scoreboard()`, a function that allows a user to get live scoreboard data directly from the CFBD API, if they subscribe to the CFBD patreon. - Implemented `cfbd_json_py.games.get_cfbd_weather_info()`, a function that allows a user to get weather data directly from the CFBD API, if they subscribe to the CFBD patreon. - Partially implemented `cfbd_json_py.plays.get_cfbd_live_pbp_data()`, a function that allows someone to access live play-by-play (PBP) data, if they subscribe to the CFBD patreon. - Implemented a new file header template for all python files. - Applied some minor formatting changes to the python code. - Updated the package version to `0.2.0`, because of the new season (2024). --- CHANGELOG.md | 13 +- cfbd_json_py/_early_access.py | 4 +- cfbd_json_py/betting.py | 4 +- cfbd_json_py/coaches.py | 4 +- cfbd_json_py/conferences.py | 6 +- cfbd_json_py/draft.py | 8 +- cfbd_json_py/drives.py | 8 +- cfbd_json_py/games.py | 1568 +- cfbd_json_py/metrics.py | 6 +- cfbd_json_py/players.py | 4 +- cfbd_json_py/plays.py | 52 +- cfbd_json_py/rankings.py | 6 +- cfbd_json_py/ratings.py | 6 +- cfbd_json_py/recruiting.py | 6 +- cfbd_json_py/stats.py | 6 +- cfbd_json_py/teams.py | 5 +- cfbd_json_py/utls.py | 86 +- cfbd_json_py/venues.py | 6 +- docs/cfbd_json_py.html | 2069 ++- docs/cfbd_json_py/_early_access.html | 1882 ++- docs/cfbd_json_py/betting.html | 4203 +++-- docs/cfbd_json_py/coaches.html | 3870 +++-- docs/cfbd_json_py/conferences.html | 2589 ++- docs/cfbd_json_py/draft.html | 5315 +++--- docs/cfbd_json_py/drives.html | 4797 ++++-- docs/cfbd_json_py/games.html | 21476 +++++++++++++++---------- docs/cfbd_json_py/metrics.html | 14465 +++++++++-------- docs/cfbd_json_py/players.html | 13351 ++++++++------- docs/cfbd_json_py/plays.html | 8032 +++++---- docs/cfbd_json_py/rankings.html | 2028 ++- docs/cfbd_json_py/ratings.html | 8659 ++++++---- docs/cfbd_json_py/recruiting.html | 6390 +++++--- docs/cfbd_json_py/stats.html | 10091 +++++++----- docs/cfbd_json_py/teams.html | 7430 +++++---- docs/cfbd_json_py/utls.html | 2972 +++- docs/cfbd_json_py/venues.html | 2642 ++- docs/index.html | 6 +- docs/search.js | 1722 +- pyproject.toml | 10 +- 39 files changed, 78779 insertions(+), 47018 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3860780..5de8a0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # CHANGELOG: cfbd_json_py +## 0.2.0 The "Patreon" Update +- Re-implemented the process of storing a user's API key. If you have used `cfbd_json_py.utls.set_cfbd_api_token()` in the past, you do not need to do anything to migrate your API key to this new process. +- The following functions require a user to subscribe to the [CFBD Patreon](https://www.patreon.com/collegefootballdata): + - Implemented `cfbd_json_py.games.get_cfbd_live_scoreboard()`, a function that allows a user to get live scoreboard data directly from the CFBD API, if they subscribe to the CFBD patreon. + - Implemented `cfbd_json_py.games.get_cfbd_weather_info()`, a function that allows a user to get weather data directly from the CFBD API, if they subscribe to the CFBD patreon. + - Partially implemented `cfbd_json_py.plays.get_cfbd_live_pbp_data()`, a function that allows someone to access live play-by-play (PBP) data, if they subscribe to the CFBD patreon. +- Implemented a new file header template for all python files. +- Applied some minor formatting changes to the python code. +- Updated the package version to `0.2.0`, because of the new season (2024). + + ## 0.1.2: The "Spell Check" update - Fixed spelling errors previously present in earlier versions of this python package. - Updated the package version to `0.1.2`. @@ -173,7 +184,7 @@ - Removed the option to cache data. This may be implemented in a future version. - Implemented `cfbd_json_py.betting.get_cfbd_betting_lines()`, a function that allows a user to get betting lines for a season, a week, and/or for a specific team for the regular season, or postseason. -- Changed `cfbd_json_py.utls.get_cfbd_api_token()`` to log, not print out the fact that the CFBD API key the function is trying to find is not present in the current Python environment. +- Changed `cfbd_json_py.utls.get_cfbd_api_token()` to log, not print out the fact that the CFBD API key the function is trying to find is not present in the current Python environment. - Updated the package version to `0.0.2`. ## 0.0.1: The "First Steps" Update diff --git a/cfbd_json_py/_early_access.py b/cfbd_json_py/_early_access.py index 4fcd627..1f3d01d 100644 --- a/cfbd_json_py/_early_access.py +++ b/cfbd_json_py/_early_access.py @@ -17,8 +17,8 @@ def about_early_access_functions(): print( - "Early Access functions are functions " - + "generated by a generator script " + "Early Access functions are functions:\n" + + "Generated by a generator script " + "when an API endpoint is created, " + "but not implemented yet by this python package." ) diff --git a/cfbd_json_py/betting.py b/cfbd_json_py/betting.py index f36cbca..726cf23 100644 --- a/cfbd_json_py/betting.py +++ b/cfbd_json_py/betting.py @@ -1,11 +1,9 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: betting.py # Purpose: Houses functions pertaining to betting data within the CFBD API. ############################################################################### -""" import warnings diff --git a/cfbd_json_py/coaches.py b/cfbd_json_py/coaches.py index 916363a..1c0fde6 100644 --- a/cfbd_json_py/coaches.py +++ b/cfbd_json_py/coaches.py @@ -1,11 +1,9 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 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 warnings diff --git a/cfbd_json_py/conferences.py b/cfbd_json_py/conferences.py index 896cc15..605f8c7 100644 --- a/cfbd_json_py/conferences.py +++ b/cfbd_json_py/conferences.py @@ -1,12 +1,10 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: conferences.py # Purpose: Houses functions pertaining to CFB conference data - within the CFBD API. +# within the CFBD API. ############################################################################### -""" import pandas as pd import requests diff --git a/cfbd_json_py/draft.py b/cfbd_json_py/draft.py index 74d3889..0519c14 100644 --- a/cfbd_json_py/draft.py +++ b/cfbd_json_py/draft.py @@ -1,19 +1,17 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: draft.py # Purpose: Houses functions pertaining to NFL Draft data within the CFBD API. ############################################################################### -""" -from datetime import datetime import logging +from datetime import datetime + import pandas as pd import requests # from tqdm import tqdm - from cfbd_json_py.utls import get_cfbd_api_token diff --git a/cfbd_json_py/drives.py b/cfbd_json_py/drives.py index fe6844a..1eedba2 100644 --- a/cfbd_json_py/drives.py +++ b/cfbd_json_py/drives.py @@ -1,18 +1,16 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: drives.py # Purpose: Houses functions pertaining to CFB drive data within the CFBD API. ############################################################################### -""" -from datetime import datetime import logging +from datetime import datetime + import pandas as pd import requests - from cfbd_json_py.utls import get_cfbd_api_token diff --git a/cfbd_json_py/games.py b/cfbd_json_py/games.py index aad5368..f69c936 100644 --- a/cfbd_json_py/games.py +++ b/cfbd_json_py/games.py @@ -1,13 +1,12 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: games.py # Purpose: Houses functions pertaining to CFB game data within the CFBD API. ############################################################################### -""" -from datetime import datetime + import logging +from datetime import datetime import pandas as pd import requests @@ -2022,8 +2021,12 @@ def get_cfbd_player_game_stats( # `week`, `team`, and/or `conference` # must be not null for this function to work. - if week is None and team is None \ - and conference is None and game_id is None: + if ( + week is None and + team is None and + conference is None and + game_id is None + ): raise ValueError( "To use `get_cfbd_player_game_stats()`," + " `week`, `team`, and/or `conference` " @@ -2153,18 +2156,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "passing_C/ATT"] = player_stat + "passing_C/ATT" + ] = player_stat elif stat["name"] == "YDS": # passing_YDS for i in stat["athletes"]: @@ -2175,21 +2183,25 @@ def get_cfbd_player_game_stats( if rebuilt_json.get(player_id) is None: rebuilt_json[player_id] = {} + rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "game_id"] = game_id - rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "passing_YDS"] = player_stat + "passing_YDS" + ] = player_stat elif stat["name"] == "AVG": # passing_AVG for i in stat["athletes"]: @@ -2202,18 +2214,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "passing_AVG"] = player_stat + "passing_AVG" + ] = player_stat elif stat["name"] == "TD": # passing_TD for i in stat["athletes"]: @@ -2226,18 +2243,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "passing_TD"] = player_stat + "passing_TD" + ] = player_stat elif stat["name"] == "INT": # passing_INT for i in stat["athletes"]: @@ -2250,18 +2272,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "passing_INT"] = player_stat + "passing_INT" + ] = player_stat elif stat["name"] == "QBR": # passing_QBR for i in stat["athletes"]: @@ -2277,18 +2304,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "passing_QBR"] = player_stat + "passing_QBR" + ] = player_stat else: raise IndexError( @@ -2308,18 +2340,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "rushing_CAR"] = player_stat + "rushing_CAR" + ] = player_stat elif stat["name"] == "YDS": # rushing_YDS for i in stat["athletes"]: @@ -2332,18 +2369,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "rushing_YDS"] = player_stat + "rushing_YDS" + ] = player_stat elif stat["name"] == "AVG": # rushing_AVG for i in stat["athletes"]: @@ -2356,18 +2398,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "rushing_AVG"] = player_stat + "rushing_AVG" + ] = player_stat elif stat["name"] == "TD": # rushing_TD for i in stat["athletes"]: @@ -2380,18 +2427,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "rushing_TD"] = player_stat + "rushing_TD" + ] = player_stat elif stat["name"] == "LONG": # rushing_LONG for i in stat["athletes"]: @@ -2404,18 +2456,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "rushing_LONG"] = player_stat + "rushing_LONG" + ] = player_stat else: raise IndexError( @@ -2435,18 +2492,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "receiving_REC"] = player_stat + "receiving_REC" + ] = player_stat elif stat["name"] == "YDS": # receiving_YDS for i in stat["athletes"]: @@ -2459,18 +2521,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "receiving_YDS"] = player_stat + "receiving_YDS" + ] = player_stat elif stat["name"] == "AVG": # receiving_AVG for i in stat["athletes"]: @@ -2483,18 +2550,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "receiving_AVG"] = player_stat + "receiving_AVG" + ] = player_stat elif stat["name"] == "TD": # receiving_TD for i in stat["athletes"]: @@ -2507,18 +2579,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "receiving_TD"] = player_stat + "receiving_TD" + ] = player_stat elif stat["name"] == "LONG": # receiving_LONG for i in stat["athletes"]: @@ -2531,18 +2608,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "receiving_LONG"] = player_stat + "receiving_LONG" + ] = player_stat else: raise IndexError( @@ -2562,18 +2644,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "fumbles_FUM"] = player_stat + "fumbles_FUM" + ] = player_stat elif stat["name"] == "LOST": # fumbles_LOST for i in stat["athletes"]: @@ -2586,18 +2673,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "fumbles_LOST"] = player_stat + "fumbles_LOST" + ] = player_stat elif stat["name"] == "REC": # fumbles_REC for i in stat["athletes"]: @@ -2610,18 +2702,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "fumbles_REC"] = player_stat + "fumbles_REC" + ] = player_stat else: raise IndexError( @@ -2641,18 +2738,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "defensive_TOT"] = player_stat + "defensive_TOT" + ] = player_stat elif stat["name"] == "SOLO": # defensive_SOLO for i in stat["athletes"]: @@ -2665,18 +2767,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "defensive_SOLO"] = player_stat + "defensive_SOLO" + ] = player_stat elif stat["name"] == "TFL": # defensive_TFL for i in stat["athletes"]: @@ -2689,18 +2796,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "defensive_TFL"] = player_stat + "defensive_TFL" + ] = player_stat elif stat["name"] == "QB HUR": # defensive_QB HUR for i in stat["athletes"]: @@ -2713,16 +2825,20 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ "defensive_QB HUR" ] = player_stat @@ -2738,18 +2854,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "defensive_SACKS"] = player_stat + "defensive_SACKS" + ] = player_stat elif stat["name"] == "PD": # defensive_PD for i in stat["athletes"]: @@ -2762,18 +2883,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "defensive_PD"] = player_stat + "defensive_PD" + ] = player_stat elif stat["name"] == "TD": # defensive_TD for i in stat["athletes"]: @@ -2786,18 +2912,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "defensive_TD"] = player_stat + "defensive_TD" + ] = player_stat else: raise IndexError( @@ -2817,16 +2948,20 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ "interceptions_INT" ] = player_stat @@ -2842,16 +2977,20 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ "interceptions_YDS" ] = player_stat @@ -2867,16 +3006,20 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ "interceptions_TD" ] = player_stat @@ -2899,18 +3042,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "punting_NO"] = player_stat + "punting_NO" + ] = player_stat elif stat["name"] == "YDS": # punting_YDS for i in stat["athletes"]: @@ -2923,18 +3071,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "punting_YDS"] = player_stat + "punting_YDS" + ] = player_stat elif stat["name"] == "AVG": # punting_AVG for i in stat["athletes"]: @@ -2947,18 +3100,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "punting_AVG"] = player_stat + "punting_AVG" + ] = player_stat elif stat["name"] == "TB": # punting_TB for i in stat["athletes"]: @@ -2971,18 +3129,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "punting_TB"] = player_stat + "punting_TB" + ] = player_stat elif stat["name"] == "In 20": # punting_In 20 for i in stat["athletes"]: @@ -2995,18 +3158,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "punting_In 20"] = player_stat + "punting_In 20" + ] = player_stat elif stat["name"] == "LONG": # punting_LONG for i in stat["athletes"]: @@ -3019,18 +3187,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "punting_LONG"] = player_stat + "punting_LONG" + ] = player_stat else: raise IndexError( @@ -3050,18 +3223,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kicking_FG"] = player_stat + "kicking_FG" + ] = player_stat elif stat["name"] == "TOT": # kicking_FG, special case for i in stat["athletes"]: @@ -3074,18 +3252,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kicking_FG"] = player_stat + "kicking_FG" + ] = player_stat elif stat["name"] == "PCT": # kicking_PCT for i in stat["athletes"]: @@ -3098,18 +3281,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kicking_PCT"] = player_stat + "kicking_PCT" + ] = player_stat elif stat["name"] == "LONG": # kicking_LONG for i in stat["athletes"]: @@ -3122,18 +3310,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kicking_LONG"] = player_stat + "kicking_LONG" + ] = player_stat elif stat["name"] == "XP": # kicking_XP for i in stat["athletes"]: @@ -3146,18 +3339,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kicking_XP"] = player_stat + "kicking_XP" + ] = player_stat elif stat["name"] == "PTS": # kicking_PTS for i in stat["athletes"]: @@ -3170,18 +3368,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kicking_PTS"] = player_stat + "kicking_PTS" + ] = player_stat else: raise IndexError( @@ -3201,18 +3404,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kickReturns_NO"] = player_stat + "kickReturns_NO" + ] = player_stat elif stat["name"] == "YDS": # kickReturns_YDS for i in stat["athletes"]: @@ -3225,18 +3433,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kickReturns_YDS"] = player_stat + "kickReturns_YDS" + ] = player_stat elif stat["name"] == "AVG": # kickReturns_AVG for i in stat["athletes"]: @@ -3249,18 +3462,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kickReturns_AVG"] = player_stat + "kickReturns_AVG" + ] = player_stat elif stat["name"] == "TD": # kickReturns_TD for i in stat["athletes"]: @@ -3273,18 +3491,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "kickReturns_TD"] = player_stat + "kickReturns_TD" + ] = player_stat elif stat["name"] == "LONG": # kickReturns_LONG for i in stat["athletes"]: @@ -3297,16 +3520,20 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ "kickReturns_LONG" ] = player_stat @@ -3329,18 +3556,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "puntReturns_NO"] = player_stat + "puntReturns_NO" + ] = player_stat elif stat["name"] == "YDS": # puntReturns_YDS for i in stat["athletes"]: @@ -3353,18 +3585,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "puntReturns_YDS"] = player_stat + "puntReturns_YDS" + ] = player_stat elif stat["name"] == "AVG": # puntReturns_AVG for i in stat["athletes"]: @@ -3377,18 +3614,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "puntReturns_AVG"] = player_stat + "puntReturns_AVG" + ] = player_stat elif stat["name"] == "TD": # puntReturns_TD for i in stat["athletes"]: @@ -3401,18 +3643,23 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ - "puntReturns_TD"] = player_stat + "puntReturns_TD" + ] = player_stat elif stat["name"] == "LONG": # puntReturns_LONG for i in stat["athletes"]: @@ -3425,16 +3672,20 @@ def get_cfbd_player_game_stats( rebuilt_json[player_id]["game_id"] = game_id rebuilt_json[player_id][ - "team_name"] = team_name + "team_name" + ] = team_name rebuilt_json[player_id][ "team_conference" ] = team_conference rebuilt_json[player_id][ - "player_id"] = player_id + "player_id" + ] = player_id rebuilt_json[player_id][ - "player_name"] = player_name + "player_name" + ] = player_name rebuilt_json[player_id][ - "home_away"] = home_away + "home_away" + ] = home_away rebuilt_json[player_id][ "puntReturns_LONG" ] = player_stat @@ -3459,11 +3710,13 @@ def get_cfbd_player_game_stats( ].str.split("/", expand=True) cfb_games_df[["kicking_FGM", "kicking_FGA"]] = cfb_games_df[ - "kicking_FG"].str.split( + "kicking_FG" + ].str.split( "/", expand=True ) cfb_games_df[["kicking_XPM", "kicking_XPA"]] = cfb_games_df[ - "kicking_XP"].str.split( + "kicking_XP" + ].str.split( "/", expand=True ) @@ -3933,14 +4186,16 @@ def get_cfbd_player_advanced_game_stats( # Add in these columns for completeness. - adv_stats_df.loc[adv_stats_df["team"] == home_team_name, - "home_away"] = "home" + adv_stats_df.loc[ + adv_stats_df["team"] == home_team_name, "home_away" + ] = "home" adv_stats_df.loc[adv_stats_df["team"] == home_team_name, "opponent"] = ( away_team_name ) - adv_stats_df.loc[adv_stats_df["team"] == away_team_name, - "home_away"] = "away" + adv_stats_df.loc[ + adv_stats_df["team"] == away_team_name, "home_away" + ] = "away" adv_stats_df.loc[adv_stats_df["team"] == away_team_name, "opponent"] = ( home_team_name ) @@ -3968,39 +4223,780 @@ def get_cfbd_player_advanced_game_stats( def get_cfbd_live_scoreboard( - api_key: str = None, - api_key_dir: str = None, ncaa_division: str = "fbs", conference: str = None, + api_key: str = None, + api_key_dir: str = None, + return_as_dict: bool = False, ): """ YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK! To view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata + Retrieves live scoreboard data from the CFBD API, + assuming the API key is an API key from a Patreon supporter. - """ + Parameters + ---------- + `ncaa_division` (str, semi-optional): + Semi-optional argument. + By default, `ncaa_division` will be set to "fbs", + short for the Football Bowl Subdivision (FBS), + formerly known as D1-A (read as "division one single A"), + the highest level in the NCAA football pyramid, + where teams can scholarship up to 85 players + on their football team solely for athletic ability, + and often have the largest athletics budgets + within the NCAA. - raise NotImplementedError( - "This function has yet to be implemented by this version." - ) + Other valid inputs are: + - "fcs": Football Championship Subdivision (FCS), + formerly known as D1-AA (read as "division one double A"). + An FCS school is still in the 1st division of the NCAA, + making them eligible for the March Madness tournament, + but may not have the resources to compete at the FBS level + at this time. FCS schools are limited to 63 athletic scholarships + for football. + - "ii": NCAA Division II. Schools in this and D3 are not + eligible for the March Madness tournament, + and are limited to 36 athletic scholarships + for their football team. + - "iii": NCAA Division III. The largest single division within the + NCAA football pyramid. + D3 schools have the distinction of being part of + the only NCAA division that cannot give out scholarships solely + for athletic ability. + `conference` (str, optional): + Optional argument. + If you only want live scoreboard data from games + involving teams a specific conference, + set `conference` to the abbreviation + of the conference you want live scoreboard data from. + + `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.games import get_cfbd_live_scoreboard + + + cfbd_key = "tigersAreAwesome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwesome": + print( + "Using the user's API key declared " + + "in this script for this example." + ) + + # Get live scoreboard data from the CFBD API. + print( + "Get live scoreboard data from the CFBD API." + ) + json_data = get_cfbd_live_scoreboard( + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get live scoreboard data from the CFBD API, + # but only from the FCS ranks. + print( + "Get live scoreboard data from the CFBD API, " + + "but only from the FCS ranks." + ) + json_data = get_cfbd_live_scoreboard( + ncaa_division="fcs", + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get live scoreboard data from the CFBD API, + # but only from the Atlantic Coast Conference. + print( + "Get live scoreboard data from the CFBD API, " + + "but only from the Atlantic Coast Conference." + ) + json_data = get_cfbd_live_scoreboard( + conference="ACC", + 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_live_scoreboard( + 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 supposedly loaded " + + "into this python environment for this example." + ) + + # Get live scoreboard data from the CFBD API. + print( + "Get live scoreboard data from the CFBD API." + ) + json_data = get_cfbd_live_scoreboard() + print(json_data) + time.sleep(5) + + # Get live scoreboard data from the CFBD API, + # but only from the FCS ranks. + print( + "Get live scoreboard data from the CFBD API, " + + "but only from the FCS ranks." + ) + json_data = get_cfbd_live_scoreboard( + ncaa_division="fcs", + ) + print(json_data) + time.sleep(5) + + # Get live scoreboard data from the CFBD API, + # but only from the Atlantic Coast Conference. + print( + "Get live scoreboard data from the CFBD API, " + + "but only from the Atlantic Coast Conference." + ) + json_data = get_cfbd_live_scoreboard( + conference="ACC", + ) + 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_live_scoreboard( + return_as_dict=True + ) + print(json_data) + + ``` + + Returns + ---------- + A pandas `DataFrame` object with live scoreboard data, + or (if `return_as_dict` is set to `True`) + a dictionary object with live scoreboard data. -def get_cfbd_weather_info( - api_key: str = None, - api_key_dir: str = None, - ncaa_division: str = "fbs", - game_id: int = None, - # `game_id` and/or `year` must be not null for this function to work. - season: int = None, - week: int = None, - season_type: str = "regular", # "regular", "postseason", or "both" - conference: str = None, -): - """ - YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK! - To view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata """ + # real_api_key = "" + scoreboard_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/scoreboard" - raise NotImplementedError( - "This function has yet to be implemented by this version." - ) + if api_key is not 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 == "tigersAreAwesome": + 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 ( + ncaa_division.lower() == "fbs" + or ncaa_division.lower() == "fcs" + or ncaa_division.lower() == "ii" + or ncaa_division.lower() == "iii" + ): + pass + else: + raise ValueError( + "An invalid NCAA Division was inputted when calling this function." + + '\nValid inputs are:\n-"fbs"\n-"fcs"\n-"ii"\n-"iii"' + + f"\n\nYou entered:\n{ncaa_division}" + ) + + url += f"?classification={ncaa_division}" + + if conference is not None and len(conference) > 0: + url += f"&conference={conference}" + + 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( + "Could not connect. The connection was refused.\n" + + "HTTP Status Code 401." + ) + else: + raise ConnectionError( + f"Could not connect.\nHTTP Status code {response.status_code}" + ) + + json_data = response.json() + + if return_as_dict is True: + return json_data + + scoreboard_df = pd.json_normalize(json_data) + + if len(scoreboard_df) > 0: + scoreboard_df.rename( + columns={ + "id": "game_id", + "startDate": "start_datetime", + "startTimeTBD": "is_start_time_tbd", + "tv": "tv_network", + "neutralSite": "is_neutral_site_game", + "conferenceGame": "is_conference_game", + "venue.name": "stadium_name", + "venue.city": "stadium_city", + "venue.state": "stadium_state", + "homeTeam.id": "home_team_id", + "homeTeam.name": "home_team_name", + "homeTeam.conference": "home_team_conference", + "awayTeam.id": "away_team_id", + "awayTeam.name": "away_team_name", + "awayTeam.conference": "away_team_conference", + "weather.temperature": "weather_temperature", + "weather.description": "weather_description", + "weather.windSpeed": "weather_wind_speed", + "weather.windDirection": "weather_wind_direction", + "betting.spread": "betting_spread", + "betting.overUnder": "betting_over_under", + "betting.homeMoneyline": "betting_home_moneyline", + "betting.awayMoneyline": "betting_away_moneyline", + }, + inplace=True, + ) + + return scoreboard_df + + +def get_cfbd_weather_info( + game_id: int = None, + season: int = None, + # `game_id` and/or `season` must be not null for this function to work. + week: int = None, + season_type: str = "both", # "regular", "postseason", or "both" + conference: str = None, + team_name: str = None, + ncaa_division: str = "fbs", + api_key: str = None, + api_key_dir: str = None, + return_as_dict: bool = False, +): + """ + YOU MUST BE SUBSCRIBED TO THE CFBD PATREON FOR THIS FUNCTION TO WORK! + To view the CFBD Patreon, visit https://www.patreon.com/collegefootballdata + + Parameters + ---------- + Retrieves live scoreboard data from the CFBD API, + assuming the API key is an API key from a Patreon supporter. + + Parameters + ---------- + + `game_id` (int, mandatory): + Mandatory requirement. + Specifies the game you want weather data from. + This or `season` must be set to a valid non-null value. + + `season` (int, mandatory): + Mandatory requirement. + Specifies the season you want weather data from. + This or `season` must be set to a valid non-null value. + + `week` (int, optional): + Optional argument. + If `week` is set to an integer, this function will attempt + to load weather data from games in that season, and in that week. + + `season_type` (str, semi-optional): + Semi-optional argument. + By default, this will be set to "both", for the CFB regular season. + If you want postseason betting data, set `season_type` to "postseason". + If `season_type` is set to anything but "regular" or "postseason", + a `ValueError()` will be raised. + + `conference` (str, optional): + Optional argument. + If you only want weather data from games + involving teams a specific conference, + set `conference` to the abbreviation + of the conference you want weather data from. + + `team_name` (str, optional): + Optional argument. + If you only want weather data for a team, + regardless if they are the home/away team, + set `team` to the name of the team + you want weather data from. + + `ncaa_division` (str, semi-optional): + Semi-optional argument. + By default, `ncaa_division` will be set to "fbs", + short for the Football Bowl Subdivision (FBS), + formerly known as D1-A (read as "division one single A"), + the highest level in the NCAA football pyramid, + where teams can scholarship up to 85 players + on their football team solely for athletic ability, + and often have the largest athletics budgets + within the NCAA. + + Other valid inputs are: + - "fcs": Football Championship Subdivision (FCS), + formerly known as D1-AA (read as "division one double A"). + An FCS school is still in the 1st division of the NCAA, + making them eligible for the March Madness tournament, + but may not have the resources to compete at the FBS level + at this time. FCS schools are limited to 63 athletic scholarships + for football. + - "ii": NCAA Division II. Schools in this and D3 are not + eligible for the March Madness tournament, + and are limited to 36 athletic scholarships + for their football team. + - "iii": NCAA Division III. The largest single division within the + NCAA football pyramid. + D3 schools have the distinction of being part of + the only NCAA division that cannot give out scholarships solely + for athletic ability. + + `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.games import get_cfbd_weather_info + + + cfbd_key = "tigersAreAwesome" # placeholder for your CFBD API Key. + + if cfbd_key != "tigersAreAwesome": + print( + "Using the user's API key declared " + + "in this script for this example." + ) + + # Get weather data for the 2024 CFB season + print( + "Get weather data for the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for the 2024 Rose Bowl (game ID #401551786). + print( + "Get weather data for the 2024 Rose Bowl (game ID #401551786)." + ) + json_data = get_cfbd_weather_info( + game_id=401551786, + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for week 1 of the 2024 CFB season + print( + "Get weather data for week 1 of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + week=1, + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for postseason games of the 2023 CFB season. + print( + "Get weather data for postseason games of the 2023 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2023, + season_type="postseason", + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for postseason games of the 2023 CFB season. + print( + "Get weather data for postseason games of the 2023 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2023, + season_type="postseason", + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for Big 10 (B1G) games of the 2024 CFB season. + print( + "Get weather data for Big 10 (B1G) games of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + conference="B1G", + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for FCS games of the 2024 CFB season. + print( + "Get weather data for FCS games of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + ncaa_division="fcs", + api_key=cfbd_key + ) + print(json_data) + time.sleep(5) + + # Get weather data for University of Cincinnati games + # of the 2024 CFB season. + print( + "Get weather data for Big 10 (B1G) games of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + team_name="Cincinnati", + 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_weather_info( + api_key=cfbd_key, + season=2023, + 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 supposedly loaded " + + "into this python environment for this example." + ) + + # Get weather data for the 2024 CFB season + print( + "Get weather data for the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024 + ) + print(json_data) + time.sleep(5) + + # Get weather data for the 2024 Rose Bowl (game ID #401551786). + print( + "Get weather data for the 2024 Rose Bowl (game ID #401551786)." + ) + json_data = get_cfbd_weather_info( + game_id=401551786 + ) + print(json_data) + time.sleep(5) + + # Get weather data for week 1 of the 2024 CFB season + print( + "Get weather data for week 1 of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + week=1 + ) + print(json_data) + time.sleep(5) + + # Get weather data for postseason games of the 2023 CFB season. + print( + "Get weather data for postseason games of the 2023 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2023, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # Get weather data for postseason games of the 2023 CFB season. + print( + "Get weather data for postseason games of the 2023 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2023, + season_type="postseason" + ) + print(json_data) + time.sleep(5) + + # Get weather data for Big 10 (B1G) games of the 2024 CFB season. + print( + "Get weather data for Big 10 (B1G) games of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + conference="B1G" + ) + print(json_data) + time.sleep(5) + + # Get weather data for FCS games of the 2024 CFB season. + print( + "Get weather data for FCS games of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + ncaa_division="fcs" + ) + print(json_data) + time.sleep(5) + + # Get weather data for University of Cincinnati games + # of the 2024 CFB season. + print( + "Get weather data for Big 10 (B1G) games of the 2024 CFB season." + ) + json_data = get_cfbd_weather_info( + season=2024, + team_name="Cincinnati" + ) + 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_weather_info( + season=2023, + return_as_dict=True + ) + print(json_data) + + ``` + Returns + ---------- + A pandas `DataFrame` object with live weather data, + or (if `return_as_dict` is set to `True`) + a dictionary object with live weather data. + + """ + + weather_df = pd.DataFrame() + url = "https://api.collegefootballdata.com/games/weather" + + if api_key is not 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 == "tigersAreAwesome": + 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 (game_id is None) and (season is None): + raise ValueError( + "`game_id` and/or `season` must be set to valid, non-null values." + ) + elif (game_id is not None) and (season is not None): + url += f"?gameId={game_id}&year={season}" + elif game_id is not None: + url += f"?gameId={game_id}" + elif season is not None: + url += f"?year={season}" + + if (ncaa_division is not None) and ( + ncaa_division.lower() == "fbs" + or ncaa_division.lower() == "fcs" + or ncaa_division.lower() == "ii" + or ncaa_division.lower() == "iii" + ): + ncaa_division = ncaa_division.lower() + url += f"&classification={ncaa_division}" + else: + raise ValueError( + "An invalid NCAA Division was inputted when calling this function." + + '\nValid inputs are:\n-"fbs"\n-"fcs"\n-"ii"\n-"iii"' + + f"\n\nYou entered:\n{ncaa_division}" + ) + + if week is not None: + url += f"&week={week}" + + if ( + season_type == "regular" or + season_type == "postseason" or + season_type == "both" + ): + url += f"&seasonType={season_type}" + elif season_type is not None: + raise ValueError( + '`season_type` must be set to either "regular", ' + + '"postseason", or "both" if you want to specify ' + + "a part of the season." + ) + + if team_name is not None: + url += f"&team={team_name}" + + if conference is not None: + url += f"&conference={conference}" + + 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( + "Could not connect. The connection was refused.\n" + + "HTTP Status Code 401." + ) + else: + raise ConnectionError( + f"Could not connect.\nHTTP Status code {response.status_code}" + ) + + json_data = response.json() + + if return_as_dict is True: + return json_data + + weather_df = pd.json_normalize(json_data) + # print(weather_df.columns) + + [ + "weatherConditionCode", + "weatherCondition", + ] + if len(weather_df) > 0: + weather_df.rename( + columns={ + "id": "game_id", + "startTime": "start_datetime", + "seasonType": "season_type", + "gameIndoors": "is_game_indoors", + "homeTeam": "home_team_name", + "homeConference": "home_team_conference", + "awayTeam": "away_team_name", + "awayConference": "away_team_conference", + "venueId": "venue_id", + "venue": "venue_name", + "windDirection": "wind_direction", + "windSpeed": "wind_speed", + "weatherConditionCode": "weather_condition_code", + "weatherCondition": "weather_condition", + }, + inplace=True, + ) + + return weather_df diff --git a/cfbd_json_py/metrics.py b/cfbd_json_py/metrics.py index f13ace9..97866d2 100644 --- a/cfbd_json_py/metrics.py +++ b/cfbd_json_py/metrics.py @@ -1,12 +1,10 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: metrics.py # Purpose: Houses functions pertaining to various CFB - stats within the CFBD API. +# stats within the CFBD API. ############################################################################### -""" import logging from datetime import datetime diff --git a/cfbd_json_py/players.py b/cfbd_json_py/players.py index 6b5483f..ac33a0a 100644 --- a/cfbd_json_py/players.py +++ b/cfbd_json_py/players.py @@ -1,11 +1,9 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: players.py # Purpose: Houses functions pertaining to CFB player data within the CFBD API. ############################################################################### -""" import logging from datetime import datetime diff --git a/cfbd_json_py/plays.py b/cfbd_json_py/plays.py index 6aeb941..f5c8658 100644 --- a/cfbd_json_py/plays.py +++ b/cfbd_json_py/plays.py @@ -1,13 +1,12 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: plays.py # Purpose: Houses functions pertaining to CFB play data within the CFBD API. ############################################################################### -""" -from datetime import datetime + import logging +from datetime import datetime import pandas as pd import requests @@ -1332,9 +1331,46 @@ def get_cfbd_live_pbp_data( game_id: int, api_key: str = None, api_key_dir: str = None, - return_as_dict: bool = False, + # return_as_dict: bool = False, ): """ """ - raise NotImplementedError( - "This function has yet to be implemented by this version." - ) + url = f"https://api.collegefootballdata.com/live/plays?id={game_id}" + + if api_key is not 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 == "tigersAreAwesome": + 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 + + 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( + "Could not connect. The connection was refused.\n" + + "HTTP Status Code 401." + ) + else: + raise ConnectionError( + f"Could not connect.\nHTTP Status code {response.status_code}" + ) + + json_data = response.json() + return json_data diff --git a/cfbd_json_py/rankings.py b/cfbd_json_py/rankings.py index d5459fc..f063805 100644 --- a/cfbd_json_py/rankings.py +++ b/cfbd_json_py/rankings.py @@ -1,16 +1,16 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: rankings.py # Purpose: Houses functions pertaining to CFB poll data within the CFBD API. ############################################################################### -""" + from datetime import datetime import pandas as pd import requests from tqdm import tqdm + from cfbd_json_py.utls import get_cfbd_api_token diff --git a/cfbd_json_py/ratings.py b/cfbd_json_py/ratings.py index 89cd56c..7c5e1a5 100644 --- a/cfbd_json_py/ratings.py +++ b/cfbd_json_py/ratings.py @@ -1,12 +1,10 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: ratings.py # Purpose: Houses functions pertaining to CFB team rating data - within the CFBD API. +# within the CFBD API. ############################################################################### -""" import warnings from datetime import datetime diff --git a/cfbd_json_py/recruiting.py b/cfbd_json_py/recruiting.py index 2cd4d32..152efc7 100644 --- a/cfbd_json_py/recruiting.py +++ b/cfbd_json_py/recruiting.py @@ -1,12 +1,10 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: recruiting.py # Purpose: Houses functions pertaining to CFB recruiting data - within the CFBD API. +# within the CFBD API. ############################################################################### -""" import logging from datetime import datetime diff --git a/cfbd_json_py/stats.py b/cfbd_json_py/stats.py index 0480053..acc0240 100644 --- a/cfbd_json_py/stats.py +++ b/cfbd_json_py/stats.py @@ -1,12 +1,10 @@ -""" # Creation Date: 08/30/2023 01:13 PM EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: stats.py # Purpose: Houses functions pertaining to CFB team/player - stats data within the CFBD API. +# stats data within the CFBD API. ############################################################################### -""" import logging from datetime import datetime diff --git a/cfbd_json_py/teams.py b/cfbd_json_py/teams.py index 632adba..2ee04e8 100644 --- a/cfbd_json_py/teams.py +++ b/cfbd_json_py/teams.py @@ -1,12 +1,9 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: teams.py # Purpose: Houses functions pertaining to CFB team data within the CFBD API. ############################################################################### -""" - import warnings from datetime import datetime diff --git a/cfbd_json_py/utls.py b/cfbd_json_py/utls.py index 133a019..c5b55f1 100644 --- a/cfbd_json_py/utls.py +++ b/cfbd_json_py/utls.py @@ -1,15 +1,15 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: utls.py # Purpose: Houses utility functions for this python package. ############################################################################### -""" import json +import logging import os import secrets -import logging + +import keyring def reverse_cipher_encrypt(plain_text_str: str): @@ -85,6 +85,57 @@ def get_cfbd_api_token(api_key_dir: str = None): set the key in the environment by creating a repository secret named `CFBD_API_KEY`. + Parameters + ---------- + `api_key_dir` (str, optional): + Optional argument. If `api_key_dir` is set to a non-null string, + `set_cfbd_api_token()` will attempt + to see if the API key is in that directory. + + Returns + ---------- + A CFBD API key that exists within this python environment, + or within this computer. + + """ + try: + key = keyring.get_password("cfbd_json_py", str(os.getlogin())) + if key is None or len(key) == 0: + raise KeyError( + "Could not locate a valid CFBD key." + ) + return key + except Exception: + logging.warning( + "Could not locate a CFBD key on this device normally, " + + "checking if the key exists within the environment. " + + "If you have previously set a key using `set_cfbd_api_token()`, " + + "you have nothing to worry about, because this function will " + + "automatically fix this issue." + ) + key = deprecated_get_cfbd_api_token(api_key_dir) + set_cfbd_api_token(key) + return key + + +def deprecated_get_cfbd_api_token(api_key_dir: str = None): + """ + DEPRECATED! DO NOT USE!! + + 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 Retrieves the CFBD API key, + and returns it as a string. + + If this package is being used in a GitHub Actions action, + set the key in the environment by + creating a repository secret named `CFBD_API_KEY`. + Parameters ---------- `api_key_dir` (str, optional): @@ -141,7 +192,28 @@ def get_cfbd_api_token(api_key_dir: str = None): return return_key -def set_cfbd_api_token(api_key: str, api_key_dir: str = None): +def set_cfbd_api_token(api_key: str): + """ + Sets the CFBD API key for use by this python package. + + Parameters + ---------- + `api_key` (str, mandatory): + The CFBD API key you have. + DO NOT input `Bearer {your CFBD API key}`, + this package will take care of that for you. + + Returns + ---------- + Nothing. + This function only sets up the API + that this package can reference later. + + """ + keyring.set_password("cfbd_json_py", str(os.getlogin()), api_key) + + +def _set_cfbd_api_token(api_key: str, api_key_dir: str = None): """ Sets the CFBD API key into a file that exists either in `{home_dir}/.cfbd/cfbd_key.json`, or in a custom directory. @@ -290,7 +362,7 @@ def set_cfbd_api_token(api_key: str, api_key_dir: str = None): # print(f'remove last 2 characters from string: {text[:-2]}') # key = "hello world" -# set_cfbd_api_token(key) -# return_key = get_cfbd_api_token() +# set_cfbd_api_token("text") # print(key) +# return_key = get_cfbd_api_token() # print(return_key) diff --git a/cfbd_json_py/venues.py b/cfbd_json_py/venues.py index 4e46e5f..21a44c8 100644 --- a/cfbd_json_py/venues.py +++ b/cfbd_json_py/venues.py @@ -1,12 +1,10 @@ -""" # Creation Date: 08/30/2023 01:13 EDT -# Last Updated Date: 04/04/2024 05:10 PM EDT +# Last Updated Date: 08/13/2024 02:10 PM EDT # Author: Joseph Armstrong (armstrongjoseph08@gmail.com) # File Name: venues.py # Purpose: Houses functions pertaining to - CFB team venues/stadium data within the CFBD API. +# CFB team venues/stadium data within the CFBD API. ############################################################################### -""" import pandas as pd import requests diff --git a/docs/cfbd_json_py.html b/docs/cfbd_json_py.html index 8f3489f..26a1ea8 100644 --- a/docs/cfbd_json_py.html +++ b/docs/cfbd_json_py.html @@ -1,190 +1,1616 @@ + - + cfbd_json_py API documentation - - - - - - + + + + + + + +
-
-

-cfbd_json_py

- -

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 conferences.
  • -
  • 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 data points pertaining to -actual CFB games within the CFBD API.
  • -
  • cfbd_json_py.metrics: -Holds functions to allow you to calculate -or retrieve 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 recruiting 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 recommended, extreme security risk).
  2. -
  3. 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.
    • -
  4. -
  5. 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:
    • -
  6. -
- -
from cfbd_api_key.utls import set_cfbd_api_token
+        
+

+ cfbd_json_py

+ +
+

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 conferences.
  • +
  • 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 data points pertaining to + actual CFB games within the CFBD API.
  • +
  • cfbd_json_py.metrics: + Holds functions to allow you to calculate + or retrieve 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 recruiting 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 recommended, extreme security risk).
  2. +
  3. 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.
    • +
    +
  4. +
  5. 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:
    • +
    +
  6. +
+ +
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 separate 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 -to access the current Swagger docs for the entire API.
  • -
  • If you want to see the source code for this package, -click here -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.
  • -
-
- - - - - -
  1# Creation Date: 08/30/2023 01:13 EDT
+                
+

NOTE: In a future version, + there will be an executable application separate 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 + to access the current Swagger docs for the entire API. +
  • +
  • If you want to see the source code for this package, + click here + 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. +
  • +
+
+ + + + + +
+
  1# Creation Date: 08/30/2023 01:13 EDT
   2# Last Updated Date: 04/04/2024 05:10 PM EDT
   3# Author: Joseph Armstrong (armstrongjoseph08@gmail.com)
   4# File Name: __init__.py
@@ -321,191 +1747,194 @@ 

Other Notes

135# Utils 136 137from cfbd_json_py.utls import * # noqa: F403 -
+
+
-
+
- + + if (getSearchTerm()) { + initialize(); + searchBox.value = getSearchTerm(); + onInput(); + } else { + searchBox.addEventListener("focus", initialize, { once: true }); + } + + searchBox.addEventListener("keydown", e => { + if (["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) { + let focused = currentContent.querySelector(".search-result.focused"); + if (!focused) { + currentContent.querySelector(".search-result").classList.add("focused"); + } else if ( + e.key === "ArrowDown" + && focused.nextElementSibling + && focused.nextElementSibling.classList.contains("search-result") + ) { + focused.classList.remove("focused"); + focused.nextElementSibling.classList.add("focused"); + focused.nextElementSibling.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest" + }); + } else if ( + e.key === "ArrowUp" + && focused.previousElementSibling + && focused.previousElementSibling.classList.contains("search-result") + ) { + focused.classList.remove("focused"); + focused.previousElementSibling.classList.add("focused"); + focused.previousElementSibling.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest" + }); + } else if ( + e.key === "Enter" + ) { + focused.querySelector("a").click(); + } + } + }); + + + \ No newline at end of file diff --git a/docs/cfbd_json_py/_early_access.html b/docs/cfbd_json_py/_early_access.html index c835cb0..37e0cfc 100644 --- a/docs/cfbd_json_py/_early_access.html +++ b/docs/cfbd_json_py/_early_access.html @@ -1,82 +1,1508 @@ + - + cfbd_json_py._early_access API documentation - - - - - - + + + + + + + +
-
-

-cfbd_json_py._early_access

+
+

+ cfbd_json_py._early_access +

-

Creation Date: 10/06/2023 07:33 PM EDT

+
+

Creation Date: 10/06/2023 07:33 PM EDT

-

Last Updated Date: 02/24/2023 03:30 PM EST

+

Last Updated Date: 02/24/2023 03:30 PM EST

-

Author: Joseph Armstrong (armstrongjoseph08@gmail.com)

+

Author: Joseph Armstrong + (armstrongjoseph08@gmail.com)

-

File Name: _early_access.py

+

File Name: _early_access.py

-

Purpose: Houses functions that have yet to be implemented yet for

+

Purpose: Houses functions that + have yet to be implemented yet for

-
this version of this python package
+                
this version of this python package
 
-
+
- + - + -
 1"""
+            
+
 1"""
  2# Creation Date: 10/06/2023 07:33 PM EDT
  3# Last Updated Date: 02/24/2023 03:30 PM EST
  4# Author: Joseph Armstrong (armstrongjoseph08@gmail.com)
@@ -95,223 +1521,231 @@ 

Purpos 17 18def about_early_access_functions(): 19 print( -20 "Early Access functions are functions " -21 + "generated by a generator script " +20 "Early Access functions are functions:\n" +21 + "Generated by a generator script " 22 + "when an API endpoint is created, " 23 + "but not implemented yet by this python package." 24 ) 25 26 27# TODO: Create a code generator if a function doesn't exist. -

+
+
+ +
+
+ +
-
-
- -
- - def - about_early_access_functions(): + def + about_early_access_functions(): - + -
- -
19def about_early_access_functions():
+            
+ +
+
19def about_early_access_functions():
 20    print(
-21        "Early Access functions are functions "
-22        + "generated by a generator script "
+21        "Early Access functions are functions:\n"
+22        + "Generated by a generator script "
 23        + "when an API endpoint is created, "
 24        + "but not implemented yet by this python package."
 25    )
-
+ + - -
+ +
- + + if (getSearchTerm()) { + initialize(); + searchBox.value = getSearchTerm(); + onInput(); + } else { + searchBox.addEventListener("focus", initialize, { once: true }); + } + + searchBox.addEventListener("keydown", e => { + if (["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) { + let focused = currentContent.querySelector(".search-result.focused"); + if (!focused) { + currentContent.querySelector(".search-result").classList.add("focused"); + } else if ( + e.key === "ArrowDown" + && focused.nextElementSibling + && focused.nextElementSibling.classList.contains("search-result") + ) { + focused.classList.remove("focused"); + focused.nextElementSibling.classList.add("focused"); + focused.nextElementSibling.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest" + }); + } else if ( + e.key === "ArrowUp" + && focused.previousElementSibling + && focused.previousElementSibling.classList.contains("search-result") + ) { + focused.classList.remove("focused"); + focused.previousElementSibling.classList.add("focused"); + focused.previousElementSibling.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest" + }); + } else if ( + e.key === "Enter" + ) { + focused.querySelector("a").click(); + } + } + }); + + + \ No newline at end of file diff --git a/docs/cfbd_json_py/betting.html b/docs/cfbd_json_py/betting.html index 79a039d..676139b 100644 --- a/docs/cfbd_json_py/betting.html +++ b/docs/cfbd_json_py/betting.html @@ -1,1257 +1,2690 @@ + - + cfbd_json_py.betting API documentation - - - - - - - -