def loop(user, reddit, utils): print( '\n> Booting up makeswordclouds. You will be notified when makeswordclouds detects a broken link.' ) print('> To stop the bot, press Ctrl + C.') try: while True: print('\n> Checking submissions for valid entries...') submissions = reddit.get_subreddit('all').get_hot(limit=100) for submission in submissions: sub = submission.subreddit.display_name.lower() if submission.id not in utils.replied and submission.num_comments >= int( utils.config['limit']) and sub not in utils.banned: print('\n> Found valid submission in the subreddit /r/' + submission.subreddit.display_name + '!') text = utils.get_submission_comments(submission.id) cloud = utils.make_cloud(text) upload = utils.upload_image(cloud) print( '> Successfully made word cloud and uploaded to imgur!' ) os.remove(cloud) try: reply = ( 'Here is a word cloud of all of the comments in this thread: ' + upload + '\n\n' '*****\n' '[^source ^code](https://github.com/WinneonSword/makeswordclouds) ^| [^contact ^developer](http://reddit.com/user/WinneonSword)' ) utils.handle_rate_limit(submission, reply) print('> Comment posted! Link: ' + upload) except HTTPError, e: print( '\n> An HTTP error occured trying to post the comment.' ) print('> Response: %s' % e.response) if "403" in str(e.response): utils.add_banned_subreddit(sub) print( '> Added the subreddit %s to the banned list!' % sub) except:
def loop(user, reddit, utils): print('\n> Booting up makeswordclouds. You will be notified when makeswordclouds detects a broken link.') print('> To stop the bot, press Ctrl + C.') try: while True: print('\n> Checking submissions for valid entries...') submissions = reddit.get_subreddit('all').get_hot(limit = 100) for submission in submissions: if submission.id not in utils.replied and submission.num_comments >= 50: print('\n> Found valid submission in the subreddit /r/' + submission.subreddit.display_name + '!') text = utils.get_submission_comments(submission.id) cloud = utils.make_cloud(text) upload = utils.upload_image(cloud) print('> Successfully made word cloud and uploaded to imgur!') os.remove(cloud) try: reply = ( 'Here is a word cloud of all of the comments in this thread: ' + upload + '\n\n' '*****\n' '[^source ^code](https://github.com/WinneonSword/makeswordclouds) ^| [^contact ^developer](http://reddit.com/user/WinneonSword)' ) utils.handle_rate_limit(submission, reply) print('> Comment posted! Link: ' + upload) utils.replied.add(submission.id) listt = list(utils.replied) replied_current['replied'] = listt config.write(replied_current, utils.replied_file) except: print('> Failed to post comment.') traceback.print_exc(file = sys.stdout) print('\n> Sleeping.') time.sleep(15) except KeyboardInterrupt: print('> Stopped makeswordclouds. Thank you for running this bot!') except: print('\n> An error has occured. Restarting the bot.') traceback.print_exc(file = sys.stdout) loop(user, reddit, utils)
def show(subreddit): """Show media of the given subreddit.""" try: userlinks = get_subreddit(subreddit).get_hot() media_list = _get_media(userlinks) _add_media_to_dir(media_list) except InvalidSubreddit: pass except IsUnreachable: Dialog().ok(_('Information'), _('Reddit is unreachable.\n' 'Please check your internet connection.')) finally: directory.end(cache_to_disk=True)
def loop(user, reddit, utils): print('\n> Booting up makeswordclouds. You will be notified when makeswordclouds detects a broken link.') print('> To stop the bot, press Ctrl + C.') try: while True: print('\n> Checking submissions for valid entries...') submissions = reddit.get_subreddit('all').get_hot(limit = 100) for submission in submissions: sub = submission.subreddit.display_name.lower() if submission.id not in utils.replied and submission.num_comments >= int(utils.config['limit']) and sub not in utils.banned: print('\n> Found valid submission in the subreddit /r/' + submission.subreddit.display_name + '!') text = utils.get_submission_comments(submission.id) cloud = utils.make_cloud(text) upload = utils.upload_image(cloud) print('> Successfully made word cloud and uploaded to imgur!') os.remove(cloud) try: reply = ( 'Here is a word cloud of all of the comments in this thread: ' + upload + '\n\n' '*****\n' '[^source ^code](https://github.com/WinneonSword/makeswordclouds) ^| [^contact ^developer](http://reddit.com/user/WinneonSword)' ) utils.handle_rate_limit(submission, reply) print('> Comment posted! Link: ' + upload) except HTTPError, e: print('\n> An HTTP error occured trying to post the comment.') print('> Response: %s' % e.response) if "403" in str(e.response): utils.add_banned_subreddit(sub) print('> Added the subreddit %s to the banned list!' % sub) except:
def _add_subreddit(name): """Add given subreddit to the user's preference list. Raise InvalidSubreddit when it does not exist on Reddit. Raise IsUnreachable when Reddit is unreachable. """ try: subreddit = get_subreddit(name) except InvalidSubreddit: raise except IsUnreachable: raise subreddits = settings['subreddits'] subreddits[name] = subreddit.title settings['subreddits'] = subreddits
def tweet(api): img_valid = True subreddit_value = reddit.get_subreddit() reddit.get_post(subreddit_value) title, url, image_url = reddit.get_post(subreddit_value) print(title) print(url) print(image_url) try: urllib.request.urlretrieve(image_url, "img.jpg") except: img_valid = False if img_valid: api.update_with_media( "img.jpg", "Top post from r/" + subreddit_value.display_name + "\n" + url + "\n\n" + title) else: api.update_status("Top post from r/" + subreddit_value + "\n" + url + "\n\n" + title)
import leaderboard import parser import qa SUBREDDIT = 'bikeLA' PHOTOTAG_WIKI = 'phototag' RESOURCE_DIR = './resources' OVERRIDE_FILES = ['conflicting_tags.json', 'missing_tags.json'] DEFAULT_START_TAG = 1 if __name__ == '__main__': parser = parser.parser() args = parser.parse_args() subreddit = reddit.get_subreddit(SUBREDDIT) if args.use_wiki: current_leaderboard_tags = leaderboard.read_existing_leaderboard_tags(subreddit, PHOTOTAG_WIKI) start_tag = leaderboard.last_leaderboard_tag(current_leaderboard_tags) else: current_leaderboard_tags = {} start_tag = DEFAULT_START_TAG manual_override_tags = bike_tags.read_manual_override_tags(RESOURCE_DIR, OVERRIDE_FILES) new_tags = bike_tags.get_tags(start_tag, args.current_tag, subreddit, manual_override_tags) all_tags = bike_tags.combine_tags(current_leaderboard_tags, new_tags) updated_leaderboard = leaderboard.leaderboard(all_tags) leaderboard.print_new_leaderboard(updated_leaderboard, args.n_leaderboard) leaderboard.print_found_tags(all_tags)
from datetime import datetime import logging import pytz import re import reddit import solr logging.basicConfig(filename='logs/gather.log', level=logging.INFO) solr = solr.SolrConnection('http://localhost:8983/solr') reddit = reddit.Reddit(user_agent='occupymanifesto') subreddit = reddit.get_subreddit('occupymanifesto') nodes = [] for item in subreddit.get_hot(limit=None): logging.info('Processing {%s}' % item) # Only process submissions which have a valid noun-phrase type type = None matches = re.match('(.*):', item.title) if not matches: logging.info('Skipping {%s} since it has no noun-phrase type specified' % item) continue # Only text submissions are currently considered for visualization if not item.__dict__.has_key('selftext'): logging.info('Skipping {%s} since it does not contain a selftext field' % item) continue