From 0d7dcc8f33d790e2c6e9673b838ba2dbb48dcf0a Mon Sep 17 00:00:00 2001 From: tobywhughes Date: Mon, 2 Mar 2015 14:50:12 -0800 Subject: [PATCH 1/3] Added /top and /new functionality --- rtv/content.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/rtv/content.py b/rtv/content.py index 824f2b5..e718e5d 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -298,26 +298,47 @@ class SubredditContent(BaseContent): @classmethod def from_name(cls, reddit, name, loader=default_loader): + + display_type = 'normal' if name == 'front': return cls('Front Page', reddit.get_front_page(limit=None), loader) if name == 'all': sub = reddit.get_subreddit(name) - + else: + + if '/' in name: + parse = name.split('/') + name = parse[0] + + if parse[1] == 'top': + display_type = 'top' + + elif parse[1] == 'new': + display_type = 'new' + try: with loader(): sub = reddit.get_subreddit(name, fetch=True) except praw.errors.ClientException: raise SubredditNameError(name) + + if display_type == 'top': + return cls('/r/'+sub.display_name, sub.get_top_from_all(limit=None), loader) - return cls('/r/'+sub.display_name, sub.get_hot(limit=None), loader) + elif display_type == 'new': + return cls('/r/'+sub.display_name, sub.get_new(limit=None), loader) + + else: + return cls('/r/'+sub.display_name, sub.get_hot(limit=None), loader) def get(self, index, n_cols=70): """ Grab the `i`th submission, with the title field formatted to fit inside of a window of width `n` + """ if index < 0: @@ -340,4 +361,4 @@ class SubredditContent(BaseContent): data['n_rows'] = len(data['split_title']) + 3 data['offset'] = 0 - return data \ No newline at end of file + return data From 98dc5a3ae7bab59116f07e81c2f9a76bf724545d Mon Sep 17 00:00:00 2001 From: tobywhughes Date: Mon, 2 Mar 2015 15:01:35 -0800 Subject: [PATCH 2/3] /top and /new functionality added --- rtv/content.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rtv/content.py b/rtv/content.py index e718e5d..cbbeb9f 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -338,7 +338,6 @@ class SubredditContent(BaseContent): """ Grab the `i`th submission, with the title field formatted to fit inside of a window of width `n` - """ if index < 0: From 98fc02e28e0147509ddfe4e601a97859a0e47cfc Mon Sep 17 00:00:00 2001 From: tobywhughes Date: Mon, 2 Mar 2015 16:00:08 -0800 Subject: [PATCH 3/3] Removed parse and added more descriptive taglines --- rtv/content.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/rtv/content.py b/rtv/content.py index cbbeb9f..4092163 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -310,14 +310,7 @@ class SubredditContent(BaseContent): else: if '/' in name: - parse = name.split('/') - name = parse[0] - - if parse[1] == 'top': - display_type = 'top' - - elif parse[1] == 'new': - display_type = 'new' + name, display_type = name.split('/') try: with loader(): @@ -326,10 +319,10 @@ class SubredditContent(BaseContent): raise SubredditNameError(name) if display_type == 'top': - return cls('/r/'+sub.display_name, sub.get_top_from_all(limit=None), loader) + return cls('/r/'+sub.display_name + '/top', sub.get_top_from_all(limit=None), loader) elif display_type == 'new': - return cls('/r/'+sub.display_name, sub.get_new(limit=None), loader) + return cls('/r/'+sub.display_name + '/new', sub.get_new(limit=None), loader) else: return cls('/r/'+sub.display_name, sub.get_hot(limit=None), loader)