From e1fe99bc2512dcbed028223e30596f0d10bfe3ae Mon Sep 17 00:00:00 2001 From: Harmon Date: Wed, 26 Jul 2023 06:38:05 -0500 Subject: [PATCH] [Units] Limit extract after removing whitespace in search_wiki function Limit extract length after removing extraneous whitespace in search_wiki function improve clarity of function and note arbitrariness of and mirroring of Discord limit for extract character limit --- units/wikis.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/units/wikis.py b/units/wikis.py index ed26907d47..2f90c3ab24 100644 --- a/units/wikis.py +++ b/units/wikis.py @@ -159,13 +159,7 @@ async def search_wiki( wiki_info_data = data["query"]["general"] if "extract" in page: - extract = re.sub( - r"\s+ \s+", ' ', - ( - page["extract"] if len(page["extract"]) <= 512 - else page["extract"][:512] + '…' - ) - ) + extract = re.sub(r"\s+ \s+", ' ', page["extract"]) else: # https://www.mediawiki.org/wiki/API:Parsing_wikitext async with aiohttp_session.get( @@ -191,13 +185,10 @@ async def search_wiki( second_p = p[1] extract += '\n' + second_p.get_text() - extract = re.sub( - r"\n\s*\n", "\n\n", - ( - extract if len(extract) <= 512 - else extract[:512] + '…' - ) - ) + extract = re.sub(r"\n\s*\n", "\n\n", extract) + + extract = extract if len(extract) <= 512 else extract[:512] + '…' + # TODO: Update character limit?, Discord now uses 350 article_path = wiki_info_data["articlepath"] url = url.rstrip('/')