Added functionality for flairs #28

This commit is contained in:
Shawn Hind
2015-03-11 16:54:18 -04:00
parent bc9e36f7af
commit a4d531b4e7
3 changed files with 16 additions and 1 deletions

View File

@@ -141,6 +141,10 @@ class BaseContent(object):
sub_author = (clean(comment.submission.author.name) if
getattr(comment.submission, 'author') else '[deleted]')
data['is_author'] = (data['author'] == sub_author)
if comment.author_flair_text != None:
data['flair'] = comment.author_flair_text
else:
data['flair'] = ""
return data
@@ -162,9 +166,14 @@ class BaseContent(object):
data['comments'] = '{} comments'.format(sub.num_comments)
data['score'] = '{} pts'.format(sub.score)
data['author'] = (clean(sub.author.name) if getattr(sub, 'author')
else '[deleted]')
data['permalink'] = clean(sub.permalink)
data['subreddit'] = strip_subreddit_url(sub.permalink)
if sub.link_flair_text != None:
data['flair'] = sub.link_flair_text
else:
data['flair'] = ""
data['url_full'] = clean(sub.url)
data['url'] = ('selfpost' if is_selfpost(sub.url) else clean(sub.url))
@@ -365,6 +374,7 @@ class SubredditContent(BaseContent):
except:
raise SubredditNameError(display_name)
return content
def get(self, index, n_cols=70):

View File

@@ -107,7 +107,7 @@ class SubmissionPage(BasePage):
row = offset
if row in valid_rows:
text = '{author}'.format(**data)
text = '{author} {flair}'.format(**data)
attr = curses.A_BOLD
attr |= (Color.BLUE if not data['is_author'] else Color.GREEN)
win.addnstr(row, 1, text, n_cols-1, attr)
@@ -171,6 +171,8 @@ class SubmissionPage(BasePage):
attr = curses.A_BOLD | Color.GREEN
text = '{author}'.format(**data)
win.addnstr(row, 1, text, n_cols, attr)
text = '{flair}'.format(**data)
win.addnstr(row, 1, text, n_cols, curses.A_BOLD | Color.GREEN)
text = ' {created} {subreddit}'.format(**data)
win.addnstr(text, n_cols - win.getyx()[1])

View File

@@ -135,5 +135,8 @@ class SubredditPage(BasePage):
if row in valid_rows:
text = '{author}'.format(**data)
win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD)
if data['flair'] != None:
text = ' {flair}'.format(**data)
win.addnstr(text, n_cols - 1, curses.A_BOLD | Color.GREEN)
text = ' {subreddit}'.format(**data)
win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW)