Added /top and /new functionality
This commit is contained in:
@@ -298,26 +298,47 @@ class SubredditContent(BaseContent):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_name(cls, reddit, name, loader=default_loader):
|
def from_name(cls, reddit, name, loader=default_loader):
|
||||||
|
|
||||||
|
display_type = 'normal'
|
||||||
|
|
||||||
if name == 'front':
|
if name == 'front':
|
||||||
return cls('Front Page', reddit.get_front_page(limit=None), loader)
|
return cls('Front Page', reddit.get_front_page(limit=None), loader)
|
||||||
|
|
||||||
if name == 'all':
|
if name == 'all':
|
||||||
sub = reddit.get_subreddit(name)
|
sub = reddit.get_subreddit(name)
|
||||||
|
|
||||||
else:
|
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:
|
try:
|
||||||
with loader():
|
with loader():
|
||||||
sub = reddit.get_subreddit(name, fetch=True)
|
sub = reddit.get_subreddit(name, fetch=True)
|
||||||
except praw.errors.ClientException:
|
except praw.errors.ClientException:
|
||||||
raise SubredditNameError(name)
|
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):
|
def get(self, index, n_cols=70):
|
||||||
"""
|
"""
|
||||||
Grab the `i`th submission, with the title field formatted to fit inside
|
Grab the `i`th submission, with the title field formatted to fit inside
|
||||||
of a window of width `n`
|
of a window of width `n`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if index < 0:
|
if index < 0:
|
||||||
@@ -340,4 +361,4 @@ class SubredditContent(BaseContent):
|
|||||||
data['n_rows'] = len(data['split_title']) + 3
|
data['n_rows'] = len(data['split_title']) + 3
|
||||||
data['offset'] = 0
|
data['offset'] = 0
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user