🐛 Fix honey impact data parse error

Signed-off-by: Karako <karakohear@gmail.com>
This commit is contained in:
Karako 2023-04-25 22:35:58 +08:00
parent ac879cc353
commit 6efddb364a
No known key found for this signature in database
GPG Key ID: 5920831B0095D4A0
4 changed files with 20 additions and 10 deletions

View File

@ -472,6 +472,7 @@ class _NamecardAssets(_AssetsService):
def __call__(self, target: int) -> "_NamecardAssets": def __call__(self, target: int) -> "_NamecardAssets":
result = _NamecardAssets(self.client) result = _NamecardAssets(self.client)
target = int(target) if not isinstance(target, int) else target
if target > 10000000: if target > 10000000:
target = self._get_id_from_avatar_id(target) target = self._get_id_from_avatar_id(target)
result.id = target result.id = target

View File

@ -18,7 +18,6 @@ try:
except ImportError: except ImportError:
import json as jsonlib import json as jsonlib
__all__ = ["Model", "WikiModel", "HONEY_HOST"] __all__ = ["Model", "WikiModel", "HONEY_HOST"]
HONEY_HOST = URL("https://genshin.honeyhunterworld.com/") 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] chaos_data = re.findall(r"sortable_data\.push\((.*?)\);\s*sortable_cur_page", response.text)[0]
json_data = jsonlib.loads(chaos_data) # 转为 json json_data = jsonlib.loads(chaos_data) # 转为 json
for data in json_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 if with_url: # 如果需要返回对应的 url
data_url = HONEY_HOST.join(re.findall(r"\"(.*?)\"", data[0])[0]) data_url = HONEY_HOST.join(re.findall(r"\"(.*?)\"", data[0])[0])
await queue.put((data_name, data_url)) await queue.put((data_name, data_url))

View File

@ -230,7 +230,7 @@ class DailyMaterial(Plugin):
logger.info("正在获取每日素材缓存") logger.info("正在获取每日素材缓存")
self.data = await self._refresh_data() self.data = await self._refresh_data()
for domain, sche in self.data.items(): 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" # 获取秘境的培养素材的类型:是天赋书还是武器突破材料 type_ = "avatar" if DOMAINS.index(domain) < 4 else "weapon" # 获取秘境的培养素材的类型:是天赋书还是武器突破材料
# 将读取到的数据存入 local_data 中 # 将读取到的数据存入 local_data 中
local_data[type_].append({"name": area, "materials": sche[weekday][0], "items": sche[weekday][1]}) 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: for tag in calendar:
tag: Tag tag: Tag
if tag.name == "span": # 如果是秘境 if tag.name == "span": # 如果是秘境
key = tag.find("a").text key = tag.find("a").text.strip()
result[key] = [[[], []] for _ in range(7)] result[key] = [[[], []] for _ in range(7)]
for day, div in enumerate(tag.find_all("div")): for day, div in enumerate(tag.find_all("div")):
result[key][day][0] = [] result[key][day][0] = []
@ -462,6 +462,17 @@ class DailyMaterial(Plugin):
new_items.append(ITEM) new_items.append(ITEM)
task_list.append(task(*ITEM)) task_list.append(task(*ITEM))
await asyncio.gather(*task_list) # 等待所有任务执行完成 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("图标素材下载完成") logger.info("图标素材下载完成")
return the_time.value return the_time.value

View File

@ -1,15 +1,14 @@
import asyncio import asyncio
import random import random
from datetime import datetime, timedelta, time from datetime import datetime, time, timedelta
from typing import Optional, Tuple, Union, TYPE_CHECKING from typing import Optional, TYPE_CHECKING, Tuple, Union
import genshin import genshin
from genshin.errors import GenshinException from genshin.errors import GenshinException
from genshin.models import BaseCharacter from genshin.models import BaseCharacter, CalculatorCharacterDetails
from genshin.models import CalculatorCharacterDetails
from pydantic import ValidationError from pydantic import ValidationError
from sqlalchemy.exc import SQLAlchemyError 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 telegram.ext import ContextTypes
from core.basemodel import RegionEnum from core.basemodel import RegionEnum
@ -29,7 +28,7 @@ if TYPE_CHECKING:
from sqlalchemy import Table from sqlalchemy import Table
from genshin import Client as GenshinClient from genshin import Client as GenshinClient
__all__ = ("GenshinHelper", "PlayerNotFoundError", "CookiesNotFoundError") __all__ = ("GenshinHelper", "PlayerNotFoundError", "CookiesNotFoundError", "CharacterDetails")
class PlayerNotFoundError(Exception): class PlayerNotFoundError(Exception):