From 294f02cb7ba89d42d3cfdc6dc6535f6b346d874f Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Fri, 8 Sep 2017 16:11:35 +0000 Subject: [PATCH] Added blacklist --- main.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 45e9b4a..88b14d7 100755 --- a/main.py +++ b/main.py @@ -9,23 +9,29 @@ reddit = praw.Reddit('DEFAULT') rall = reddit.subreddit('all') sub = reddit.subreddit('IsAnybodyHere') +# Blacklist (by mod request) +blacklist = {'test','neoliberal'} + print("Started IsAnybodyHereBot...") # Search latest comments in r/all for comment in rall.stream.comments(): - # Match with regex - match = re.search("(does|has|is)(n't)? (any one|anyone|someone|anybody) (here)? (.*?)\?", comment.body, re.IGNORECASE) - if match: + # Check for blacklist + if comment.subreddit.display_name.lower() not in blacklist: - # Extract a description of the needed person - needed = match.group(3) + ' who ' + match.group(1) + ' ' + match.group(5) - print(match.group(),'\n',needed.title(),'\n') - - # Post to our sub - try: - post = sub.submit(needed.title(), url='https://www.reddit.com'+comment.permalink(), resubmit=False) - except: - print("Failed to post to our sub"); raise - else: - print("Posted to sub:",post.shortlink) + # Match with regex + match = re.search("(does|has|is)(n't)? (any one|anyone|someone|anybody) (here)? (.*?)\?", comment.body, re.IGNORECASE) + if match: + + # Extract a description of the needed person + needed = match.group(3) + ' who ' + match.group(1) + ' ' + match.group(5) + print(match.group(),'\n',needed.title(),'\n') + + # Post to our sub + try: + post = sub.submit(needed.title(), url='https://www.reddit.com'+comment.permalink(), resubmit=False) + except: + print("Failed to post to our sub"); raise + else: + print("Posted to sub:",post.shortlink)