def print_monthly_top_comment_authors(year, month):
    last_day_of_month = monthrange(year, month)[1]
    before_timestamp = int(datetime(
        year, month, last_day_of_month, 23, 59, 59, tzinfo=timezone.utc).timestamp())
    after_timestamp = int(datetime(year, month, 1, 0, 0,
                                   1, tzinfo=timezone.utc).timestamp())

    subreddit = get_subreddit()

    author_exceptions = [*subreddit.banned(), 'timee_bot', '[deleted]']

    pushshift_comments = get_data_from_pushshift(
        author_exceptions, after_timestamp, before_timestamp, False)
    praw_comments = fill_remaining_from_praw(
        subreddit, author_exceptions, pushshift_comments, before_timestamp)

    pushshift_authors = [c['author'] for c in pushshift_comments]
    praw_authors = [c.author.name for c in praw_comments]

    post_authors = pushshift_authors + praw_authors

    print('Total # of posts: {}'.format(len(post_authors)))
    post_authors_counter = Counter(post_authors)
    print()
    print(convert_counter_most_common_to_reddit_table(
        post_authors_counter.most_common(20), ['Name', '#']))
    print()
Example #2
0
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)
Example #3
0
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="Sidebar update")
    parser.add_argument('week', metavar='W', type=int)
    args = parser.parse_args()

    sidebar_tables = dict()

    # Regular season methods
    if args.week < FIRST_ROUND_OF_PLAYOFFS:
        standings_table = get_standings_table()
        results_table = get_results_table(args.week)

        sidebar_tables['Standings'] = standings_table
        sidebar_tables['Results'] = results_table

        # Schedule is different on the last day of the regular season
        # The dates for the playoffs are only announced afterwards,
        # hence no schedule table after the last round of the regular season
        if args.week < FIRST_ROUND_OF_PLAYOFFS - 1:
            schedule_table = get_schedule_table(args.week + 1)
            sidebar_tables['Schedule'] = schedule_table
    # Find out where the playoffs end and final 4 begins
    else:
        playoffs_tables = get_playoffs_tables(args.week,
                                              FIRST_ROUND_OF_PLAYOFFS)
        sidebar_tables['Playoffs'] = playoffs_tables

    subreddit = get_subreddit()

    if args.week == FIRST_ROUND_OF_PLAYOFFS:
        clean_widgets(subreddit)

    update_new_reddit(subreddit, sidebar_tables)
    update_old_reddit(subreddit, sidebar_tables, args.week)
Example #5
0
def main():
    competition_groups = get_competitions()

    week_interval = get_current_week_interval()

    subreddit = get_subreddit()

    driver = webdriver.Firefox()

    build_discussion_threads(subreddit, driver, competition_groups,
                             week_interval)

    driver.close()
def main():
    parser = argparse.ArgumentParser(description="Flair counter")

    subparsers = parser.add_subparsers(help='commands')

    parser.add_argument('--team',
                        '-t',
                        dest='team',
                        type=str,
                        nargs=1,
                        metavar='t')

    parser.add_argument('--selenium', '-s', action='store_const', const=True)

    save_parser = subparsers.add_parser('save', help='Saves the count')
    save_parser.add_argument(dest='year',
                             type=int,
                             nargs=1,
                             choices=[2020, 2021])
    save_parser.add_argument(dest='month',
                             type=int,
                             nargs=1,
                             choices=range(1, 13))
    save_parser.add_argument('--lock',
                             '-l',
                             dest='lock',
                             action='store_const',
                             default=False,
                             const=True)

    args = parser.parse_args()

    subreddit = get_subreddit()

    if args.selenium:
        all_users_flairs = get_flairs_from_selenium()
    else:
        all_users_flairs = get_flairs_from_praw(subreddit)

    if args.team is not None:
        print_redditors_from_club(all_users_flairs, args.team[0])
    else:
        flair_table_str = get_flair_table_list_from_all_flairs(
            all_users_flairs)
        if hasattr(args, 'year') and hasattr(args, 'month'):
            save_flair_count(flair_table_str, args.year[0], args.month[0],
                             args.lock)
Example #7
0
def main():
    subreddit = get_subreddit()

    update_converted_dms(subreddit)
def main():
    subreddit = get_subreddit()

    handle_reddit_streams(subreddit)
Example #9
0
class Game():
    # Since new returns an iterator, it's obligatory to convert to list so that elements are not consumed
    submissions = list(get_subreddit().new(limit=100))

    def __init__(self, comp_stage, game_str, team_1, team_2, date, score=None, bool_md_round=True):
        self.comp_stage = comp_stage
        self.game_str = game_str
        self.home_team = team_1
        self.away_team = team_2
        self.date = date
        self.score = score
        self.bool_md_round = bool_md_round

        self.game_number = [int(s)
                            for s in self.game_str.split() if s.isdigit()][0]

    @property
    def score(self):
        return self._score

    @score.setter
    def score(self, value):
        self._score = value

    @property
    def number(self):
        return self._number

    @number.setter
    def number(self, value):
        self._number = value

    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'

    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
Example #10
0
class RedditGameThread():
    comp_info = None
    subreddit = get_subreddit()

    def __init__(self,
                 home_team,
                 away_team,
                 comp_round=None,
                 comp_stage=None,
                 game_state=GameState.UNFINISHED,
                 thread_state=ThreadState.UNPUBLISHED,
                 game_link=None,
                 reddit_submission=None):
        self.home_team = home_team
        self.away_team = away_team

        self.comp_round = comp_round
        self.comp_stage = comp_stage

        self.game_state = game_state
        self.thread_state = thread_state

        self.game_link = game_link
        self.reddit_submission = reddit_submission

    def __str__(self):
        comp_stage_and_round = self.comp_round if self.comp_round == 'Semifinal' else "{}, {}".format(
            self.comp_stage, self.comp_round)

        str_list = list()
        str_list.append('Matchup: {} vs {} | {}'.format(
            self.home_team, self.away_team, comp_stage_and_round))
        str_list.append('State: {} / {}'.format(self.thread_state,
                                                self.game_state))
        str_list.append('Game Link: {}'.format(self.game_link))
        if self.reddit_submission is not None:
            str_list.append('Reddit Submission: {}'.format(
                'https://old.reddit.com/r/Euroleague/comments/' +
                str(self.reddit_submission)))
        return '\n'.join(str_list)

    def __eq__(self, other):
        """Overrides the default implementation"""
        if isinstance(other, RedditGameThread):
            return self.home_team == other.home_team and self.away_team == other.away_team
        return False

    @classmethod
    def set_competition_info(cls, comp_info):
        cls.comp_info = comp_info

    @property
    def home_team(self):
        return self._home_team

    @home_team.setter
    def home_team(self, value):
        self._home_team = value

    @property
    def away_team(self):
        return self._away_team

    @away_team.setter
    def away_team(self, value):
        self._away_team = value

    @property
    def comp_round(self):
        return self._comp_round

    @comp_round.setter
    def comp_round(self, value):
        self._comp_round = value

    @property
    def comp_stage(self):
        return self._comp_stage

    @comp_stage.setter
    def comp_stage(self, value):
        self._comp_stage = value

    @property
    def game_state(self):
        return self._game_state

    @game_state.setter
    def game_state(self, value):
        if value not in GameState:
            raise ValueError('Invalid game state')

        self._game_state = value

    @property
    def thread_state(self):
        return self._thread_state

    @thread_state.setter
    def thread_state(self, value):
        if value not in ThreadState:
            raise ValueError('Invalid thread state')

        self._thread_state = value

    @property
    def game_link(self):
        return self._game_link

    @game_link.setter
    def game_link(self, value):
        self._game_link = value

    @property
    def reddit_submission(self):
        return self._reddit_submission

    @reddit_submission.setter
    def reddit_submission(self, value):
        self._reddit_submission = value

    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 update_thread(self):
        if self.reddit_submission is None:
            raise ValueError('Reddit Thread should not be null')

        self.reddit_submission, updated = handle_thread_update(
            self.home_team, self.away_team, self.reddit_submission,
            self.game_link)

        if updated:
            self._thread_state = ThreadState.COMPLETED