Skip to content

Commit

Permalink
[Units] Limit extract after removing whitespace in search_wiki function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Harmon758 committed Jul 26, 2023
1 parent c5d668a commit e1fe99b
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions units/wikis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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('/')
Expand Down

0 comments on commit e1fe99b

Please sign in to comment.