コード例 #1
0
def get_schedule_table(week):
    if week > 34:
        return ''

    r = requests.get(
        'https://www.euroleague.net/main/results?gamenumber={}&seasoncode=E2021'.format(week))

    soup = BeautifulSoup(r.text, 'html.parser')

    final_table = rh.get_reddit_table_head_and_cell_alignment(
        ['ROUND', 'DATE', 'HOME', 'AWAY', 'TIME'])

    # Result in 2nd element
    livescores = soup.find_all("div", class_="livescore")

    schedule_html = livescores[1]

    schedule_html_games = schedule_html.find_all("div", class_="game")

    cond_day = 0

    for idx, html_game in enumerate(schedule_html_games):
        both_clubs = html_game.find_all("div", class_="club")

        home_team_name = team_info_by_official.get(
            str(both_clubs[0].find("span", class_="name").get_text())).letter3_md
        away_team_name = team_info_by_official.get(
            str(both_clubs[1].find("span", class_="name").get_text())).letter3_md

        el_round = str(week) if idx == 0 else ""
        game_date = html_game.find("span", class_="date")
        if game_date is not None:
            game_date_text = game_date.get_text()

            # Removes "CET" from the string
            game_date_text = game_date_text.strip()[:len(game_date_text) - 4]
            game_date_text = datetime.strptime(game_date_text, "%B %d %H:%M")

            el_date = game_date_text.strftime("%b %d") if idx == 0 or (
                idx > 0 and int(game_date_text.day) != cond_day) else ""
            cond_day = game_date_text.day
            row_markdown = rh.build_table_delimitors(
                [el_round, el_date, home_team_name, away_team_name, game_date_text.strftime("%H:%M")])
        else:
            el_date = ''
            row_markdown = rh.build_table_delimitors(
                [el_round, el_date, home_team_name, away_team_name, 'PP'])

        final_table = rh.newline_join([final_table, row_markdown])

    # Add note
    final_table = rh.newline_join(
        [final_table, '**Note:** All CET times // PP = Postponed'])
    return final_table
コード例 #2
0
def get_eurocup_games(now_time, soup, main_url):
    group_container = soup.find_all('div', class_='group-container')
    games_markdown = list()

    # when no group-container, it defaults to the Euroleague markup format
    if len(group_container) == 0:
        return get_euroleague_games(now_time, soup, main_url)

    for group in group_container:
        group_games = group.find_all('div', class_='game')

        for game in group_games:
            has_date = game.find('span', class_='date')

            if not has_date:
                continue

            game_date = has_date.text

            game_date = game_date.strip()[:len(game_date) - 4]
            game_date = datetime.strptime(game_date, "%B %d %H:%M")

            if game_date.day == now_time.day and game_date.month == now_time.month:
                game_clubs = game.find_all('div', class_='club')

                game_home_team = team_info_by_official.get(game_clubs[0].find(
                    'span', class_='name').text).reddit
                game_away_team = team_info_by_official.get(game_clubs[1].find(
                    'span', class_='name').text).reddit

                matchup_text = "{home_team} - {away_team}".format(
                    home_team=rh.bold(game_home_team),
                    away_team=rh.bold(game_away_team))

                matchup_url = main_url + \
                    game.find('a', class_="game-link")['href']

                matchup_linked_text = build_linked_text(
                    matchup_text, matchup_url)

                matchup_time = "{hours}:{minutes} CET".format(
                    hours=game_date.strftime('%H'),
                    minutes=game_date.strftime('%M'))

                game_md = '{} | {}'.format(matchup_linked_text, matchup_time)

                games_markdown.append((game_date, game_md))

    return games_markdown
コード例 #3
0
def get_table_markdown(table, name, coach):
    table_rows = table.find_all('tr')

    team_markdown = team_info_by_official.get(name).full_md.upper()

    final_table = rh.get_reddit_table_head_and_cell_alignment([
        rc.NUMBER, team_markdown, rc.MINUTES, rc.POINTS, rc.FG2, rc.FG3,
        rc.FREE_TRHOWS, rc.OFF_REBOUNDS, rc.DEF_REBOUNDS, rc.TOT_REBOUNDS,
        rc.ASSISTS, rc.STEALS, rc.TURNOVERS, rc.BLOCKS, rc.FOULS_COMMITED,
        rc.PIR
    ])

    for row in table_rows[2:len(table_rows) - 1]:
        cols = row.find_all('td')
        cols = [ele.text.strip() for ele in cols]

        # Removes the blocks against and fouls drawn columns
        cols.pop(16)
        cols.pop(14)

        cols_markdown = rh.build_table_delimitors(cols)
        final_table = rh.newline_join([final_table, cols_markdown])

    head_coach_markdown = rh.bold("Head Coach:") + coach
    final_table = rh.newline_join(
        [head_coach_markdown, rc.NEWLINE, final_table])

    return final_table
コード例 #4
0
def get_quarter_scores_markdown(soup):
    quarter_table = soup.find(
        id=
        "ctl00_ctl00_ctl00_ctl00_maincontainer_maincontent_contentpane_boxscorepane_ctl00_PartialsStatsByQuarter_dgPartials"
    )
    quarter_table_rows = quarter_table.find_all('tr')

    table_head_elements = [
        th.text.upper() for th in quarter_table_rows[0].find_all('th')
    ]
    final_table = rh.get_reddit_table_head_and_cell_alignment(
        table_head_elements, left_align_first=True)

    for row in quarter_table_rows[1:]:
        quarter_table_cols = row.find_all('td')
        quarter_table_cols = [ele.text.strip() for ele in quarter_table_cols]

        # Overrides the team name
        quarter_table_cols[0] = team_info_by_official.get(
            quarter_table_cols[0]).full_md

        cols_markdown = rh.build_table_delimitors(quarter_table_cols)

        final_table = rh.newline_join([final_table, cols_markdown])

    return final_table
コード例 #5
0
def get_euroleague_games(now_time, soup, main_url):
    all_games = soup.find_all('div',
                              class_='livescore')[1].find_all('div',
                                                              class_='game')

    games_markdown = list()

    for game in all_games:
        has_date = game.find('span', class_='date')

        if not has_date:
            continue

        game_date = has_date.text

        game_date = game_date.strip()[:len(game_date) - 4]
        game_date = datetime.strptime(game_date, "%B %d %H:%M")

        # Date is not set, continue to next game
        if game_date is None:
            continue

        if game_date.day == now_time.day and game_date.month == now_time.month:
            game_clubs = game.find_all('div', class_='club')

            game_home_team = team_info_by_official.get(game_clubs[0].find(
                'span', class_='name').text).reddit
            game_away_team = team_info_by_official.get(game_clubs[1].find(
                'span', class_='name').text).reddit

            matchup_text = "{home_team} - {away_team}".format(
                home_team=rh.bold(game_home_team),
                away_team=rh.bold(game_away_team))

            matchup_url = main_url + game.find('a', class_="game-link")['href']

            matchup_linked_text = build_linked_text(matchup_text, matchup_url)

            matchup_time = "{hours}:{minutes} CET".format(
                hours=game_date.strftime('%H'),
                minutes=game_date.strftime('%M'))

            game_md = '{} | {}'.format(matchup_linked_text, matchup_time)

            games_markdown.append((game_date, game_md))

    return games_markdown
コード例 #6
0
def get_final_score_markdown(home_team_name, home_team_score, away_team_name,
                             away_team_score):
    final_table = rh.get_reddit_table_head_and_cell_alignment(
        ['TEAM', 'SCORE'], left_align_first=True)

    home_team_md = team_info_by_official.get(home_team_name).full_md
    away_team_md = team_info_by_official.get(away_team_name).full_md

    home_team_name_score = rh.build_table_delimitors(
        [home_team_md, home_team_score])
    away_team_name_score = rh.build_table_delimitors(
        [away_team_md, away_team_score])

    final_table = rh.newline_join(
        [final_table, home_team_name_score, away_team_name_score])

    return final_table
コード例 #7
0
    def __repr__(self):
        submission_url = self.get_result_thread()

        result = "[{home_team_score}-{away_team_score}]({submission_url})".format(home_team_score=str(
            self.score[0]), away_team_score=str(self.score[1]), submission_url=submission_url) if self.score[0] != '-' and self.score[1] != '-' else 'POSTPONED'

        home_team_3lmd = team_info_by_official.get(self.home_team).letter3_md
        away_team_3lmd = team_info_by_official.get(self.away_team).letter3_md

        # For testing purposes
        # home_team_3lmd = '[HOM](https://www.old.reddit.com/r/Euroleague)'
        # away_team_3lmd = '[AWA](https://www.old.reddit.com/r/Euroleague)'

        game_or_round_md = str(self.game_number) if self.bool_md_round else ""

        row_markdown = build_table_delimitors(
            [game_or_round_md, home_team_3lmd, away_team_3lmd, result])

        return row_markdown
コード例 #8
0
    def get_result_thread(self):
        reddit_home_team = team_info_by_official.get(self.home_team).reddit
        reddit_away_team = team_info_by_official.get(self.away_team).reddit

        # For testing purposes:
        # reddit_home_team = 'Home Team'
        # reddit_away_team = 'Away Team'

        title_to_find = 'Post-Match Thread: {home_team} - {away_team} [EuroLeague {competition_stage}, {round_or_game}]'.format(
            home_team=reddit_home_team, away_team=reddit_away_team, competition_stage=self.comp_stage, round_or_game=self.game_str)

        for submission in Game.submissions:
            if submission.title == title_to_find:
                return submission.url

        # return None

        # For testing purposes
        return 'https://old.reddit.com/r/Euroleague'
コード例 #9
0
def get_results_table(week):
    r = requests.get(
        'https://www.euroleague.net/main/results?gamenumber={}&phasetypecode=RS&seasoncode=E2021'
        .format(week))

    soup = BeautifulSoup(r.text, 'html.parser')

    final_table = rh.get_reddit_table_head_and_cell_alignment(
        ['ROUND', 'HOME', 'AWAY', 'RESULT'])

    # Result in 2nd element
    livescores = soup.find_all("div", class_="livescore")

    schedule_html = livescores[1]

    schedule_html_games = schedule_html.find_all("div", class_="game")

    for idx, html_game in enumerate(schedule_html_games):
        both_clubs = html_game.find_all("div", class_="club")

        home_team_name = team_info_by_official.get(
            str(both_clubs[0].find("span",
                                   class_="name").get_text())).letter3_md
        home_team_score = both_clubs[0].find(
            "span", class_="score").attrs['data-score']

        away_team_name = team_info_by_official.get(
            str(both_clubs[1].find("span",
                                   class_="name").get_text())).letter3_md
        away_team_score = both_clubs[1].find(
            "span", class_="score").attrs['data-score']

        el_round = sys.argv[1] if idx == 0 else ""
        result = "[{}-{}]()".format(
            home_team_score, away_team_score
        ) if home_team_score != '-' and away_team_score != '-' else 'POSTPONED'

        row_markdown = rh.build_table_delimitors(
            [el_round, home_team_name, away_team_name, result])

        final_table = rh.newline_join([final_table, row_markdown])

    return final_table
コード例 #10
0
def get_team_names_and_scores_table(soup):
    home_team_orig = soup.find(
        id=
        "ctl00_ctl00_ctl00_ctl00_maincontainer_maincontent_contentpane_boxscorepane_ctl00_LocalClubStats_lblTeamName"
    ).text
    away_team_orig = soup.find(
        id=
        "ctl00_ctl00_ctl00_ctl00_maincontainer_maincontent_contentpane_boxscorepane_ctl00_RoadClubStats_lblTeamName"
    ).text

    home_team_name = team_info_by_official.get(home_team_orig).reddit
    away_team_name = team_info_by_official.get(away_team_orig).reddit

    home_team_score = soup.find(class_="sg-score").find(class_="local").find(
        class_="score").text
    away_team_score = soup.find(class_="sg-score").find(class_="road").find(
        class_="score").text

    return home_team_orig, home_team_name, away_team_orig, away_team_name, get_final_score_markdown(
        home_team_orig, home_team_score, away_team_orig, away_team_score)
コード例 #11
0
def get_standings_table():
    r = requests.get('https://www.euroleague.net/main/standings')

    soup = BeautifulSoup(r.text, 'html.parser')

    final_table = rh.get_reddit_table_head_and_cell_alignment(
        ['#', '', 'W', 'L', '+/-'])

    # Returns only the standings table
    standings_table = soup.find_all("table")

    table_rows = standings_table[0].find_all('tr')

    for idx, row in enumerate(table_rows[1:]):
        cols = row.find_all('td')

        team_ahref = cols[0].find('a').text

        # Strips all the leading and trailing white space, removes the digits and shifts the string 2 positions to remove the '. ' substring
        team_name = ''.join([i for i in team_ahref.strip()
                             if not i.isdigit()])[2:]

        team_markdown = team_info_by_official.get(team_name).full_md

        position = str(idx + 1)
        wins = cols[1].text.strip()
        losses = cols[2].text.strip()
        plus_minus = cols[5].text.strip()

        plus_minus = '+' + \
            plus_minus if plus_minus[0].isdigit() else plus_minus

        cols_markdown = rh.build_table_delimitors(
            [position, team_markdown, wins, losses, plus_minus])

        final_table = rh.newline_join([final_table, cols_markdown])

    return final_table