
Usage example: python comments.py getmotivated import praw import sys import argparse def parse(): print('parsing arguments and options.') parser = argparse.ArgumentParser(description="Get the comments of a subreddit") parser.add_argument('subreddit', type=str, help='name of subreddit') return parser.parse_args() def gather(subreddit): print('searching subreddit for key phrase.') relevant_strings = print('gathering texts for analysis.') try: for submission in subreddit.hot(limit=10): print('.') if lftext: relevant_strings.append(str(lftext)) for comment in (): if isinstance(comment, ): continue relevant_strings.append(str(comment.body)) if len(relevant_strings) = 0: raise Exception return relevant_strings except: sys.exit('ERROR: No posts were found for the provided subreddit and key phrase.') args = parse() subreddit_str = args.subreddit print('establishing reddit instance.') try: reddit = praw.Reddit("bot") except: sys.exit('ERROR: Failed to establish a reddit instance. Make sure to modify the output path of this script before running. See here for help with creating a Reddit App and here for help with praw. The script requires praw and a praw.ini file in the project's root named bot with the following Reddit App parameters: client_id, client_secret, and user_agent. The purpose of the Python script is to connect to Reddit and dump the comments of a subreddit into a JSON file. They are famous among redditors for being hotspots for insecure individuals and often host some of the lowest-quality discussions in the platform.

