From 6efddb364a51e7cb6d2194eb9f3b1425134a6ac9 Mon Sep 17 00:00:00 2001 From: Karako Date: Tue, 25 Apr 2023 22:35:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20honey=20impact=20data=20pa?= =?UTF-8?q?rse=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Karako --- core/dependence/assets.py | 1 + modules/wiki/base.py | 3 +-- plugins/genshin/daily/material.py | 15 +++++++++++++-- plugins/tools/genshin.py | 11 +++++------ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/dependence/assets.py b/core/dependence/assets.py index 72558497..9077eb86 100644 --- a/core/dependence/assets.py +++ b/core/dependence/assets.py @@ -472,6 +472,7 @@ class _NamecardAssets(_AssetsService): def __call__(self, target: int) -> "_NamecardAssets": result = _NamecardAssets(self.client) + target = int(target) if not isinstance(target, int) else target if target > 10000000: target = self._get_id_from_avatar_id(target) result.id = target diff --git a/modules/wiki/base.py b/modules/wiki/base.py index 3b5ba7d1..d2b5fada 100644 --- a/modules/wiki/base.py +++ b/modules/wiki/base.py @@ -18,7 +18,6 @@ try: except ImportError: import json as jsonlib - __all__ = ["Model", "WikiModel", "HONEY_HOST"] HONEY_HOST = URL("https://genshin.honeyhunterworld.com/") @@ -208,7 +207,7 @@ class WikiModel(Model): chaos_data = re.findall(r"sortable_data\.push\((.*?)\);\s*sortable_cur_page", response.text)[0] json_data = jsonlib.loads(chaos_data) # 转为 json for data in json_data: # 遍历 json - data_name = re.findall(r">(.*)<", data[1])[0].replace("\r", "") # 获取 Model 的名称 + data_name = re.findall(r">(.*)<", data[1])[0].strip() # 获取 Model 的名称 if with_url: # 如果需要返回对应的 url data_url = HONEY_HOST.join(re.findall(r"\"(.*?)\"", data[0])[0]) await queue.put((data_name, data_url)) diff --git a/plugins/genshin/daily/material.py b/plugins/genshin/daily/material.py index bec87ccd..0d10793e 100644 --- a/plugins/genshin/daily/material.py +++ b/plugins/genshin/daily/material.py @@ -230,7 +230,7 @@ class DailyMaterial(Plugin): logger.info("正在获取每日素材缓存") self.data = await self._refresh_data() for domain, sche in self.data.items(): - area = DOMAIN_AREA_MAP[domain] # 获取秘境所在的区域 + area = DOMAIN_AREA_MAP[domain := domain.strip()] # 获取秘境所在的区域 type_ = "avatar" if DOMAINS.index(domain) < 4 else "weapon" # 获取秘境的培养素材的类型:是天赋书还是武器突破材料 # 将读取到的数据存入 local_data 中 local_data[type_].append({"name": area, "materials": sche[weekday][0], "items": sche[weekday][1]}) @@ -387,7 +387,7 @@ class DailyMaterial(Plugin): for tag in calendar: tag: Tag if tag.name == "span": # 如果是秘境 - key = tag.find("a").text + key = tag.find("a").text.strip() result[key] = [[[], []] for _ in range(7)] for day, div in enumerate(tag.find_all("div")): result[key][day][0] = [] @@ -462,6 +462,17 @@ class DailyMaterial(Plugin): new_items.append(ITEM) task_list.append(task(*ITEM)) await asyncio.gather(*task_list) # 等待所有任务执行完成 + try: + await message.edit_text( + "\n".join(message.text_html.split("\n")[:2] + ["图标素材下载完成!"]), parse_mode=ParseMode.HTML + ) + except RetryAfter as e: + await asyncio.sleep(e.retry_after) + await message.edit_text( + "\n".join(message.text_html.split("\n")[:2] + ["图标素材下载完成!"]), parse_mode=ParseMode.HTML + ) + except Exception as e: + logger.debug(e) logger.info("图标素材下载完成") return the_time.value diff --git a/plugins/tools/genshin.py b/plugins/tools/genshin.py index 8b90d612..d3b09eaf 100644 --- a/plugins/tools/genshin.py +++ b/plugins/tools/genshin.py @@ -1,15 +1,14 @@ import asyncio import random -from datetime import datetime, timedelta, time -from typing import Optional, Tuple, Union, TYPE_CHECKING +from datetime import datetime, time, timedelta +from typing import Optional, TYPE_CHECKING, Tuple, Union import genshin from genshin.errors import GenshinException -from genshin.models import BaseCharacter -from genshin.models import CalculatorCharacterDetails +from genshin.models import BaseCharacter, CalculatorCharacterDetails from pydantic import ValidationError from sqlalchemy.exc import SQLAlchemyError -from sqlmodel import SQLModel, Field, String, Column, Integer, BigInteger, select, DateTime, func, delete, Index +from sqlmodel import BigInteger, Column, DateTime, Field, Index, Integer, SQLModel, String, delete, func, select from telegram.ext import ContextTypes from core.basemodel import RegionEnum @@ -29,7 +28,7 @@ if TYPE_CHECKING: from sqlalchemy import Table from genshin import Client as GenshinClient -__all__ = ("GenshinHelper", "PlayerNotFoundError", "CookiesNotFoundError") +__all__ = ("GenshinHelper", "PlayerNotFoundError", "CookiesNotFoundError", "CharacterDetails") class PlayerNotFoundError(Exception):