Fix count bugs (#1)

* tail/head working
* check if votes is null.
This commit is contained in:
Dave Gallant
2018-03-12 23:59:31 -04:00
committed by GitHub
parent c580bbd913
commit e5f2dd8bcb
9 changed files with 157 additions and 25 deletions

View File

@@ -28,9 +28,10 @@ def cli():
@cli.command(short_help="Displays posts in a specific thread.")
@click.option('--count', default=5, help='Number of topics. 0 for all topics')
@click.option('--head', default=0, help='Number of topics. Default is 0, for all topics')
@click.option('--tail', default=0, help='Number of topics. Default is disabled. This will override head.')
@click.argument('post_id')
def posts(count, post_id):
def posts(post_id, head, tail):
"""Displays posts in a specific thread.
post_id can be a full url or post id only
@@ -41,13 +42,23 @@ def posts(count, post_id):
url: https://forums.redflagdeals.com/koodo-targeted-public-mobile-12-120-koodo-5gb-40-no-referrals-2173603
post_id: 2173603
"""
if count < 0:
click.echo("Invalid count.")
if head < 0:
click.echo("Invalid head.")
sys.exit(1)
if tail < 0:
click.echo("Invalid tail.")
sys.exit(1)
# Tail overrides head
if tail > 0:
count = tail
else:
count = head
try:
click.echo("-" * get_terminal_width())
for post in get_posts(post_id, count):
for post in get_posts(post=post_id, count=count, tail=tail > 0):
click.echo(" -" + get_vote_color(post.get('score')) + Fore.RESET +
post.get('body') + Fore.YELLOW + " ({})".format(post.get('user')))
click.echo(Style.RESET_ALL)