def main(): parser = argparse.ArgumentParser(description='Post game thread creator') parser.add_argument('competition', metavar='C', type=str, choices=['EL', 'EC']) parser.add_argument('gamecode', metavar='G', type=int) parser.add_argument('--publish', '-p', dest='publish', action='store_const', default=False, const=True) args = parser.parse_args() competition_info = get_competition_info(args.competition) r = requests.get(competition_info.game_url.format(args.gamecode)) soup = BeautifulSoup(r.text, 'html.parser') title, markdown = build_thread_title_and_markdown( soup, competition_info.comp_full_name) if args.publish: subreddit = sr.get_subreddit() sr.submit_text_post(subreddit, title, markdown, flair_text=args.competition) else: print(markdown) pc.copy(markdown)
def main(): parser = argparse.ArgumentParser(description='Live thread creator') parser.add_argument('competition', metavar='C', type=str, choices=['EL', 'EC']) parser.add_argument('--publish', '-p', dest='publish', action='store_const', default=False, const=True) args = parser.parse_args() competition_info = get_competition_info(args.competition) now_time = datetime.now() # now_time = datetime.now() + timedelta(days=3) games_markdown_list = get_games_markdown_list(competition_info, now_time) title, markdown = build_thread_title_and_markdown(games_markdown_list, competition_info, now_time) if args.publish: subreddit = sr.get_subreddit() sr.submit_text_post(subreddit, title, markdown, sticky=True, suggested_sort='new', flair_text=competition_info.comp_small_name) else: print(markdown) pc.copy(markdown)
def build_general_discussion_thread(subreddit, week_start: str, week_end: str): title = 'Weekly Discussion Thread [{} - {}]'.format(week_start, week_end) markdown = 'Will be updated' return submit_text_post(subreddit, title, markdown, sticky=True, suggested_sort='new')
def publish_thread(self): self.thread_state = ThreadState.PUBLISHING home_team_parsed = team_info_by_fs.get(self.home_team).reddit away_team_parsed = team_info_by_fs.get(self.away_team).reddit title = 'Post-Match Thread: {home_team} - {away_team} [{comp} {comp_stage}, {comp_round}]'.format( comp=RedditGameThread.comp_info.comp_full_name, home_team=home_team_parsed, away_team=away_team_parsed, comp_stage=self.comp_stage, comp_round=self.comp_round) markdown = REDDIT_THREAD_PLACEHOLDER_TEXT self.reddit_submission = submit_text_post( RedditGameThread.subreddit, title, markdown, flair_text=RedditGameThread.comp_info.comp_small_name) if self.reddit_submission is not None: self.thread_state = ThreadState.PUBLISHED
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')