def populate_subreddit_lists(config): """ Gets the list of subreddits to monitor and loads it into memory. :return: None. """ config.subreddits_to_check = [] config.upvote_filter_subs = {} config.no_link_header_subs = [] config.subreddits_to_check = get_wiki_page('subreddits', config).split('\r\n') config.subreddits_to_check = clean_list(config.subreddits_to_check) logging.debug('Created list of subreddits from wiki: {}'.format( config.subreddits_to_check)) for line in get_wiki_page('subreddits/upvote-filtered', config).splitlines(): if ',' in line: sub, threshold = line.split(',') config.upvote_filter_subs[sub] = int(threshold) logging.debug( 'Retrieved subreddits subject to the upvote filter: {}'.format( config.upvote_filter_subs)) config.subreddits_domain_filter_bypass = get_wiki_page( 'subreddits/domain-filter-bypass', config).split('\r\n') config.subreddits_domain_filter_bypass = clean_list( config.subreddits_domain_filter_bypass) logging.debug( 'Retrieved subreddits that bypass the domain filter: {}'.format( config.subreddits_domain_filter_bypass)) config.no_link_header_subs = get_wiki_page('subreddits/no-link-header', config).split('\r\n') config.no_link_header_subs = clean_list(config.no_link_header_subs) logging.debug( 'Retrieved subreddits subject to the upvote filter: {}'.format( config.no_link_header_subs)) lines = get_wiki_page('subreddits/archive-time', config).splitlines() config.archive_time_default = int(lines[0]) config.archive_time_subreddits = {} for line in lines[1:]: if ',' in line: sub, time = line.split(',') config.archive_time_subreddits[sub.lower()] = int(time)
def populate_domain_lists(config): """ Loads the approved content domains into the config object from the wiki page. :return: None. """ config.video_domains = [] config.image_domains = [] config.audio_domains = [] domains = get_wiki_page('domains', config) domains = ''.join(domains.splitlines()).split('---') for domainset in domains: domain_list = domainset[domainset.index('['):].strip('[]').split(', ') current_domain_list = [] if domainset.startswith('video'): current_domain_list = config.video_domains elif domainset.startswith('audio'): current_domain_list = config.audio_domains elif domainset.startswith('images'): current_domain_list = config.image_domains current_domain_list += domain_list # [current_domain_list.append(x) for x in domain_list] logging.debug(f'Domain list populated: {current_domain_list}')
def populate_formatting(config): """ Grabs the contents of the three wiki pages that contain the formatting examples and stores them in the config object. :return: None. """ # zero out everything so we can reinitialize later config.audio_formatting = '' config.video_formatting = '' config.image_formatting = '' config.other_formatting = '' config.audio_formatting = get_wiki_page('format/audio', config) config.video_formatting = get_wiki_page('format/video', config) config.image_formatting = get_wiki_page('format/images', config) config.other_formatting = get_wiki_page('format/other', config)
def process_claim(post, config): """ Handles comment replies containing the word 'claim' and routes based on a basic decision tree. :param post: The Comment object containing the claim. :param config: the global config dict. :return: None. """ top_parent = get_parent_post_id(post, config.r) # WAIT! Do we actually own this post? if top_parent.author.name != 'transcribersofreddit': logging.debug('Received `claim` on post we do not own. Ignoring.') return try: if not coc_accepted(post, config): # do not cache this page. We want to get it every time. post.reply( _( please_accept_coc.format( get_wiki_page('codeofconduct', config)))) return # this can be either '' or None depending on how the API is feeling # today if top_parent.link_flair_text in ['', None]: # There exists the very small possibility that the post was # malformed and doesn't actually have flair on it. In that case, # let's set something so the next part doesn't crash. flair_post(top_parent, flair.unclaimed) if flair.unclaimed in top_parent.link_flair_text: # need to get that "Summoned - Unclaimed" in there too post.reply(_(claim_success)) flair_post(top_parent, flair.in_progress) logging.info( f'Claim on ID {top_parent.fullname} by {post.author} successful' ) # can't claim something that's already claimed elif top_parent.link_flair_text == flair.in_progress: post.reply(_(already_claimed)) elif top_parent.link_flair_text == flair.completed: post.reply(_(claim_already_complete)) except praw.exceptions.APIException as e: if e.error_type == 'DELETED_COMMENT': logging.info( f'Comment attempting to claim ID {top_parent.fullname} has ' f'been deleted. Back up for grabs! ') return raise # Re-raise exception if not
def process_claim(post, config): """ Handles comment replies containing the word 'claim' and routes based on a basic decision tree. :param post: The Comment object containing the claim. :param config: the global config dict. :return: None. """ top_parent = get_parent_post_id(post, config.r) # WAIT! Do we actually own this post? if top_parent.author.name != 'transcribersofreddit': logging.debug('Received `claim` on post we do not own. Ignoring.') return if not coc_accepted(post, config): # do not cache this page. We want to get it every time. post.reply(_( please_accept_coc.format(get_wiki_page('codeofconduct', config.tor)) )) return if top_parent.link_flair_text is None: # There exists the very small possibility that the post was malformed # and doesn't actually have flair on it. In that case, let's set # something so the next part doesn't crash. flair_post(top_parent, flair.unclaimed) if flair.unclaimed in top_parent.link_flair_text: # need to get that "Summoned - Unclaimed" in there too post.reply(_(claim_success)) flair_post(top_parent, flair.in_progress) logging.info( 'Claim on ID {} by {} successful'.format( top_parent.fullname, post.author ) ) # can't claim something that's already claimed elif top_parent.link_flair_text == flair.in_progress: post.reply(_(already_claimed)) elif top_parent.link_flair_text == flair.completed: post.reply(_(claim_already_complete))
def populate_header(config): config.header = '' config.header = get_wiki_page('format/header', config)
def populate_gifs(config): # zero it out so we can load more config.no_gifs = [] config.no_gifs = get_wiki_page('usefulgifs/no', config).split('\r\n')