-
Notifications
You must be signed in to change notification settings - Fork 0
/
michael_scott_bot.py
54 lines (44 loc) · 1.45 KB
/
michael_scott_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import praw
import os
from match_comment import get_quote
import time
def authenticate():
print("Authenticating...")
reddit = praw.Reddit(
"michaelscottbot",
user_agent="michael scott bot v0.1")
print("Authenticated as {}".format(reddit.user.me()))
return reddit
def main():
reddit = authenticate()
idlist = get_saved_comments()
while True:
bot_run(reddit, idlist)
time.sleep(600)
def bot_run(reddit, idlist):
print("Scanning for comments...")
for comment in reddit.subreddit('DunderMifflin').comments(limit=50):
if comment.id not in idlist and comment.author != reddit.user.me():
quote = get_quote(comment.body)
if quote == None:
return
print("Keyword found!")
rep = ">" + quote
rep += "\n\n\n - Michael Scott"
rep += "\n\n Hi I'm just a bot, bip bop. Thank you for noticing me!"
comment.reply(rep)
print("Repplied to comment: " + comment.id)
idlist.append(comment.id)
with open("idlist.txt", "a") as f:
f.write(comment.id + "\n")
def get_saved_comments():
if not os.path.isfile("idlist.txt"):
idlist = []
else:
with open("idlist.txt", "r") as f:
idlist = f.read()
idlist = idlist.split("\n")
idlist = list(filter(None, idlist))
return idlist
if __name__ == "__main__":
main()