Merge pull request #261 from DomizianoScarcelli/filter-comments-by-length

Option to filter the comments by length (min and max number of characters)
This commit is contained in:
Callum Leslie authored and GitHub committed 2022-06-07 23:14:02 +01:00
commit a05a43f1de
2 files changed
+19 -10

No files matched your search

+5
View File
@@ -16,5 +16,10 @@ THEME=""
# Enter a subreddit, e.g. "AskReddit"
SUBREDDIT=""
# Filters the comments by range of lenght (min and max characters)
# Min has to be less or equal to max
# DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES
COMMENT_LENGTH_RANGE = "min,max"
# Range is 0 -> 1
OPACITY="0.9"
+14 -10
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
from numpy import Infinity
from rich.console import Console
from utils.console import print_step, print_substep
from utils.console import print_step, print_substep, print_markdown
from dotenv import load_dotenv
import os
import random
@@ -74,14 +74,18 @@ def get_subreddit_threads():
content["comments"] = []
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,
}
)
COMMENT_LENGTH_RANGE = [0, Infinity]
if os.getenv("COMMENT_LENGTH_RANGE"):
COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")]
if COMMENT_LENGTH_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGTH_RANGE[1]:
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,
}
)
except AttributeError:
pass