Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
PRAW: make bot skip over submissions where it already left a comment
Post Flair (click to view more posts with a particular flair)
Post Body

I am trying to write a reddit bot that does the following:

  1. visits a specified subreddit
  2. checks submission titles for a specified keyword
  3. posts a randomized comment to submissions with the keyword in the title
    1. skips over submissions in which it has already commented

Steps 1-3 work but I'm stuck on step 4.

My code:

imports
import praw
import random

setup reddit login
userAgent = my_agent
cID = my_cID
cSC= my_cSC
userN = my_userN
userP = my_userP

reddit = praw.Reddit (user_agent=userAgent, client_id=cID, client_secret=cSC, username=userN, password=userP)

visits specified subreddit
subreddit = reddit.subreddit(TEST_SUBREDDIT)

list of random comments text_stubs = ['COMMENT 1','COMMENT 2','COMMENT 3']

blank list to store submissions IDs where bot has left a comment
skip = []

counter to track progress through submissions in the subreddit
numFound = 0
for submission in subreddit.hot(limit=25): look through submissons in the subreddit
n_title = submission.title.lower() regularize title case
if submission.id not in skip: check submission against the skip list
if 'KEYWORD' in n_title: check for keyword
numFound = numFound 1 advance the counter
rand_comment = random.randint(1, len(text_stubs) - 1) pick a random comment
bot_phrase = str(text_stubs[rand_comment]) comment on the submission
skip.append(submission.id) add the submission ID to the skip list so bot won't comment on the same post twice

When I run the code in a test subreddit, it posts a comment correctly. When I rerun the code again, it will post again on a submission where it already left a comment. I don't want it to do that. Any thoughts?

Author
Account Strength
60%
Account Age
4 years
Verified Email
No
Verified Flair
No
Total Karma
4,338
Link Karma
1,173
Comment Karma
3,110
Profile updated: 5 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago