Will
Will

Reputation: 381

Can you use PRAW to find someone's first comment in a subreddit?

It looks like there's no way to get the date a user subscribed to a subreddit through PRAW, but is there a way to get a user's first comment in a particular subreddit?

Upvotes: 1

Views: 469

Answers (1)

Harshith Bolar
Harshith Bolar

Reputation: 826

The only way I can think of doing it is by parsing all his comments and filtering out those comments made on that specific subreddit. You can then sort that list based on comment.created_utc and get the oldest comment.

You can parse all the comments of a user and filter comments from a specific subreddit like so -

user = reddit.redditor('username')
target_subreddit = 'target_subreddit'
comment_list = []
# This iterates over all the comments made by the user
for comment in user.comments.new(limit=None):
    # Check if a comment belongs to your target subreddit
    if str(comment.subreddit) == target_subreddit:
        comment_list.append(comment)

# Sort comment_list based on comment.created_utc to get the oldest comment
...

Upvotes: 2

Related Questions