aboutsummaryrefslogtreecommitdiff
path: root/nba/fetch_data.py
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cmc.pub>2025-03-29 00:23:35 -0500
committerChristian Cleberg <hello@cmc.pub>2025-03-29 00:23:35 -0500
commitea85cd451eb052e80b38a04e25918290094325b4 (patch)
tree443fccfc7fe2a23443ac993e84436a757b3efc77 /nba/fetch_data.py
downloadnba-scores-ea85cd451eb052e80b38a04e25918290094325b4.tar.gz
nba-scores-ea85cd451eb052e80b38a04e25918290094325b4.tar.bz2
nba-scores-ea85cd451eb052e80b38a04e25918290094325b4.zip
initial commit
Diffstat (limited to 'nba/fetch_data.py')
-rw-r--r--nba/fetch_data.py28
1 files changed, 28 insertions, 0 deletions
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