-
Notifications
You must be signed in to change notification settings - Fork 0
/
reply.py
32 lines (25 loc) · 953 Bytes
/
reply.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
#!/usr/bin/python
import praw
import pdb
import re
import os
#what are the 3 other imports needed for.
reddit = praw.Reddit('bot1')
subreddit = reddit.subreddit("ulcompsoc")
if not os.path.isfile("posts_replied_to.txt"):
posts_replied_to = []
else:
with open("posts_replied_to.txt") as f:
posts_replied_to = f.read()
posts_replied_to = posts_replied_to.split("\n")
posts_replied_to = list(filter(None, posts_replied_to))
subreddit = reddit.subreddit("ulcompsoc")
for submission in subreddit.hot(limit=2):
if submission.id not in posts_replied_to:
if re.search("compsoc loves python", submission.title, re.IGNORECASE):
submission.reply("Skynet0001 says Hello!")
print("Bot replying to : ", submission.title)
posts_replied_to.append(submission.id)
with open("posts_replied_to.txt", "w") as f:
for post_id in posts_replied_to:
f.write(post_id + "\n")