From 843e9d060a7bfdeab16f5b345ea6a2c469769b19 Mon Sep 17 00:00:00 2001 From: freamon Date: Fri, 10 May 2024 13:42:12 +0100 Subject: [PATCH] fall back for if there's no recognised punctuation in microblog --- app/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/utils.py b/app/utils.py index de99253a..196e6888 100644 --- a/app/utils.py +++ b/app/utils.py @@ -259,11 +259,16 @@ def microblog_content_to_title(html: str) -> str: question_index = title.find('?') exclamation_index = title.find('!') - # Find the earliest occurrence of either '.' or '?' + # Find the earliest occurrence of either '.' or '?' or '!' end_index = min(period_index if period_index != -1 else float('inf'), question_index if question_index != -1 else float('inf'), exclamation_index if exclamation_index != -1 else float('inf')) + # give up if there's no recognised punctuation + if end_index == float('inf'): + title = '(content in post body)' + return title + if end_index != -1: if question_index != -1: end_index += 1 # Add the ? back on