Browse Source

Adding quick edits to the top.

master
Michael Tan 6 years ago
parent
commit
008bbb2067
Signed by: mike
GPG Key ID: EFBDC90BE2BF394F
  1. 19
      linkmakerbot.py

19
linkmakerbot.py

@ -5,6 +5,11 @@ import re
import os import os
import time import time
LINK_URL="xkcd.com"
SUBREDDIT_NAME="xkcd"
SEARCH_STRING=r"xkcd\d+"
DEBUG=1
def check_for_string(searchString,comment): def check_for_string(searchString,comment):
temp = re.findall(searchString, comment, flags=re.IGNORECASE) temp = re.findall(searchString, comment, flags=re.IGNORECASE)
res = list(temp) res = list(temp)
@ -40,15 +45,17 @@ else:
posts_replied_to = list(filter(None, posts_replied_to)) posts_replied_to = list(filter(None, posts_replied_to))
# Get the top 5 values from our subreddit # Get the top 5 values from our subreddit
subreddit = reddit.subreddit('pythonforengineers') subreddit = reddit.subreddit(SUBREDDIT_NAME)
for submission in subreddit.hot(limit=5): for submission in subreddit.hot(limit=5):
#time.sleep(2) #time.sleep(2)
# If we haven't replied to this post before # If we haven't replied to this post before
if submission.id not in posts_replied_to: if submission.id not in posts_replied_to:
# Do a case insensitive search # Do a case insensitive search
myreply = check_for_string(r'xkcd \d+',submission.title) myreply = check_for_string(SEARCH_STRING,submission.title)
if myreply: if myreply:
#print(myreply) if DEBUG:
print(myreply)
else:
# Reply to the post # Reply to the post
submission.reply(myreply) submission.reply(myreply)
tempMessage="Bot replying to: %s with ID: %s" %(submission.title,submission.id) tempMessage="Bot replying to: %s with ID: %s" %(submission.title,submission.id)
@ -61,9 +68,11 @@ for submission in subreddit.hot(limit=5):
#time.sleep(2) #time.sleep(2)
if thisComment.id not in posts_replied_to: if thisComment.id not in posts_replied_to:
myreply = check_for_string(r'xkcd \d+',thisComment.body) myreply = check_for_string(SEARCH_STRING,thisComment.body)
if myreply: if myreply:
#print(myreply) if DEBUG:
print(myreply)
else:
# Reply to the comment # Reply to the comment
thisComment.reply(myreply) thisComment.reply(myreply)
tempMessage="Bot replying to a comment in: %s with ID: %s" %(submission.title,thisComment.id) tempMessage="Bot replying to a comment in: %s with ID: %s" %(submission.title,thisComment.id)

Loading…
Cancel
Save