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.
I am trying to write a reddit bot that does the following:
- visits a specified subreddit
- checks submission titles for a specified keyword
- posts a randomized comment to submissions with the keyword in the title
- 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?
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/redditdev/c...