Ejemplo n.º 1
0
def get_league_standings(league, season, results_array=None):
    league = str(league)
    season = str(season)

    if results_array is None or len(results_array) == 0:
        results_array.append([
            'Team Name', 'League', 'Season', 'Games', 'W', 'L', 'OT', 'GF',
            'GA', 'Points', 'PostSeason'
        ])

    standings_url = 'http://www.eliteprospects.com/standings.php?league={0}&startdate={1}'.format(
        league, str(int(season) - 1))
    request = requests.get(standings_url)
    standings_page = html5lib.parse(request.text)

    standings_table = standings_page.find(
        './/*[@id="standings"]/{0}div/{0}div[3]/{0}table'.replace(
            '{0}', html_prefix))

    teams_by_conference = helpers.get_ep_table_rows(standings_table)
    """ Parse the team standings table """

    for conference in teams_by_conference:
        for team in conference:
            team_stats = team.findall('.//{0}td'.format(html_prefix))

            name = team_stats[NAME].find(
                './/{0}span/{0}a'.format(html_prefix)).text.strip()
            games = team_stats[GAMES].text.strip()

            def parse_number(node):
                try:
                    return int(node.text)
                except (ValueError, Exception):
                    return 0

            wins = parse_number(team_stats[WINS])
            losses = parse_number(team_stats[LOSSES])
            ties = parse_number(team_stats[TIES])
            ot_wins = parse_number(team_stats[OT_WINS])
            ot_losses = parse_number(team_stats[OT_LOSSES])
            goals_for = team_stats[GOALS_FOR].text.strip()
            goals_against = team_stats[GOALS_AGAINST].text.strip()
            points = team_stats[POINTS].text.strip()
            postseason = ''.join(team_stats[POSTSEASON].itertext()).strip()

            results_array.append([
                name, league, season, games, wins + ot_wins, losses,
                ot_losses + ties, goals_for, goals_against, points, postseason
            ])

    return results_array
Ejemplo n.º 2
0
def get_player_stats(league,
                     season,
                     results_array=None,
                     goalie_results_array=None):
    league = str(league)
    season = str(season)

    if results_array is None:
        results_array = []
    if goalie_results_array is None:
        goalie_results_array = []
    team_urls = []
    """ Get the league link """

    team_search_url = "http://www.eliteprospects.com/standings.php?league={0}&startdate={1}".format(
        league, str(int(season) - 1))
    team_search_request = requests.get(team_search_url)

    # All tag names have this prepended to them
    html_prefix = '{http://www.w3.org/1999/xhtml}'
    team_search_page = html5lib.parse(team_search_request.text)
    team_table = team_search_page.find(
        './/*[@id="standings"]/{0}div/{0}div[3]/{0}table'.replace(
            '{0}', html_prefix))

    teams_by_conference = helpers.get_ep_table_rows(team_table)

    for conference in teams_by_conference:
        for team in conference:
            team_url: str = team.find(
                './/{0}td[2]/{0}span/{0}a'.format(html_prefix)).attrib['href']
            if re.compile('/\d{4}-\d{4}$').search(team_url):
                team_url = team_url[:team_url.rfind('/')]
            if team_url.endswith('/'):
                team_url = team_url[:-1]
            team_urls.append("{}/{}-{}".format(team_url,
                                               int(season) - 1, season))
    """ Get the players """

    for team_url in team_urls:
        team_stats.get_player_stats(team_url, season, league, results_array,
                                    goalie_results_array)

    return results_array
Ejemplo n.º 3
0
def get_player_stats(team_url, season, league_name, results_array, goalie_results_array):
    if results_array is None:
        results_array = []

    if len(results_array) == 0:
        results_array.append(['Name', 'Position', 'Season', 'League',
                              'Team', 'GP', 'G', 'A', 'TP', 'PIM', '+/-', 'ID'])

    if goalie_results_array is None:
        goalie_results_array = []

    if len(goalie_results_array) == 0:
        goalie_results_array.append(
            ['Name', 'Season', 'League', 'Team', 'GP', 'GAA', 'SV%', 'ID'])

    team_search_request = requests.get(team_url + '?tab=stats#players')
    team_page = html5lib.parse(team_search_request.text)

    team_name = team_page.find('.//*[@id="name-and-logo"]/{0}h1'.format(helpers.html_prefix)).text.strip()

    player_table = team_page.find(
        './/*[@id="players"]/{0}div[1]/{0}div[4]/{0}table'.format(helpers.html_prefix))
    goalies_table = team_page.find(
        './/*[@id="players"]/{0}div[2]/{0}div[2]/{0}table'.format(helpers.html_prefix))

    players_grouped = helpers.get_ep_table_rows(player_table)
    goalies_grouped = helpers.get_ep_table_rows(goalies_table)

    for group in players_grouped:
        for player in group:
            player_stats = player.findall(
                './/{}td'.format(helpers.html_prefix))

            name_link = player_stats[NAME].find(
                './{0}span/{0}a'.format(helpers.html_prefix))
            name, position = helpers.get_info_from_player_name(name_link.text)
            id = helpers.get_player_id_from_url(
                name_link.attrib['href'])
            games = player_stats[GAMES].text.strip()
            goals = player_stats[GOALS].text.strip()
            assists = player_stats[ASSISTS].text.strip()
            points = player_stats[POINTS].text.strip()
            pim = player_stats[PIM].text.strip()
            plusminus = player_stats[PLUSMINUS].text.strip()

            results_array.append([
                name,
                position,
                season,
                league_name,
                team_name,
                games,
                goals,
                assists,
                points,
                pim,
                plusminus,
                id,
            ])

    for goalie_group in goalies_grouped:
        for goalie in goalie_group:
            goalie_stats = goalie.findall('./{}td'.format(helpers.html_prefix))

            name_link = goalie_stats[GOALIE_NAME].find(
                './{0}a'.format(helpers.html_prefix))
            name = name_link.text.strip()
            id = helpers.get_player_id_from_url(
                name_link.attrib['href'])

            games = goalie_stats[GOALIE_GP].text.strip()
            gaa = goalie_stats[GOALIE_GAA].text.strip()
            svp = goalie_stats[GOALIE_SVP].text.strip()

            goalie_results_array.append([
                name,
                season,
                league_name,
                team_name,
                games,
                gaa,
                svp,
                id,
            ])
Ejemplo n.º 4
0
def get_team_roster(team_url,
                    season,
                    league_name,
                    player_ids=None,
                    results_array=None,
                    multiple_teams=False):
    if results_array is None:
        results_array = []

    if player_ids is None:
        player_ids = []

    if len(results_array) == 0:
        results_array.append([
            'Number', 'Name', 'Position', 'Season', 'League', 'Team', 'DOB',
            'Hometown', 'Height', 'Weight', 'Shoots', 'ID'
        ])

    team_search_request = requests.get(team_url)
    team_page = html5lib.parse(team_search_request.text)

    team_name = team_page.find('.//*[@id="name-and-logo"]/{0}h1'.format(
        helpers.html_prefix)).text.strip()

    player_table = team_page.find(
        './/*[@id="roster"]/{0}div/{0}div[3]/{0}table'.format(
            helpers.html_prefix))

    players_by_position = helpers.get_ep_table_rows(player_table)

    for position in players_by_position:
        for player in position:
            player_stats = player.findall('./{}td'.format(helpers.html_prefix))

            try:
                name_link = player_stats[NAME].find('./{0}span/{0}a'.format(
                    helpers.html_prefix))
                name, position = helpers.get_info_from_player_name(
                    name_link.text)
                id = helpers.get_player_id_from_url(name_link.attrib['href'])
                number = player_stats[JERSEY_NUMBER].text.strip()[1:]
                dob = player_stats[DOB].get('title').strip()
                hometown = player_stats[HOMETOWN].find('./{}a'.format(
                    helpers.html_prefix)).text.strip()
                height = player_stats[HEIGHT].text.strip()
                weight = player_stats[WEIGHT].text.strip()
                shoots = player_stats[SHOOTS].text.strip()
            except IndexError:
                continue

            if not multiple_teams:
                player_id = name + dob + hometown
                if player_id in player_ids:
                    index = player_ids.index(player_id)
                    results_array[index][5] = 'multiple'
                    continue

                player_ids.append(player_id)

            results_array.append([
                number,
                name,
                position,
                season,
                league_name,
                team_name,
                dob,
                hometown,
                height,
                weight,
                shoots,
                id,
            ])
Ejemplo n.º 5
0
def get_draft_picks(season, results_array=None, show_extra=False):
    if results_array is None:
        results_array = []
    if len(results_array) == 0:
        results_array.append(['Year', 'Round', 'Number', 'Team', 'Name', 'Position',
                              'Seasons', 'Games', 'Goals', 'Assists', 'Points', 'PIM', 'Birthday'])

    url = 'http://www.eliteprospects.com/draft.php?year={0}'.format(
        str(season))
    r = requests.get(url)

    # All tag names have this prepended to them
    html_prefix = '{http://www.w3.org/1999/xhtml}'
    draft_page = html5lib.parse(r.text)
    draft_table = draft_page.find(
        './body/section[2]/div/div[1]/div[4]/div[3]/div[1]/div[1]/div[3]/table'.replace('/', '/' + html_prefix))

    pick_number = 1

    rounds = helpers.get_ep_table_rows(draft_table)

    for round_number in range(1, len(rounds) + 1):
        players = rounds[round_number - 1]

        for playerIndex in range(0, len(players)):
            player = players[playerIndex]
            columns = player.findall('.//{0}td'.format(html_prefix))

            player_birthday = ''

            try:
                name_link = columns[NAME].find(
                    './{0}span/{0}a'.format(html_prefix))
                name, position = helpers.get_info_from_player_name(
                    name_link.text)
                if show_extra:
                    player_request = requests.get(name_link.attrib['href'])
                    player_page = html5lib.parse(player_request.text)

                    player_birthday = player_page.find(
                        './body/section[2]/div/div[1]/div[4]/div[1]/div[1]/div[2]/section/div[4]/div[1]/div[1]/ul/li[1]/div[2]/a'.replace(
                            '/', '/' + html_prefix)
                    ).text.strip()
            except AttributeError:
                name = 'No selection made'
                position = 'N/A'

            results_array.append([
                season,
                round_number,
                pick_number,
                columns[TEAM].find('./{}a'.format(html_prefix)).text,
                name,
                position,
                columns[SEASONS].text.strip(),
                columns[GAMES].text.strip() or '',
                columns[GOALS].text.strip() or '',
                columns[ASSISTS].text.strip() or '',
                columns[POINTS].text.strip() or '',
                columns[PIM].text.strip() or '',
                player_birthday
            ])

            pick_number += 1

    return results_array