Simplify sort-by 'total_views' -> 'views' (#76)

This commit is contained in:
Dave Gallant
2020-08-02 21:42:53 -04:00
committed by GitHub
parent 20089bc699
commit ad4a072325
4 changed files with 7 additions and 7 deletions

View File

@@ -48,7 +48,7 @@ $ rfd threads --sort-by score
``` ```
```console ```console
$ rfd threads --sort-by total_views --limit 40 $ rfd threads --sort-by views --limit 40
``` ```
### Simple Search ### Simple Search

View File

@@ -1 +1 @@
0.4.0 0.4.1

View File

@@ -56,7 +56,7 @@ def display_thread(click, thread, count): # pylint: disable=redefined-outer-nam
+ Fore.RESET + Fore.RESET
+ "%s%s" % (dealer, thread.title) + "%s%s" % (dealer, thread.title)
+ Fore.LIGHTYELLOW_EX + Fore.LIGHTYELLOW_EX
+ " (%d views)" % thread.total_views + " (%d views)" % thread.views
+ Fore.RESET + Fore.RESET
) )
click.echo(Fore.BLUE + " {}".format(thread.url)) click.echo(Fore.BLUE + " {}".format(thread.url))

View File

@@ -4,12 +4,12 @@ from .scores import calculate_score
# pylint: disable=old-style-class # pylint: disable=old-style-class
class Thread: class Thread:
def __init__(self, title, dealer_name, score, url, total_views): def __init__(self, title, dealer_name, score, url, views):
self.dealer_name = dealer_name self.dealer_name = dealer_name
self.score = score self.score = score
self.title = title self.title = title
self.url = url self.url = url
self.total_views = total_views self.views = views
def __repr__(self): def __repr__(self):
return "Thread(%s)" % self.title return "Thread(%s)" % self.title
@@ -48,7 +48,7 @@ def parse_threads(threads, limit):
dealer_name=get_dealer(topic), dealer_name=get_dealer(topic),
score=calculate_score(topic), score=calculate_score(topic),
url=build_web_path(topic.get("web_path")), url=build_web_path(topic.get("web_path")),
total_views=topic.get("total_views"), views=topic.get("total_views"),
) )
) )
return parsed_threads return parsed_threads
@@ -58,7 +58,7 @@ def sort_threads(threads, sort_by):
"""Sort threads by an attribute""" """Sort threads by an attribute"""
if sort_by is None: if sort_by is None:
return threads return threads
assert sort_by in ["total_views", "score", "title"] assert sort_by in ["views", "score", "title"]
threads = sorted(threads, key=lambda x: getattr(x, sort_by), reverse=True) threads = sorted(threads, key=lambda x: getattr(x, sort_by), reverse=True)
return threads return threads