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