Better handling of missing content attributes.
This commit is contained in:
@@ -77,16 +77,19 @@ class BaseContent(object):
|
|||||||
data['count'] = comment.count
|
data['count'] = comment.count
|
||||||
data['body'] = 'More comments'.format(comment.count)
|
data['body'] = 'More comments'.format(comment.count)
|
||||||
else:
|
else:
|
||||||
|
author = getattr(comment, 'author', '[deleted]')
|
||||||
|
name = getattr(author, 'name', '[deleted]')
|
||||||
|
sub = getattr(comment, 'submission', '[deleted]')
|
||||||
|
sub_author = getattr(sub, 'author', '[deleted]')
|
||||||
|
sub_name = getattr(sub_author, 'name', '[deleted]')
|
||||||
|
flair = getattr(comment, 'author_flair_text', '')
|
||||||
data['type'] = 'Comment'
|
data['type'] = 'Comment'
|
||||||
data['body'] = comment.body
|
data['body'] = comment.body
|
||||||
data['created'] = humanize_timestamp(comment.created_utc)
|
data['created'] = humanize_timestamp(comment.created_utc)
|
||||||
data['score'] = '{} pts'.format(comment.score)
|
data['score'] = '{} pts'.format(comment.score)
|
||||||
author = getattr(comment, 'author')
|
data['author'] = name
|
||||||
data['author'] = (author.name if author else '[deleted]')
|
data['is_author'] = (name == sub_name)
|
||||||
sub_author = getattr(comment.submission.author, 'name')
|
data['flair'] = flair
|
||||||
data['is_author'] = (data['author'] == sub_author)
|
|
||||||
flair = comment.author_flair_text
|
|
||||||
data['flair'] = (flair if flair else '')
|
|
||||||
data['likes'] = comment.likes
|
data['likes'] = comment.likes
|
||||||
data['gold'] = comment.gilded > 0
|
data['gold'] = comment.gilded > 0
|
||||||
|
|
||||||
@@ -100,6 +103,9 @@ class BaseContent(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
is_selfpost = lambda s: s.startswith('http://www.reddit.com/r/')
|
is_selfpost = lambda s: s.startswith('http://www.reddit.com/r/')
|
||||||
|
author = getattr(sub, 'author', '[deleted]')
|
||||||
|
name = getattr(author, 'name', '[deleted]')
|
||||||
|
flair = getattr(sub, 'link_flair_text', '')
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
data['object'] = sub
|
data['object'] = sub
|
||||||
@@ -109,11 +115,10 @@ class BaseContent(object):
|
|||||||
data['created'] = humanize_timestamp(sub.created_utc)
|
data['created'] = humanize_timestamp(sub.created_utc)
|
||||||
data['comments'] = '{} comments'.format(sub.num_comments)
|
data['comments'] = '{} comments'.format(sub.num_comments)
|
||||||
data['score'] = '{} pts'.format(sub.score)
|
data['score'] = '{} pts'.format(sub.score)
|
||||||
author = getattr(sub, 'author')
|
data['author'] = name
|
||||||
data['author'] = (author.name if author else '[deleted]')
|
|
||||||
data['permalink'] = sub.permalink
|
data['permalink'] = sub.permalink
|
||||||
data['subreddit'] = strip_subreddit_url(sub.permalink)
|
data['subreddit'] = strip_subreddit_url(sub.permalink)
|
||||||
data['flair'] = (sub.link_flair_text if sub.link_flair_text else '')
|
data['flair'] = flair
|
||||||
data['url_full'] = sub.url
|
data['url_full'] = sub.url
|
||||||
data['url'] = ('selfpost' if is_selfpost(sub.url) else sub.url)
|
data['url'] = ('selfpost' if is_selfpost(sub.url) else sub.url)
|
||||||
data['likes'] = sub.likes
|
data['likes'] = sub.likes
|
||||||
|
|||||||
Reference in New Issue
Block a user