Adds env var for max posts

This commit is contained in:
sloum 2021-12-30 21:47:54 +00:00
parent 34bd525b82
commit c047cab495
1 changed files with 17 additions and 0 deletions

View File

@ -4,6 +4,7 @@
## If this script contains bugs, blame cmccabe.
import getpass
import os
import readline # pylint: disable=unused-import
import signal
import subprocess
@ -47,6 +48,18 @@ def print_categories():
def print_category_details(view_cat):
"""produces category detail data, prints it to the console. returns dict
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()
maxnamelen = len(max(link_data, key=lambda x: len(x[1]))[1])
namelen = max(maxnamelen, 6) # minimum field width is 6
@ -73,6 +86,10 @@ def print_category_details(view_cat):
for link in category_details:
link_count += 1
if limit and link_count > limit:
break
thread_index[link_count] = link["postid"]
if(desclen > 0):
desc = textwrap.shorten(link["description"], width=desclen, placeholder="...")