Skip to content

Commit

Permalink
[Medium] connector - fix after the review
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneLightsOn committed Dec 15, 2023
1 parent ba994fa commit 1b6902b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 9 additions & 8 deletions msteams/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions msteams/provider/unstructured.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)

CACHE_LIMIT_BYTES = 20 * 1024 * 1024 # 20 MB to bytes

TIMEOUT_SECONDS = 20
unstructured = None


Expand All @@ -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()
Expand Down

0 comments on commit 1b6902b

Please sign in to comment.