diff options
Diffstat (limited to 'build/lib/nba/fetch_data.py')
| -rw-r--r-- | build/lib/nba/fetch_data.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/build/lib/nba/fetch_data.py b/build/lib/nba/fetch_data.py new file mode 100644 index 0000000..49503cc --- /dev/null +++ b/build/lib/nba/fetch_data.py @@ -0,0 +1,30 @@ +""" +Fetches data for use in other modules. +""" + +import json +from nba_api.live.nba.endpoints import scoreboard +from nba_api.stats.endpoints import leaguestandings + + +def fetch_data() -> tuple: + """ + Fetches live NBA scoreboard data and standings from the NBA API. + + Returns: + games (dict): JSON parsed games data. + standings (dict): JSON parsed team standings data. + """ + # Get today's scoreboard data + games_endpoint = scoreboard.ScoreBoard() + games_json = games_endpoint.get_json() + + # Get league standings + standings_endpoint = leaguestandings.LeagueStandings() + standings_json = standings_endpoint.get_json() + + # Parse the JSON strings into Python dictionaries + games = json.loads(games_json) + standings = json.loads(standings_json) + + return games, standings |
