From 1b6902bd32846bfc6d952330f3eb9e1b44d9f4c1 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Fri, 15 Dec 2023 15:13:33 +0200 Subject: [PATCH] [Medium] connector - fix after the review --- msteams/provider/provider.py | 17 +++++++++-------- msteams/provider/unstructured.py | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/msteams/provider/provider.py b/msteams/provider/provider.py index 6afaf642b..d886206f3 100644 --- a/msteams/provider/provider.py +++ b/msteams/provider/provider.py @@ -16,13 +16,10 @@ def strip_html_tags(html_text): def serialize_results(results): - return [ - { + serialized_results = [] + for result in results: + data_to_append = { "id": str(result["id"]), - "title": str( - result["subject"] - or strip_html_tags(result["body"]["content"])[:30] + "..." - ), "text": strip_html_tags(result["body"]["content"]), "summary": str(result["summary"]), "url": str( @@ -35,8 +32,12 @@ def serialize_results(results): "has_attachments": str(len(result["attachments"]) > 0), "date": str(result["createdDateTime"]), } - for result in results - ] + if "subject" in result: + data_to_append["title"] = str(result["subject"]) + + serialized_results.append(data_to_append) + + return serialized_results def prepare_attachments_to_parse(results): diff --git a/msteams/provider/unstructured.py b/msteams/provider/unstructured.py index 2b84d9bb3..c7ac10e34 100644 --- a/msteams/provider/unstructured.py +++ b/msteams/provider/unstructured.py @@ -10,7 +10,7 @@ logger = logging.getLogger(__name__) CACHE_LIMIT_BYTES = 20 * 1024 * 1024 # 20 MB to bytes - +TIMEOUT_SECONDS = 20 unstructured = None @@ -25,7 +25,9 @@ def __init__(self, unstructured_base_url, api_key): def start_session(self): self.loop = asyncio.new_event_loop() - self.session = aiohttp.ClientSession(loop=self.loop) + # Create ClientTimeout object to apply timeout for every request in the session + client_timeout = aiohttp.ClientTimeout(total=TIMEOUT_SECONDS) + self.session = aiohttp.ClientSession(loop=self.loop, timeout=client_timeout) def close_loop(self): self.loop.stop()