From a4d531b4e7f087acc1befdcaa33efebe6441aa36 Mon Sep 17 00:00:00 2001 From: Shawn Hind Date: Wed, 11 Mar 2015 16:54:18 -0400 Subject: [PATCH 1/2] Added functionality for flairs #28 --- rtv/content.py | 10 ++++++++++ rtv/submission.py | 4 +++- rtv/subreddit.py | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rtv/content.py b/rtv/content.py index 48e321d..44d1356 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -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): diff --git a/rtv/submission.py b/rtv/submission.py index c23e637..67c33e5 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -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]) diff --git a/rtv/subreddit.py b/rtv/subreddit.py index e81e5c0..1fa18f7 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -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) From 34dfa53b9f4f05a8afd051eda55dc4c79371b6dc Mon Sep 17 00:00:00 2001 From: Shawn Hind Date: Thu, 12 Mar 2015 17:42:26 -0400 Subject: [PATCH 2/2] Fixed suggested changes for pull request, changed colour of flairs to yellow for more visibility on submission page --- rtv/content.py | 10 ++-------- rtv/submission.py | 8 +++++--- rtv/subreddit.py | 5 ++--- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/rtv/content.py b/rtv/content.py index 44d1356..bcbb58f 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -141,10 +141,7 @@ 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'] = "" + data['flair'] = (clean(comment.author_flair_text) if comment.author_flair_text else "") return data @@ -170,10 +167,7 @@ class BaseContent(object): 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['flair'] = (clean(sub.link_flair_text) if sub.link_flair_text else "") data['url_full'] = clean(sub.url) data['url'] = ('selfpost' if is_selfpost(sub.url) else clean(sub.url)) diff --git a/rtv/submission.py b/rtv/submission.py index 67c33e5..f56766a 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -107,10 +107,12 @@ class SubmissionPage(BasePage): row = offset if row in valid_rows: - text = '{author} {flair}'.format(**data) + text = '{author}'.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) + text = ' {flair}'.format(**data) + win.addnstr(text, n_cols-win.getyx()[1], curses.A_BOLD | Color.YELLOW) text = ' {score} {created}'.format(**data) win.addnstr(text, n_cols - win.getyx()[1]) @@ -171,8 +173,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 = ' {flair}'.format(**data) + win.addnstr(text, n_cols-win.getyx()[1], curses.A_BOLD | Color.YELLOW) text = ' {created} {subreddit}'.format(**data) win.addnstr(text, n_cols - win.getyx()[1]) diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 1fa18f7..989a727 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -135,8 +135,7 @@ 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 = ' {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)