if roster_data.status_code == 200:
        roster_data = roster_data.json()
        for player in roster_data["roster"]:
            player_data = requests.get(config["api_url"] +
                                       f"/people/{player['person']['id']}")
            if player_data.status_code == 200:
                player_data = player_data.json()["people"][0]
                connection = create_connection()
                try:
                    execute_sql(
                        connection, "INSERT INTO players"
                        f"    VALUES ({player_data['id']}"
                        f"         , '{player_data['firstName']}'"
                        f"         , '{player_data['lastName']}'"
                        f"         , {player_data['primaryNumber']}"
                        f"         , '{player_data['birthDate']}'"
                        f"         , {player_data['currentAge']}"
                        f"         , '{player_data['nationality']}'"
                        f"         , '{player_data['height'][0] + '-' + player_data['height'][2:-1]}'"
                        f"         , {player_data['weight']}"
                        f"         , {player_data['currentTeam']['id']}"
                        f"         , {player_data['alternateCaptain']}"
                        f"         , {player_data['captain']}"
                        f"         , {player_data['rookie']}"
                        f"         , '{player_data['shootsCatches']}'"
                        f"         , '{player_data['primaryPosition']['name']}'"
                        f"         , {player_data['active']})")
                except:
                    close_and_commit_connection(connection)
                    print('log')
import requests
from connect_to_db import create_connection, close_and_commit_connection, execute_sql
from config import get_config

if __name__ == "__main__":
    config = get_config()
    conference_data = requests.get(config["api_url"] + "/conferences")
    if conference_data.status_code == 200:
        conference_data = conference_data.json()
        connection = create_connection()
        for conference in conference_data['conferences']:
            execute_sql(
                connection, "INSERT INTO conferences"
                f"    VALUES ({conference['id']}"
                f"         , '{conference['name']}'"
                f"         , '{conference['abbreviation']}'"
                f"         , {conference['active']})")
        close_and_commit_connection(connection)
import requests
from connect_to_db import create_connection, close_and_commit_connection, execute_sql
from config import get_config

if __name__ == "__main__":
    config = get_config()
    team_data = requests.get(config["api_url"] + "/teams")
    if team_data.status_code == 200:
        team_data = team_data.json()
        connection = create_connection()
        for team in team_data['teams']:
            execute_sql(
                connection, "INSERT INTO teams"
                f"    VALUES ({team['id']}"
                f"         , '{team['name']}'"
                f"         , '{team['abbreviation']}'"
                f"         , '{team['locationName']}'"
                f"         , '{team['firstYearOfPlay']}'"
                f"         , {team['division']['id']}"
                f"         , {team['conference']['id']}"
                f"         , {team['active']})")
        close_and_commit_connection(connection)
Esempio n. 4
0
        if season_data.status_code == 200:
            season_data = season_data.json()['stats'][0]['splits'][0]['stat']
            execute_sql(
                connection, "INSERT INTO season_stats"
                f"    VALUES ({season}"
                f"         , {season_data['gamesPlayed']}"
                f"         , {season_data['wins']}"
                f"         , {season_data['losses']}"
                f"         , {season_data['ot']}"
                f"         , {season_data['pts']}"
                f"         , {season_data['goalsPerGame']}"
                f"         , {season_data['goalsAgainstPerGame']}"
                f"         , {season_data['evGGARatio']}"
                f"         , {season_data['powerPlayPercentage']}"
                f"         , {season_data['powerPlayGoals']}"
                f"         , {season_data['powerPlayGoalsAgainst']}"
                f"         , {season_data['powerPlayOpportunities']}"
                f"         , {season_data['penaltyKillPercentage']}"
                f"         , {season_data['shotsPerGame']}"
                f"         , {season_data['shotsAllowed']}"
                f"         , {season_data['winScoreFirst']}"
                f"         , {season_data['winOppScoreFirst']}"
                f"         , {season_data['winLeadFirstPer']}"
                f"         , {season_data['winLeadSecondPer']}"
                f"         , {season_data['winOutshootOpp']}"
                f"         , {season_data['winOutshotByOpp']}"
                f"         , {season_data['faceOffsTaken']}"
                f"         , {season_data['faceOffsLost']}"
                f"         , {season_data['faceOffsWon']})")
    close_and_commit_connection(connection)
Esempio n. 5
0
import requests
from connect_to_db import create_connection, close_and_commit_connection, execute_sql
from config import get_config

if __name__ == "__main__":
    config = get_config()
    division_data = requests.get(config["api_url"] + "/divisions")
    if division_data.status_code == 200:
        division_data = division_data.json()
        connection = create_connection()
        for division in division_data['divisions']:
            execute_sql(
                connection, "INSERT INTO divisions"
                f"    VALUES ({division['id']}"
                f"         , '{division['name']}'"
                f"         , '{division['abbreviation']}'"
                f"         , {division['active']})")
        close_and_commit_connection(connection)