def getTeamIdsByName(team_name: str, fuzzy_match: bool = False) -> Optional[Dict[int, str]]: """ Takes a string name and returns a list of all the teams and ids that match that string :param team_name: :return: """ stripped_name = team_name.strip() if stripped_name == "": return None all_matches = teams.find_teams_by_full_name(stripped_name) ret_dict = {} if all_matches is None or len(all_matches) < 1: if fuzzy_match: return fuzzyids.getFuzzyTeamIdsByName(stripped_name) else: return None else: for match in all_matches: ret_dict[match.get('id')] = match.get('full_name') if fuzzy_match and len(ret_dict) > 1: return fuzzyids.getFuzzyTeamIdsByName(stripped_name) else: return ret_dict
def roster(team, season): team = teams.find_teams_by_full_name(team) team = team[0] team = commonteamroster.CommonTeamRoster(team_id=team.get("id"), season=season) team = (team.get_data_frames())[0] return team['PLAYER']
def pts_of_matchup(team1, team2): team_id = teams.find_teams_by_full_name(team1)[0]["id"] team_games = teamgamelog.TeamGameLog( team_id=team_id).get_normalized_dict()["TeamGameLog"] opponent_abb = teams.find_teams_by_full_name(team2)[0]["abbreviation"] games_by_opponent = [ game for game in team_games if game["MATCHUP"].split(" ")[2] == opponent_abb and datetime.datetime.strptime(game["GAME_DATE"], "%b %d, %Y") <= date_time ] wins_by_opponent = [ game for game in games_by_opponent if game["WL"] == "W" ] if games_by_opponent == []: return 0 return (len(wins_by_opponent) / len(games_by_opponent)) * 10
def getTeamInfo(team): from nba_api.stats.endpoints import teaminfocommon from nba_api.stats.static import teams team = team.replace('-', ' ').replace('LA', '').strip() with timeout: try: teamInfo = teams.find_teams_by_full_name(team)[0] except: teamInfo = 'timeout' return teamInfo
def pullgameids( team, season): ##takes two strings for team and season returns all game ids team = teams.find_teams_by_full_name(team) team = team[0] gamefinder = leaguegamefinder.LeagueGameFinder( team_id_nullable=team.get("id")) games = (gamefinder.get_data_frames())[0] seasongame = games[games.SEASON_ID.str[-4:] == season] return seasongame['GAME_ID']
fav_short_team) headers = { 'x-rapidapi-host': "api-nba-v1.p.rapidapi.com", 'x-rapidapi-key': "acca717e1fmshd937604fdb1e291p148866jsn0e6ec8ccd90e" } # API Call response = requests.request("GET", url, headers=headers) # API Response as JSON team_json = response.json() # Find Stats team_name = team_json['api']['teams'][0]['fullName'] nba_teams = teams.find_teams_by_full_name(team_name) team_id = nba_teams[0]['id'] game_finder = leaguegamefinder.LeagueGameFinder(team_id_nullable=team_id) games = game_finder.get_data_frames()[0] # Narrow down list of stats and to latest season games_1819 = games[games.SEASON_ID.str[-4:] == '2018'] cols = [ 'TEAM_NAME', 'GAME_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'PTS', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PLUS_MINUS' ] games_1819 = games_1819[cols] team_stats = games_1819.mean() team_name = games_1819['TEAM_NAME'].to_list()[0]
def team_full_name_to_id(team_full_name): if isinstance(team_full_name, str): return teams.find_teams_by_full_name(team_full_name)[0]['id']
get_columns_for_measure_type('Usage') """================================================================================================================== # Create UDF that returns team ID ==================================================================================================================""" import nba_api.stats.static.teams as teams teams.get_teams() team_full_name_map = {} for dict in teams.get_teams(): team_full_name_map[dict['full_name']] = dict['id'] team_full_name_map['Atlanta Hawks'] team = 'Boston Celtics' if isinstance(team, str): print(teams.find_teams_by_full_name(team)[0]['id']) def team_full_name_to_id(team_full_name): if isinstance(team_full_name, str): return teams.find_teams_by_full_name(team_full_name)[0]['id'] """================================================================================================================== # Determine list utlization by endpoint ==================================================================================================================""" team_list = ['Philadelphia 76ers', 'Toronto Raptors'] team_id_list = [team_full_name_to_id(tm) for tm in team_list] team_id_list
def teamID(teamName): # find team ID by team name teamDict = teams.find_teams_by_full_name(teamName) if len(teamDict) == 0: teamDict = teams.find_teams_by_nickname(teamName) return teamDict[0]['id']
#player_headers = player_info.overall_player_dashboard.get_dict().get('headers') #player_data = player_info.overall_player_dashboard.get_dict().get('data')[0] ##last 20 games## player_headers = player_info.last20_player_dashboard.get_dict().get('headers') player_data = player_info.last20_player_dashboard.get_dict().get('data')[0] print(player_headers[5], player_data[5], player_headers[2], player_data[2], player_headers[26], player_data[26], player_headers[27], player_data[27]) #Team Input team1_input = input('Enter team 1: ') print(team1_input) team1 = teams.find_teams_by_full_name(team1_input)[0]['id'] teamdashboard = teamdashboardbylastngames.TeamDashboardByLastNGames( team_id=team1) #team_headers = teamdashboard.overall_team_dashboard.get_dict().get('headers') #team_data = teamdashboard.overall_team_dashboard.get_dict().get('data')[0] ##last 20 games## team_headers = teamdashboard.last20_team_dashboard.get_dict().get('headers') team_data = teamdashboard.last20_team_dashboard.get_dict().get('data')[0] print(team1, 'Season:', team_data[-1]) print(team_headers[2], team_data[2], team_headers[3], team_data[3], team_headers[4], team_data[4], team_headers[9], team_data[9]) #PER Data
def getTeamId(self, full_name="Golden State Warriors"): try: team_details = teams.find_teams_by_full_name(full_name) return (team_details[0]['id']) except: raise Exception("No team with the given name")
driver = login() print('Login successful') session_id = driver.session_id for i in mydivs: down_new_video(i['href']) j = i['title'].split('–')[1] new_date2 = get_date(j) file1 = open("all_team_and_date.txt", "w") file1.writelines(i['title']) file1.close() name = i['title'].split('–')[0] a = i['title'].split('–')[0].split('vs') first = a[0].lstrip() first = first.strip() second = a[1].strip() second = second.lstrip() if second == 'LA Clippers': second = teams.find_teams_by_full_name( 'Los Angeles Clippers')[0]['abbreviation'] elif first == 'LA Clippers': first = teams.find_teams_by_full_name( 'Los Angeles Clippers')[0]['abbreviation'] else: frst = teams.find_teams_by_full_name(first)[0]['abbreviation'] sec = teams.find_teams_by_full_name(second)[0]['abbreviation'] url_for_high = 'https://watch.nba.com/game/{}/{}'.format( new_date2, frst + sec) hight_light(url_for_high) logging.basicConfig(filename="sample.log", level=logging.INFO)
'total_incorrect_ratio': 0, 'max_correct_ratio': 0, 'min_correct_ratio': 1, 'max_incorrect_ratio': 0, 'min_incorrect_ratio': 1} for row in reader: #First check if field has an ID instead of a name team_id = None try: team_id = int(row[CORRECT_INDEX]) except ValueError: pass # If it's not an ID, get the team by their name if team_id is None: teams_dict = teams.find_teams_by_full_name(row[CORRECT_INDEX]) else: teams_dict = [teams.find_team_name_by_id(team_id)] # Don't run the test if we don't know what the solution should be if not len(teams_dict) == 1: print(f"Couldn't find team matching {row[CORRECT_INDEX]}") else: print(f"\"{row[MISSPELLED_INDEX]}\" ", end='') # Figure out which mode the fuzzy code is going to run in team_names = row[MISSPELLED_INDEX].split() if len(team_names) == 1: stats_dict = one_stats_dict print('(First or last name mode)') else: