Filter out False comments

This commit is contained in:
2019-08-30 06:23:14 +00:00
parent 20a9d9d452
commit 2ede5ed6ff
3 changed files with 36 additions and 23 deletions

View File

@@ -22,22 +22,21 @@ reddit = praw.Reddit('bot')
def feed():
return [x.id for x in reddit.subreddit(SUBREDDITS).hot()]
def good_comment(c):
if isinstance(c, MoreComments):
return False
if c.body == '[removed]':
return False
if c.author and c.author.name == 'AutoModerator':
return False
return True
def comment(i):
if isinstance(i, MoreComments):
return False
if '[removed]' in i.body or '[deleted]' in i.body:
return False
if i.author and i.author.name == 'AutoModerator':
return False
c = {}
c['author'] = i.author.name if i.author else '[Deleted]'
c['score'] = i.score
c['date'] = i.created_utc
c['text'] = render_md(i.body)
c['comments'] = [comment(j) for j in i.replies if good_comment(j)]
c['comments'] = [comment(j) for j in i.replies]
c['comments'] = list(filter(bool, c['comments']))
return c
def story(ref):
@@ -52,7 +51,8 @@ def story(ref):
s['title'] = r.title
s['link'] = SITE_LINK(r.permalink)
s['url'] = r.url
s['comments'] = [comment(i) for i in r.comments if good_comment(i)]
s['comments'] = [comment(i) for i in r.comments]
s['comments'] = list(filter(bool, s['comments']))
s['num_comments'] = r.num_comments
if r.selftext: