Added blacklist
parent
25e9ee5222
commit
294f02cb7b
34
main.py
34
main.py
|
@ -9,23 +9,29 @@ reddit = praw.Reddit('DEFAULT')
|
||||||
rall = reddit.subreddit('all')
|
rall = reddit.subreddit('all')
|
||||||
sub = reddit.subreddit('IsAnybodyHere')
|
sub = reddit.subreddit('IsAnybodyHere')
|
||||||
|
|
||||||
|
# Blacklist (by mod request)
|
||||||
|
blacklist = {'test','neoliberal'}
|
||||||
|
|
||||||
print("Started IsAnybodyHereBot...")
|
print("Started IsAnybodyHereBot...")
|
||||||
|
|
||||||
# Search latest comments in r/all
|
# Search latest comments in r/all
|
||||||
for comment in rall.stream.comments():
|
for comment in rall.stream.comments():
|
||||||
|
|
||||||
# Match with regex
|
# Check for blacklist
|
||||||
match = re.search("(does|has|is)(n't)? (any one|anyone|someone|anybody) (here)? (.*?)\?", comment.body, re.IGNORECASE)
|
if comment.subreddit.display_name.lower() not in blacklist:
|
||||||
if match:
|
|
||||||
|
|
||||||
# Extract a description of the needed person
|
# Match with regex
|
||||||
needed = match.group(3) + ' who ' + match.group(1) + ' ' + match.group(5)
|
match = re.search("(does|has|is)(n't)? (any one|anyone|someone|anybody) (here)? (.*?)\?", comment.body, re.IGNORECASE)
|
||||||
print(match.group(),'\n',needed.title(),'\n')
|
if match:
|
||||||
|
|
||||||
# Post to our sub
|
# Extract a description of the needed person
|
||||||
try:
|
needed = match.group(3) + ' who ' + match.group(1) + ' ' + match.group(5)
|
||||||
post = sub.submit(needed.title(), url='https://www.reddit.com'+comment.permalink(), resubmit=False)
|
print(match.group(),'\n',needed.title(),'\n')
|
||||||
except:
|
|
||||||
print("Failed to post to our sub"); raise
|
# Post to our sub
|
||||||
else:
|
try:
|
||||||
print("Posted to sub:",post.shortlink)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue