From b03089def0f6ce959914290d849291c60e5e860b Mon Sep 17 00:00:00 2001 From: Riccardo Benedetti <43098109+rbenedettix@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:38:29 +0200 Subject: [PATCH 1/2] Added max comment length variable in env --- .env.template | 3 +++ reddit/subreddit.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.env.template b/.env.template index e95c209..3574188 100644 --- a/.env.template +++ b/.env.template @@ -16,5 +16,8 @@ THEME="" # Enter a subreddit, e.g. "AskReddit" SUBREDDIT="" +# Max reddit comments length in characters e.g. "100" +MAX_COMMENT_LEN="100" + # Range is 0 -> 1 OPACITY="0.9" diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c560293..42bf87c 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,3 +1,4 @@ +from email.mime import base from rich.console import Console from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv @@ -67,13 +68,14 @@ def get_subreddit_threads(): for top_level_comment in submission.comments: if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if len(top_level_comment.body) <= int(os.getenv("MAX_COMMENT_LEN")): + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass From 223ab282a3d17c41928c7f75f3b39bbf67599627 Mon Sep 17 00:00:00 2001 From: Riccardo Benedetti <43098109+rbenedettix@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:49:42 +0200 Subject: [PATCH 2/2] Added comment len property to required values --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index 9aabe78..99e6afa 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ REQUIRED_VALUES = [ "REDDIT_USERNAME", "REDDIT_PASSWORD", "OPACITY", + "MAX_COMMENT_LEN", ]