krz/nba-scores
A CLI/TUI app for NBA scores.
clone: git clone https://gitbay.org/krz/nba-scores.git
1"""
2Fetches data for use in other modules.
3"""
4
5import json
6
7from nba_api.live.nba.endpoints import scoreboard
8from nba_api.stats.endpoints import leaguestandings
9
10
11def fetch_data() -> tuple:
12 """
13 Fetches live NBA scoreboard data and standings from the NBA API.
14
15 Returns:
16 games (dict): JSON parsed games data.
17 standings (dict): JSON parsed team standings data.
18 """
19 # Get today's scoreboard data
20 games_endpoint = scoreboard.ScoreBoard()
21 games_json = games_endpoint.get_json()
22
23 # Get league standings
24 standings_endpoint = leaguestandings.LeagueStandings()
25 standings_json = standings_endpoint.get_json()
26
27 # Parse the JSON strings into Python dictionaries
28 games = json.loads(games_json)
29 standings = json.loads(standings_json)
30
31 return games, standings