WIP: Adds env var for max posts #105

Draft
sloum wants to merge 1 commits from line-limit into master
1 changed files with 17 additions and 0 deletions

View File

@ -4,6 +4,7 @@
## If this script contains bugs, blame cmccabe. ## If this script contains bugs, blame cmccabe.
import getpass import getpass
import os
import readline # pylint: disable=unused-import import readline # pylint: disable=unused-import
import signal import signal
import subprocess import subprocess
@ -47,6 +48,18 @@ def print_categories():
def print_category_details(view_cat): def print_category_details(view_cat):
"""produces category detail data, prints it to the console. returns dict """produces category detail data, prints it to the console. returns dict
containing an index of threads""" containing an index of threads"""
# Limits the number of posts that will show based on the
# env var $LINK_LIMIT
limit = os.getenv("LINK_LIMIT")
if limit:
try:
limit = int(limit)
if limit <= 0:
limit = None
except:
limit = None
columns, _ = get_terminal_size() columns, _ = get_terminal_size()
maxnamelen = len(max(link_data, key=lambda x: len(x[1]))[1]) maxnamelen = len(max(link_data, key=lambda x: len(x[1]))[1])
namelen = max(maxnamelen, 6) # minimum field width is 6 namelen = max(maxnamelen, 6) # minimum field width is 6
@ -73,6 +86,10 @@ def print_category_details(view_cat):
for link in category_details: for link in category_details:
link_count += 1 link_count += 1
if limit and link_count > limit:
break
thread_index[link_count] = link["postid"] thread_index[link_count] = link["postid"]
if(desclen > 0): if(desclen > 0):
desc = textwrap.shorten(link["description"], width=desclen, placeholder="...") desc = textwrap.shorten(link["description"], width=desclen, placeholder="...")