From 3e2d1262febcadb1c62e8bba8e60013ba807514e Mon Sep 17 00:00:00 2001 From: binaryYuki <60097976+binaryYuki@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:01:59 +0100 Subject: [PATCH] fix: keyword error Signed-off-by: binaryYuki <60097976+binaryYuki@users.noreply.github.com> --- _search.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/_search.py b/_search.py index f65702f..818b2b0 100644 --- a/_search.py +++ b/_search.py @@ -70,14 +70,16 @@ async def link_keywords(keyword): if response.status_code != 200: return JSONResponse(content={"error": "Upstream Error"}, status_code=507) try: - words = response.json()["data"]["words"] - words = dict(set(words)) - # 排序 - words = dict(sorted(words.items(), key=lambda x: x[1], reverse=True)) - response.json()["data"]["words"] = words + words = response.json()["data"][0]["words"] + words = [word for word in words if word != "" and word != keyword] + # 去重 以及 空字符串 + words2 = list(set(words)) + words3 = list(sorted(words2, key=lambda x: len(x))) + newResponse = response.json() + newResponse["data"][0]["words"] = words3 + return newResponse except Exception as e: - pass - return response.json() + return response.json() # url 编码关键词