Search code examples
pythonprawreddit

PRAW: Get limited amount of new comments from submission


I'm attempting to write code to store a variable amount of new comments from a post submission to a file. My code in its current form works, but it always returns the same comments. In other words, I can run it hours apart and the newer comments will not show. I tried following this page and various other sites, and can't find any information on this.

Any help is much appreciated!

post = reddit.submission(url=link)

fileName = "out/" + platform.lower() + ".txt"
file = open(fileName, 'w+')

for top_level_comment in post.comments:
    # Get comment
    try:
        body = top_level_comment.body   
        # Parse each line of comment
        for line in body.splitlines():
            file.write(line + "\n") 
    except:
        continue

Solution

  • The answer was something simple:

    post.comment_sort = 'new'
    

    This was not in the original PRAW comment documentation, but instead found here.