-
Notifications
You must be signed in to change notification settings - Fork 0
/
dont_call_it_cali_bot.py
52 lines (44 loc) · 1.92 KB
/
dont_call_it_cali_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
import praw
import re
import sys
import datetime
import time
from time import sleep
from praw.helpers import comment_stream
def handle_ratelimit(func, *args, **kwargs):
while True:
try:
func(*args, **kwargs)
break
except praw.errors.RateLimitExceeded as error:
print '\tRate limit exceeded! Sleeping for %d seconds starting at %s' % (error.sleep_time, datetime.datetime.now())
time.sleep(error.sleep_time)
except praw.errors.APIException, e:
print "[praw.errors.APIException]:", e
break
except requests.exceptions.HTTPError, e:
print "[requests.exceptions.HTTPError]:", e
break
def main():
r = praw.Reddit("any platform/1.0 (by /u/dont_call_it_cali)")
r.login("dont_call_it_cali", "*******")
target_text = r"^.*\bcali\b.*$"
response_text = r'''http://i.imgur.com/sdrbmHj.jpeg
The name of the state is California.'''
blacklist = ['CoDCompetitive', 'MMA', 'OpTicGaming', 'SuicideWatch', 'Colombia', 'leagueoflegends']
processed = []
while True:
for c in comment_stream(r, 'all'):
if re.match(target_text, c.body, re.IGNORECASE):
if c.link_id not in processed:
if c.subreddit.display_name in blacklist:
# subreddit is on the black list, skip replying to it
print "skipping comment because subreddit", c.subreddit.display_name, "is in blacklist..."
continue
handle_ratelimit(c.reply, response_text)
processed.append(c.link_id)
print "replied to", c.author.name, "in", c.link_url, "at", datetime.datetime.now()
else:
print "skipping because we already replied in this thread:", c.link_id, c.link_url, "at", datetime.datetime.now()
if __name__ == '__main__':
sys.exit(main())