From 9a5c4616e38c004ef71d25fe5ecaf8d29568a72d Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Tue, 4 Mar 2025 16:36:01 -0500 Subject: [PATCH] Finished description cutoff detection. Added min_length parameter, as well as an addon parameter that might be used in the future to add extra text to the description where needed. Next up will be checking for media in the entry and adding a second embed field or attachment so the media can be previewed or listened to/watched right in the Discord post. --- discorss.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/discorss.py b/discorss.py index d33f387..b0163f0 100755 --- a/discorss.py +++ b/discorss.py @@ -44,34 +44,25 @@ app_config = {} # This function gets and formats the brief excerpt that goes in the embed # Different feeds put summaries in different fields, so we pick the best # one and limit it to 250 characters. -# TODO: make the character limit smarter, as to split at a natural point -def get_description(feed, length=250): +def get_description(feed, length=250, min_length=150, addons=None): try: temporary_string = str(feed["summary_detail"]["value"]) temporary_string = html_filter.sub("", temporary_string) - while length > 150: + while length > min_length: if temporary_string[length - 1 : length] == " ": break else: length -= 1 - desc = ( - temporary_string[:length] - if len(temporary_string) > length - else temporary_string - ) + desc = temporary_string[:length] except KeyError: temporary_string = str(feed["description"]) temporary_string = html_filter.sub("", temporary_string) - while length > 150: + while length > min_length: if temporary_string[length - 1 : length] == " ": break else: length -= 1 - desc = ( - temporary_string[:length] - if len(temporary_string) > length - else temporary_string - ) + desc = temporary_string[:length] return desc