def test_get_functions(self): """Tests various get functions to assure they don't return nothing/empty stringss""" self.assertIsNotNone(get_color()) self.assertIsNotNone(get_full_name()) self.assertIsNotNone(get_team()) self.assertIsNotNone(get_season_year())
def get_team_data(season=None): """Gets raw json data for all teams. Args: season: Year of season start date. Ex: 2019 for the 2019/2020 season. Returns: Dict of raw json data from data.nba.net.../teams.json endpoint """ if not season: season = get_season_year() url = 'http://data.nba.net/prod/v2/' + str(season) + '/teams.json' data = get_data(url) return data
def __init__(self, season=None, team=None): self.season = season if season != None \ else get_season_year() self.team = team if team != None else get_team() self.raw_data = get_schedule_data(season=self.season, team=self.team) self._internal = self.raw_data['_internal'] self.league = self.raw_data['league'] self.standard = self.league['standard'] #list of all games self.last_game_idx = self.league['lastStandardGamePlayedIndex'] self.last_game = self.standard[self.last_game_idx] self.last_game_id = self.last_game['gameId'] self.last_game_date = self.last_game['gameUrlCode'][0:8] self.last_game_id_date = (self.last_game_id, self.last_game_date)
def get_schedule_data(season=None, team=None): """Gets raw json data of given team schedule for given season. Args: season: year of season start date, YYYY format. team: teamUrl for given team -> team name, ex: raptors, sixers Returns: Dict of raw json data from data.nba.net.../schedule.json endpoint """ if not team: season = get_season_year() if not team: team = get_team() team = handle_team_url_name(team) url_start = 'http://data.nba.net/prod/v1/' url = url_start + str(season) + '/teams/' + str(team) + '/schedule.json' data = get_data(url) return data
def get_team_leaders_data(team=None, season=None): """Gets raw json data for stat leaders for given team. Args: team: lowercase team name of team. ex: raptors, sixers, bulls season: Year of season start date. Ex: 2019 for the 2019/2020 season. Returns: Dict of raw json data from data.nba.net /leaders.json endpoint """ if not team: team = get_team() team = handle_team_url_name(team) if not season: season = get_season_year() url1 = 'http://data.nba.net/prod/v1/' url_end = '/leaders.json' url = str(url1) + str(season) + '/teams/' + str( team.lower()) + str(url_end) data = get_data(url) return data