This repository has been archived by the owner on Apr 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gb-bb.py
56 lines (53 loc) · 1.92 KB
/
gb-bb.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
55
56
import praw
import prawcore
from modules.logger import setup_logger
from modules.login import reddit
import logging
from modules.footer import footer
logger = setup_logger('good_bot_bad_bot')
def main():
try:
for item in reddit.inbox.stream():
try:
written_to = 0
text = ''
with open('comments_written_to.txt', 'r') as file:
for line in file.readlines():
if line == str(item) and written_to == 0:
written_to = 1
logging.info('Comment {} has been already replied to.'.format(str(item)))
if written_to == 0:
if 'good bot' in str(item.body.lower()):
text = 'Good human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'bad bot' in str(item.body.lower()):
text = 'Bad human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'average bot' in str(item.body.lower()):
text = 'Average human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
except(prawcore.exceptions.Forbidden):
logging.info('Blocked on /r/{}'.format(str(item.subreddit)))
except(KeyboardInterrupt):
raise KeyboardInterrupt
except Exception as e:
logging.error('Error on item {}. {}'.format(str(item),str(e)), exc_info=True)
except(KeyboardInterrupt):
raise KeyboardInterrupt
except Exception as e:
logging.critical('Error on main loop! {}'.format(str(e)), exc_info=True)
if __name__ == '__main__':
while True:
try:
main()
except(KeyboardInterrupt):
raise KeyboardInterrupt