Skip to content

Instantly share code, notes, and snippets.

@PythonCoderAS
Created December 6, 2016 01:19
Show Gist options
  • Select an option

  • Save PythonCoderAS/fa91e87bb55def930b6a05c60d4b2110 to your computer and use it in GitHub Desktop.

Select an option

Save PythonCoderAS/fa91e87bb55def930b6a05c60d4b2110 to your computer and use it in GitHub Desktop.
import praw
r=praw.Reddit(user_agent="oetuwoiut423oiut34oi2jtn432oijntoiut42oiu/0.1")
user_name='user'
r.login(user_name,'pass',disable_warning=True)
session = r.get_redditor(user_name)
comments = session.get_comments(limit=1000)
nsfw_subreddits_list = []
sfw_subreddits_list = []
def test_sub(subreddit):
if subreddit in nsfw_subreddits_list:
print('Already know it\'s NSFW ('+ subreddit + ')')
return True
if subreddit in sfw_subreddits_list:
print('Already know it\'s SFW ('+ subreddit + ')')
return
newposts = r.get_subreddit(subreddit_name=subreddit).get_new(limit=10)
nsfw = []
for posts in newposts:
nsfw.append(bool(posts.over_18))
stop = False #ugly but simple!
for bools in nsfw:
if bools == False:
stop = True
break
#if any of the posts are sfw, break
if stop == True: #necessary because we have to break two loops
print(subreddit + ' not nsfw')
sfw_subreddits_list.append(subreddit)
return # don't do anything
#ok so if all 10 of them do some housekeeping and return True (meaning the subreddit is definitely nsfw)
nsfw_subreddits_list.append(subreddit)
print(subreddit + " is nsfw")
return True
for comment in comments:
subreddit = str(comment.subreddit)
result = test_sub(subreddit)
if result:
comment.delete()
submitted = session.get_submitted(limit=1000)
for submission in submitted:
subreddit = str(submission.subreddit)
result = test_sub(subreddit)
if result:
submission.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment