コード例 #1
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
コード例 #2
0
def get_table_markdown(table, name, coach):
    table_rows = table.find_all('tr')

    team_markdown = team_info_by_fs.get(name).full_md

    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 = rc.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
コード例 #3
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
コード例 #4
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
    ])
コード例 #5
0
def build_competition_group_thread(subreddit, week_start: str, week_end: str,
                                   group_list: list,
                                   weekly_discussion_thread_url: str):
    comp_small_names = list()
    comp_full_names = list()
    markdown_list = list()

    # List value to infer if the text to be prepended includes information about cups/lower leagues
    # This does not apply to competitions whose country is None (i.e., VTB and ABA)
    # In the future, we might add support for countries related to clubs in those leagues
    countries = list()

    for competition, games in group_list:
        comp_small_names.append(competition.small_name)
        comp_full_names.append(competition.full_name)
        markdown_list.append('{}- [Standings]({})'.format(
            bold(competition.full_name), competition.standings))

        if len(games) > 0:
            markdown_list.extend([str(g) for g in games])
        else:
            markdown_list.append('No games scheduled this week')

        markdown_list.append(HORIZONTAL_LINE)

        if competition.country is not None:
            countries.append(competition.country)

    small_names_join = '/'.join(comp_small_names)
    long_names_join = '/'.join(comp_full_names)

    # Depending upon the number of countries in the group, different solutions
    # 0 - unformatted boilerplate (no domestic leagues/lower divisions)
    # 1 - no '/' join in formatted boilerplate
    # >1 - '/' join countries in formatted boilerplate
    if len(countries) > 0:
        bp = read_boilerplate_from_file('group_pre_cup.txt')
        if len(countries) > 1:
            countries_markdown = '/'.join(countries)
            markdown_pre = bp.format(competitions=long_names_join,
                                     countries=countries_markdown)
        else:
            markdown_pre = bp.format(competitions=long_names_join,
                                     countries=countries[0])
    else:
        bp = read_boilerplate_from_file('group_pre.txt')
        markdown_pre = bp.format(competitions=long_names_join)

    markdown_post = 'Is this not what you were looking for? Head back to the [Weekly Discussion Thread]({}).'.format(
        weekly_discussion_thread_url)

    # Technique used to "prepend" the preceeding elements in the markdown
    markdown_list = [
        markdown_pre, HORIZONTAL_LINE, *markdown_list, markdown_post
    ]

    title = '{competitions} Discussion Thread [{week_start} - {week_end}]'.format(
        week_start=week_start,
        week_end=week_end,
        competitions=small_names_join)

    note = "{}Asking for or sharing illegal streams is NOT allowed!".format(
        bold("Note:"))
    markdown = double_newline_join([*markdown_list, note])

    return submit_text_post(subreddit, title, markdown, suggested_sort='new')