コード例 #1
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
コード例 #2
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
コード例 #3
0
def get_quarter_scores_markdown(soup, home_team, away_team):
    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 idx, row in enumerate(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_fs.get(
            home_team).full_md if idx == 0 else team_info_by_fs.get(
                away_team).full_md

        cols_markdown = rh.build_table_delimitors(quarter_table_cols)

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

    return final_table
コード例 #4
0
def handle_thread_update(home_team, away_team, submission, game_link):
    r = requests.get(game_link)

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

    updated = False

    if is_page_ready(soup):
        final_game_information_markdown = get_game_information_markdown(soup)
        final_score_markdown = get_scores_table(soup, home_team, away_team)
        final_quarters_score_markdown = get_quarter_scores_markdown(
            soup, home_team, away_team)
        home_table_markdown, away_table_markdown = get_tables_markdown(
            soup, home_team, away_team)

        final_markdown = rh.newline_join([
            final_game_information_markdown, rc.REDDIT_HR,
            final_score_markdown, rc.REDDIT_HR, final_quarters_score_markdown,
            rc.REDDIT_HR, home_table_markdown, rc.NEWLINE, away_table_markdown
        ])

        submission.edit(final_markdown)

        updated = True

    return submission, updated
コード例 #5
0
    def __repr__(self):
        repr_games = [repr(g) for g in self.games]

        final_table = rh.get_reddit_table_head_and_cell_alignment(
            ['GAME', 'DAY', 'HOME', 'AWAY', '#'])

        return rh.newline_join([final_table, *repr_games])
コード例 #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_fs.get(home_team_name).full_md
    away_team_md = team_info_by_fs.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 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
コード例 #8
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
コード例 #9
0
def build_thread_title_and_markdown(soup, competition: str):
    final_game_information_markdown = get_game_information_markdown(soup)
    home_team_orig, home_team_name, away_team_orig, away_team_name, final_score_markdown = get_team_names_and_scores_table(
        soup)
    final_quarters_score_markdown = get_quarter_scores_markdown(soup)
    home_table_markdown, away_table_markdown = get_tables_markdown(
        soup, home_team_orig, away_team_orig)
    comp_stage, comp_round = get_game_stage(soup)

    final_markdown = rh.newline_join([
        final_game_information_markdown, rc.REDDIT_HR, final_score_markdown,
        rc.REDDIT_HR, final_quarters_score_markdown, rc.REDDIT_HR,
        home_table_markdown, rc.NEWLINE, away_table_markdown
    ])

    final_title = 'Post-Match Thread: {home_team} - {away_team} [{comp} {comp_stage}, {comp_round}]'.format(
        comp=competition,
        home_team=home_team_name,
        away_team=away_team_name,
        comp_round=comp_round,
        comp_stage=comp_stage)

    return final_title, final_markdown
コード例 #10
0
def get_game_information_markdown(soup):
    date_stadium_info_div = soup.find('div', class_='dates')

    date_info_cet = (date_stadium_info_div.find(
        'div', class_='date cet').text).replace('CET: ', '') + ' CET'
    stadium_info = date_stadium_info_div.find('span', class_='stadium').text
    attendance_info = soup.find(
        id=
        'ctl00_ctl00_ctl00_ctl00_maincontainer_maincontent_contentpane_boxscorepane_ctl00_lblAudience'
    ).text
    referees_info = soup.find(
        id=
        'ctl00_ctl00_ctl00_ctl00_maincontainer_maincontent_contentpane_boxscorepane_ctl00_lblReferees'
    ).text

    date_info_cet_markdown = rh.bold('Event Date:') + date_info_cet
    stadium_info_markdown = rh.bold('Stadium:') + stadium_info
    attendance_info_markdown = rh.bold('Attendance:') + attendance_info
    referees_info_markdown = rh.bold('Referees:') + referees_info

    return rh.newline_join([
        date_info_cet_markdown, rc.NEWLINE, stadium_info_markdown, rc.NEWLINE,
        attendance_info_markdown, rc.NEWLINE, referees_info_markdown
    ])