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
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
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
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
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
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
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