From ea85cd451eb052e80b38a04e25918290094325b4 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Sat, 29 Mar 2025 00:23:35 -0500 Subject: initial commit --- nba/fetch_data.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 nba/fetch_data.py (limited to 'nba/fetch_data.py') diff --git a/nba/fetch_data.py b/nba/fetch_data.py new file mode 100644 index 0000000..bba3a59 --- /dev/null +++ b/nba/fetch_data.py @@ -0,0 +1,28 @@ +""" +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 \ No newline at end of file -- cgit v1.2.3-70-g09d2