Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import pdb
- import re
- import os
- reddit=praw.Reddit(client_id='',
- client_secret='',
- username='',
- password='',
- user_agent='')
- if not os.path.isfile("posts_replie_to.txt"):
- posts_replie_to = []
- else:
- with open("posts_replie_to.txt", "r") as f:
- posts_replie_to = f.read()
- posts_replie_to = posts_replie_to.split("\n")
- posts_replie_to = list(filter(None, posts_replie_to))
- if not os.path.isfile("posts_repli_to.txt"):
- posts_repli_to = []
- else:
- with open("posts_repli_to.txt", "r") as f:
- posts_repli_to = f.read()
- posts_repli_to = posts_repli_to.split("\n")
- posts_repli_to = list(filter(None, posts_repli_to))
- subreddit = reddit.subreddit('subreddit you like')
- comments = subreddit.stream.comments()
- for comment in comments:
- author=comment.author
- if comment.id not in posts_replie_to:
- posts_replie_to.append(comment.id)
- with open("posts_replie_to.txt", "w") as f:
- for comment_id in posts_replie_to:
- f.write(comment_id + "\n")
- #if you want the bot to trigger on more words copy this below and put in a new word
- if re.search("fill in word if it finds the word it replies.", comment.body, re.IGNORECASE):
- if author.name in posts_repli_to:
- print "you have already commented on %s" % comment.author
- if author.name not in posts_repli_to:
- print("Bot replying to : ", comment.body)
- posts_repli_to.append(author.name)
- message=("Hello /u/%s! I'm a bot. Bleepy bloop. ") % author.name
- comment.reply(message)
- with open("posts_repli_to.txt", "w") as f:
- for author.name in posts_repli_to:
- f.write(author.name + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement