Search code examples
apiredditjredditreddit-access-tokenredditkit

Using the Reddit API, is it possible to return a list of comments if the submission title includes a specific keyword?


Using the Reddit API, is it possible to return a list of Reddit comments if the submission title includes a specific keyword? For example, if the keyword is "Lime Sparkling Water", I want to return all the comments under submissions that have "Lime Sparkline Water" in the title.

I've tried using the Pushshift API for Reddit but looks like we can only isolate the submission data or the comment data and not isolate the comments data based on the submissions data.

Please help :)


Solution

  • Yes, this is possible with PRAW.

    You can use PRAW's stream function, that page also has examples how to use PRAW.

    An example being:

    subreddit = reddit.subreddit("AskReddit")
    for submission in subreddit.stream.submissions():
        # do something with submission
        ...
    

    This will return all submissions within "AskReddit". From there you could check the post title:

    if 'Lime Sparking Water' in submission:
        # do something with the submission
    

    Although, I know this is a hypothetical phrase to search, you'd be better off searching lowercase phrases/words and .lower()