def test_get_json_response_bad_response(): url = 'https://stats.nba.com/stats/scoreboardV2' responses.add(responses.GET, url, status=400) params = {} with pytest.raises(requests.exceptions.HTTPError): utils.get_json_response(url, params)
def get_hustle_response_json_for_stat_measure(season, season_type, **kwargs): """ season - string, ex '2019-20' season_type - string, 'Regular Season' or 'Playoffs' possible kwargs: date_from - string, optional, format - MM/DD/YYYY date_to - string, optional, format - MM/DD/YYYY returns dict """ url = 'https://stats.nba.com/stats/leaguehustlestatsplayer' parameters = { 'Season': season, 'SeasonType': season_type, 'DateFrom': kwargs.get('date_from', ''), 'DateTo': kwargs.get('date_to', ''), 'GameScope': '', 'LastNGames': 0, 'LeagueID': '00', 'Location': '', 'Month': 0, 'OpponentTeamID': 0, 'Outcome': '', 'PerMode': 'Totals', 'PlayerExperience': '', 'PlayerPosition': '', 'SeasonSegment': '', 'StarterBench': '', 'VsConference': '', 'VsDivision': '', } return utils.get_json_response(url, parameters)
def get_boxscore_response_json_for_stat_measure(measure_type, season, season_type, **kwargs): """ season - string, ex '2019-20' season_type - string, 'Regular Season' or 'Playoffs' possible kwargs: date_from - string, optional, format - MM/DD/YYYY date_to - string, optional, format - MM/DD/YYYY returns dict """ url = 'https://stats.nba.com/stats/leaguedashplayerstats' parameters = { 'College': '', 'Conference': '', 'Country': '', 'DateFrom': kwargs.get('date_from', ''), 'DateTo': kwargs.get('date_to', ''), 'Division': '', 'DraftPick': '', 'DraftYear': '', 'GameScope': '', 'GameSegment': '', 'Height': '', 'LastNGames': 0, 'LeagueID': '00', 'Location': '', 'MeasureType': measure_type, 'Month': 0, 'OpponentTeamID': 0, 'Outcome': '', 'PORound': 0, 'PaceAdjust': 'N', 'PerMode': 'Totals', 'Period': 0, 'PlayerExperience': '', 'PlayerPosition': '', 'PlusMinus': 'N', 'Rank': 'N', 'Season': season, 'SeasonSegment': '', 'SeasonType': season_type, 'ShotClockRange': '', 'StarterBench': '', 'TeamID': 0, 'TwoWay': 0, 'VsConference': '', 'VsDivision': '', 'Weight': '', } return utils.get_json_response(url, parameters)
def get_tracking_shots_response(entity_type, season, season_type, **kwargs): """ entity_type - string, player, team, opponent season - string, ex 2019-20 season_type - string, Regular Season or Playoffs possible kwargs: date_from - string, optional, format - MM/DD/YYYY date_to - string, optional, format - MM/DD/YYYY close_def_dist - string, options are: '', '0-2 Feet - Very Tight','2-4 Feet - Tight','4-6 Feet - Open','6+ Feet - Wide Open' shot_clock - string, options are: '', '24-22', '22-18 Very Early', '18-15 Early', '15-7 Average', '7-4 Late', '4-0 Very Late', 'ShotClock Off' shot_dist - string, options are: '', '>=10.0' touch_time - string, options are: '', 'Touch < 2 Seconds', 'Touch 2-6 Seconds', 'Touch 6+ Seconds' dribbles - string, options are: '', '0 Dribbles', '1 Dribble', '2 Dribbles', '3-6 Dribbles', '7+ Dribbles' general_range - string, options are: 'Overall', 'Catch and Shoot', 'Pullups', 'Less Than 10 ft' period - int location - string, options are: 'Home' and 'Road' returns dict """ if entity_type == 'team': url = 'https://stats.nba.com/stats/leaguedashteamptshot' elif entity_type == 'player': url = 'https://stats.nba.com/stats/leaguedashplayerptshot' elif entity_type == 'opponent': url = 'https://stats.nba.com/stats/leaguedashoppptshot' else: return None parameters = { 'Season': season, 'SeasonType': season_type, 'DateFrom': kwargs.get('date_from', ''), 'DateTo': kwargs.get('date_to', ''), 'CloseDefDistRange': kwargs.get('close_def_dist', ''), 'ShotClockRange': kwargs.get('shot_clock', ''), 'ShotDistRange': kwargs.get('shot_dist', ''), 'TouchTimeRange': kwargs.get('touch_time', ''), 'DribbleRange': kwargs.get('dribbles', ''), 'GeneralRange': kwargs.get('general_range', 'Overall'), 'PerMode': 'Totals', 'LeagueID': '00', 'Period': kwargs.get('period', ''), 'Location': kwargs.get('location', ''), } return utils.get_json_response(url, parameters)
def get_tracking_response_json_for_stat_measure(stat_measure, season, season_type, entity_type, **kwargs): """ stat_measure - string, options: 'Drives', 'Defense', 'CatchShoot', 'Passing', 'Possessions', 'PullUpShot', 'Rebounding', 'Efficiency', 'SpeedDistance', 'ElbowTouch', 'PostTouch', 'PaintTouch' season - string, ex '2019-20' season_type - string, 'Regular Season' or 'Playoffs' entity_type - string, 'player' or 'team' possible kwargs: date_from - string, optional, format - MM/DD/YYYY date_to - string, optional, format - MM/DD/YYYY opponent_team_id - int, optional, default is 0, which gets all teams returns dict """ url = 'https://stats.nba.com/stats/leaguedashptstats' parameters = { 'PlayerOrTeam': entity_type.title(), 'PtMeasureType': stat_measure, 'Season': season, 'SeasonType': season_type, 'DateFrom': kwargs.get('date_from', ''), 'DateTo': kwargs.get('date_to', ''), 'GameScope': '', 'LastNGames': 0, 'LeagueID': '00', 'Location': '', 'Month': 0, 'OpponentTeamID': kwargs.get('opponent_team_id', 0), 'Outcome': '', 'PerMode': 'Totals', 'PlayerExperience': '', 'PlayerPosition': '', 'SeasonSegment': '', 'StarterBench': '', 'VsConference': '', 'VsDivision': '', } return utils.get_json_response(url, parameters)