-
Notifications
You must be signed in to change notification settings - Fork 0
/
nba_scores.py
45 lines (32 loc) · 1.21 KB
/
nba_scores.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from requests import get
from pprint import PrettyPrinter
BASE_URL = "https://www.nba.net"
ALL_JSON = "/prod/v1/today.json"
printer = PrettyPrinter
def get_links():
data = get(BASE_URL + ALL_JSON).json()
links = data['links']
return links
def get_scoreboard():
scoreboard = get_links()['currentScoreboard']
games = get(BASE_URL + scoreboard).json()['games']
for game in games:
home_team = game['hTeam']
away_team = game['vTeam']
clock = game['clock']
period = game['period']
print('----------------------------------------------')
print(f'{home_team['triCode']} vs {away_team['triCode']}')
print(f'{home_team['score']} - {away_team['score']}')
print(f'{clock} - {period['current']}')
def get_stats():
stats = get_links()['leagueTeamStatsLeaders']
teams = get(BASE_URL + stats).json()['league']['standard']['regularSeason']['teams']
teams = list(filter(lambda x: x['name'] != 'Team', teams))
teams.sort(key=lambda x: int(x['ppg']['rank']))
for team in teams:
name = team['name']
nickname = team['nickname']
ppg = team['ppg']['avg']
print(f'{i + 1}.{name} - {nickname} - {ppg}')
get_stats()