mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-06 08:43:41 +00:00
Make a display thread function for re-use (#74)
This commit is contained in:
@@ -1 +1 @@
|
|||||||
0.3.5
|
0.3.6
|
||||||
|
46
rfd/cli.py
46
rfd/cli.py
@@ -43,6 +43,27 @@ def print_version(ctx, value):
|
|||||||
ctx.exit()
|
ctx.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def display_thread(click, thread, count): # pylint: disable=redefined-outer-name
|
||||||
|
dealer = thread.dealer_name
|
||||||
|
if dealer and dealer is not None:
|
||||||
|
dealer = "[" + dealer + "] "
|
||||||
|
else:
|
||||||
|
dealer = ""
|
||||||
|
click.echo(
|
||||||
|
" "
|
||||||
|
+ str(count)
|
||||||
|
+ "."
|
||||||
|
+ get_vote_color(thread.score)
|
||||||
|
+ Fore.RESET
|
||||||
|
+ "%s%s" % (dealer, thread.title)
|
||||||
|
+ Fore.LIGHTYELLOW_EX
|
||||||
|
+ " (%d views)" % thread.total_views
|
||||||
|
+ Fore.RESET
|
||||||
|
)
|
||||||
|
click.echo(Fore.BLUE + " {}".format(thread.url))
|
||||||
|
click.echo(Style.RESET_ALL)
|
||||||
|
|
||||||
|
|
||||||
@click.group(invoke_without_command=True)
|
@click.group(invoke_without_command=True)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-v",
|
"-v",
|
||||||
@@ -115,19 +136,7 @@ def threads(limit, forum_id):
|
|||||||
"""
|
"""
|
||||||
_threads = parse_threads(get_threads(forum_id, limit), limit)
|
_threads = parse_threads(get_threads(forum_id, limit), limit)
|
||||||
for count, thread in enumerate(_threads, 1):
|
for count, thread in enumerate(_threads, 1):
|
||||||
click.echo(
|
display_thread(click, thread, count)
|
||||||
" "
|
|
||||||
+ str(count)
|
|
||||||
+ "."
|
|
||||||
+ get_vote_color(thread.score)
|
|
||||||
+ Fore.RESET
|
|
||||||
+ "[%s] %s" % (thread.dealer_name, thread.title)
|
|
||||||
+ Fore.LIGHTYELLOW_EX
|
|
||||||
+ " (%d views)" % thread.total_views
|
|
||||||
+ Fore.RESET
|
|
||||||
)
|
|
||||||
click.echo(Fore.BLUE + " {}".format(thread.url))
|
|
||||||
click.echo(Style.RESET_ALL)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command(short_help="Search deals based on a regular expression.")
|
@cli.command(short_help="Search deals based on a regular expression.")
|
||||||
@@ -159,13 +168,4 @@ def search(num_pages, forum_id, regex):
|
|||||||
_threads = parse_threads(get_threads(forum_id, 100, page=page), limit=100)
|
_threads = parse_threads(get_threads(forum_id, 100, page=page), limit=100)
|
||||||
for thread in search_threads(threads=_threads, regex=regex):
|
for thread in search_threads(threads=_threads, regex=regex):
|
||||||
count += 1
|
count += 1
|
||||||
click.echo(
|
display_thread(click, thread, count)
|
||||||
" "
|
|
||||||
+ str(count)
|
|
||||||
+ "."
|
|
||||||
+ get_vote_color(thread.score)
|
|
||||||
+ Fore.RESET
|
|
||||||
+ "[%s] %s" % (thread.dealer_name, thread.title)
|
|
||||||
)
|
|
||||||
click.echo(Fore.BLUE + " {}".format(thread.url))
|
|
||||||
click.echo(Style.RESET_ALL)
|
|
||||||
|
@@ -7,6 +7,13 @@ def build_web_path(slug):
|
|||||||
return "{}{}".format(API_BASE_URL, slug)
|
return "{}{}".format(API_BASE_URL, slug)
|
||||||
|
|
||||||
|
|
||||||
|
def get_dealer(topic):
|
||||||
|
dealer = None
|
||||||
|
if topic.get("offer"):
|
||||||
|
dealer = topic.get("offer").get("dealer_name")
|
||||||
|
return dealer
|
||||||
|
|
||||||
|
|
||||||
def parse_threads(threads, limit):
|
def parse_threads(threads, limit):
|
||||||
"""parse topics list api response into digestible list.
|
"""parse topics list api response into digestible list.
|
||||||
|
|
||||||
@@ -26,7 +33,7 @@ def parse_threads(threads, limit):
|
|||||||
parsed_threads.append(
|
parsed_threads.append(
|
||||||
Thread(
|
Thread(
|
||||||
title=topic.get("title"),
|
title=topic.get("title"),
|
||||||
dealer_name=topic["offer"].get("dealer_name"),
|
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"),
|
total_views=topic.get("total_views"),
|
||||||
|
Reference in New Issue
Block a user