-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
67 lines (58 loc) · 2.28 KB
/
common.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
57
58
59
60
61
62
63
64
65
66
67
bot_name = 'YOUR_BOT_NAME'
def get_current_threads(subreddit,limit=200):
bot_threads = []
threads = subreddit.hot(limit=limit)
for thread in threads:
if thread.author == bot_name:
if thread not in bot_threads:
bot_threads.append(thread)
threads = subreddit.new(limit=limit)
for thread in threads:
if thread.author == bot_name:
if thread not in bot_threads:
bot_threads.append(thread)
return bot_threads
def get_unanswered_comments(thread,number=1):
unanswered_authors = []
unanswered_comments = []
if hasattr(thread,'comments'):
for comment in thread.comments:
count = 0
if hasattr(comment, 'replies'):
for reply in comment.replies:
if len(reply.body) > 20:
count += 1
if count <= number and str(comment.banned_by) == 'None' and comment.author not in unanswered_authors:
unanswered_comments.append(comment)
unanswered_authors.append(comment.author)
return unanswered_comments
def get_numbered_helped(comment_replies,author):
number_helped = 0
for reply in comment_replies:
if str(reply.author) == str(author):
number_helped += 1
return number_helped
def get_comment_replies(thread):
comment_replies = []
if hasattr(thread,'comments'):
for comment in thread.comments:
if hasattr(comment, 'replies'):
for reply in comment.replies:
if len(reply.body) > 20:
comment_replies.append(reply)
return comment_replies
def get_num_stickies(subreddit):
stickied = 0
for thread in subreddit.hot(limit=2):
if thread.stickied:
stickied += 1
print('STICKIES', stickied)
return stickied
def remove_yesterday_stickies(subreddit, date, time_zone):
for thread in subreddit.hot(limit=2):
if str(thread.author) == bot_name:
title = str(thread.title)
if 'News and Discussions' in title and date not in title:
thread.mod.sticky(state=False)
if 'Index' in title and (date not in title or time_zone not in title):
thread.mod.sticky(state=False)