From 0736533389f0d773ecaf08c3ec4fc099b5a02597 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Mon, 13 Jun 2022 22:16:45 +0800 Subject: [PATCH] fix search_image --- README.md | 6 ++++-- plugins/search_image/saucenao.py | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b6cd755c..49f5c819 100644 --- a/README.md +++ b/README.md @@ -245,8 +245,10 @@ __Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__ ### 2022/6/13 -* 色图等提供修改md5方法 -* webui中token.json文件写入补充 +* Windows 重启适配 [@pull/804](https://github.com/HibiKier/zhenxun_bot/pull/804) +* 色图等提供修改md5方法 [@pull/800](https://github.com/HibiKier/zhenxun_bot/pull/800) +* webui中token.json文件写入补充 [@pull/798](https://github.com/HibiKier/zhenxun_bot/pull/798) +* 修复识图某些图片可能会出错 ### 2022/6/11 diff --git a/plugins/search_image/saucenao.py b/plugins/search_image/saucenao.py index 86fb2fb9..dd0c395b 100644 --- a/plugins/search_image/saucenao.py +++ b/plugins/search_image/saucenao.py @@ -1,3 +1,4 @@ +from services import logger from utils.http_utils import AsyncHttpx from configs.config import Config from configs.path_config import TEMP_PATH @@ -39,12 +40,18 @@ async def get_saucenao_image(url: str) -> Union[str, List[str]]: ): msg_list.append(image(TEMP_PATH / f"saucenao_search_{index}.jpg")) for info in data: - similarity = info["header"]["similarity"] - tmp = f"相似度:{similarity}%\n" - for x in info["data"].keys(): - if x != "ext_urls": - tmp += f"{x}:{info['data'][x]}\n" - if "source" not in info["data"].keys(): - tmp += f'source:{info["data"]["ext_urls"][0]}\n' - msg_list.append(tmp[:-1]) + try: + similarity = info["header"]["similarity"] + tmp = f"相似度:{similarity}%\n" + for x in info["data"].keys(): + if x != "ext_urls": + tmp += f"{x}:{info['data'][x]}\n" + try: + if "source" not in info["data"].keys(): + tmp += f'source:{info["data"]["ext_urls"][0]}\n' + except KeyError: + tmp += f'source:{info["header"]["thumbnail"]}\n' + msg_list.append(tmp[:-1]) + except Exception as e: + logger.warning(f"识图获取图片信息发生错误 {type(e)}:{e}") return msg_list