How to use the praw.helpers.flatten_tree function in praw

To help you get started, we’ve selected a few praw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github natehak / most-common-words / commentbot / reddit_mcw.py View on Github external
def get_top_words(link, top=5):
	# Get the submission...
	submission = r.get_submission(link)
	
	# We need to go deeper...
	submission.replace_more_comments()
	comments = praw.helpers.flatten_tree(submission.comments)
	
	wordcount = {}
	
	# Loop through the comments, split it up into words and count them up
	for comment in comments:
		
		words = comment.body.split()
		
		for word in words:
			word = word.lower()
			word = ''.join(e for e in word if e.isalnum())
			if not word in commonwords:
				if word in wordcount:
					wordcount[word] += 1
				else:
					wordcount[word] = 1
github CharlieIO / csgoteambot / csgobot.py View on Github external
talready_done = []
    palready_done = []
    forbidden = '+%\\*;[]{}:"'  # forbidden characters
    forbidden2 = 'DROP'  # forbidden keyword
    while True:
        conn = psycopg2.connect(
            database=url.path[1:],
            user=url.username,
            password=url.password,
            host=url.hostname,
            port=url.port
        )
        cur = conn.cursor()
        subreddit = r.get_subreddit('globaloffensive')
        comments = subreddit.get_comments()
        flat_comments = praw.helpers.flatten_tree(comments)
        for comment in flat_comments:  # all the comments posted in the subreddit
            comment_reply = ""  # will append to this later
            print comment
            tcall_count, pcall_count = get_count(comment)
            if comment.id not in talready_done:  # talready_done is a list of comment id's where I have already
                for instance in range(tcall_count):
                    team = get_team(comment.body, instance)
                    statfill = '\n\n**Wins:** %s' + ' \n\n**Draws:** %s' + ' \n\n**Losses:** %s' + \
                        ' \n\n**Rounds Played:**  %s '  # layout for commenting
                    if team != '!roster' and team != '!team' and any(
                            (c in forbidden) for c in team) == False and forbidden2 not in team.upper():
                        stats = []
                        try:
                            stats = []
                            if team.upper() == 'VP':
                                # single common case exception
github thundergolfer-old / mAIcroft / most_used_words.py View on Github external
"""Parse a submission's text and body (if applicable).

    :param count_word_freqs: if False, only count a word once per text block
        (title, selftext, comment body) rather than incrementing the total for
        for each instance.

    :param max_threshold: maximum relative frequency in the text a word can
        appear to be considered in word counts. prevents word spamming in a
        single submission.

    :param include_comments: include the submission's comments when True

    """
    if include_comments:  # parse all the comments for the submission
        submission.replace_more_comments()
        for comment in praw.helpers.flatten_tree(submission.comments):
            parse_text(text=comment.body, count_word_freqs=count_word_freqs,
                       max_threshold=max_threshold)

    # parse the title of the submission
    parse_text(text=submission.title, count_word_freqs=count_word_freqs,
               max_threshold=max_threshold, is_markdown=False)

    # parse the selftext of the submission (if applicable)
    if submission.is_self:
        parse_text(text=submission.selftext, count_word_freqs=count_word_freqs,
                   max_threshold=max_threshold)
github atiaxi / chromabot / chromabot / main.py View on Github external
def recruit_from_post(self, post):
        post.replace_more_comments(threshold=0)
        flat_comments = praw.helpers.flatten_tree(post.comments)
        for comment in flat_comments:
            self.recruit_from_comment(comment)