pythonpython-3.xpraw

Praw: How to get top posts that were created in last 24 hours?


I want to get top posts of a subreddit but I only get top posts of all time. How to filter the search results so it only looks for today posts?

My code:

top_memes = subreddit.top(limit=5)

for submission in top_memes:
    print(submission.title)

Solution

  • The time_filter parameter for .top() accepts one of the following values: all, day, hour, month, week, year.

    top_memes = subreddit.top("day", limit=5)
    

    https://praw.readthedocs.io/en/latest/code_overview/models/subreddit.html#praw.models.Subreddit.top