From c047cab4957441eb991f0473ff34cba3169b8a78 Mon Sep 17 00:00:00 2001 From: sloum Date: Thu, 30 Dec 2021 21:47:54 +0000 Subject: [PATCH] Adds env var for max posts --- linkulator.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/linkulator.py b/linkulator.py index d1a745c..1e3680c 100755 --- a/linkulator.py +++ b/linkulator.py @@ -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="...") -- 2.34.1