Exemple #1
0
def parse_all_teams():
    all_teams_raw = json.loads(
        commonteamyears.CommonTeamYears(APIProperty('LeagueID')).get_json())
    headers, row_set = get_result_set(all_teams_raw)

    # retrieving each team id
    teams_id = get_ids(headers, 'TEAM_ID', row_set)
    teams = []
    for team_id in teams_id:
        teams = parse_team(team_id, teams)

    # return json.dumps(teams)
    return teams
Exemple #2
0
import mysql.connector
from nba_api.stats.endpoints import commonteamyears
from nba_api.stats.endpoints import commonteamroster
import time
import database


num_to_team = {1610612737:"Atlanta_Hawks",1610612738:"Boston_Celtics", 1610612739:"Cleveland_Cavaliers", 1610612740:"New_Orleans_Pelicans", 1610612741:"Chicago_Bulls", 1610612742: "Dallas_Mavericks",1610612743:"Denver_Nuggets", 1610612744:"Golden_State_Warriors",1610612745:"Houston_Rockets", 1610612746:"Los_Angeles_Clippers", 1610612747: "Los_Angeles_Lakers", 1610612748: "Miami_Heat",1610612750:"Minnesota_Timberwolves", 1610612751:"Brooklyn_Nets", 1610612752:"New_York_Knicks", 1610612753:"Orlando_Magic", 1610612754: "Indiana_Pacers", 1610612755: "Philadelphia_76ers", 1610612756:"Phoenix_Suns", 1610612757:"Portland_Trail_Blazers", 1610612758:"Sacramento_Kings",1610612759:"San_Antonio_Spurs", 1610612760:"Oklahoma_City_Thunder", 1610612749:"Milwaukee_Bucks", 1610612762:"Utah_Jazz", 1610612763:"Menphis_Grizzlies",1610612764:"Washington_Wizards", 1610612765:"Detroit_Pistons", 1610612766:"Charlotte_Hornets", 1610612761:"Toronto_Raptors"}
#get teams
teams_dict = commonteamyears.CommonTeamYears()
teams_dict = teams_dict.team_years.get_dict()

teams = []
for teamNum in range(30):
    teams.append(teams_dict["data"][teamNum])

#get rosters
rosters = []
for team in teams:
    time.sleep(1)
    rosters_dict = commonteamroster.CommonTeamRoster(season="2018-19",team_id=team[1])
    rosters_dict = rosters_dict.common_team_roster.get_dict()
    rosters.append(rosters_dict["data"])

db = mysql.connector.connect(
    host =  database.databaseInfo["host"],
    user = database.databaseInfo["user"],
    passwd = database.databaseInfo["passwd"],
    database = database.databaseInfo["database"]
)
cursor = db.cursor()