-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbanned_reply.py
executable file
·34 lines (29 loc) · 1.04 KB
/
banned_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
31
32
33
34
#!/usr/bin/env python
import praw
from prawcore import exceptions
import re
import os
import time
import pprint
with open('banned_reply_text', 'r') as f:
banned_reply_text = f.read().rstrip()
with open('banned_with_note_reply_text', 'r') as f:
banned_with_note_reply_text = f.read().rstrip()
reddit = praw.Reddit('JustNoSinclair')
for message in reddit.inbox.messages(limit=None):
# ~ print(message.parent_id)
try:
banned_yn = re.search('banned .*r/(\w+)', message.subject)
if message.parent_id is None and not message.replies and banned_yn:
reddit.subreddit(banned_yn.group(1)).unsubscribe
if re.search('Note from the moderators', message.body):
print("Thank you reply")
message.reply(banned_with_note_reply_text)
else:
print("Question reply")
message.reply(banned_reply_text)
elif not message.replies and banned_yn:
print(message.body)
except Exception as e:
print(type(e))
print(e)