diff --git a/models/avatar.py b/models/avatar.py index 51759fa..c78266e 100644 --- a/models/avatar.py +++ b/models/avatar.py @@ -28,7 +28,7 @@ class AvatarPromote(BaseModel): coin: int = 0 """信用点""" - items: list[AvatarItem] + items: List[AvatarItem] """突破所需材料""" diff --git a/models/light_cone.py b/models/light_cone.py index a9c8fee..12ebb8b 100644 --- a/models/light_cone.py +++ b/models/light_cone.py @@ -1,4 +1,6 @@ # 光锥 +from typing import List + from pydantic import BaseModel from .enums import Quality, Destiny @@ -22,7 +24,7 @@ class LightConePromote(BaseModel): coin: int = 0 """信用点""" - items: list[LightConeItem] + items: List[LightConeItem] """突破所需材料""" @@ -41,9 +43,9 @@ class LightCone(BaseModel): """稀有度""" destiny: Destiny """命途""" - promote: list[LightConePromote] + promote: List[LightConePromote] """晋阶信息""" @property def rarity(self) -> int: - return 5 - list(Quality).index(self.quality) + return 5 - list[Quality].index(self.quality) diff --git a/res_func/avatar.py b/res_func/avatar.py index 6b34478..74ebe82 100644 --- a/res_func/avatar.py +++ b/res_func/avatar.py @@ -6,7 +6,7 @@ import aiofiles import ujson from bs4 import BeautifulSoup, Tag -from func.fetch_avatars import read_avatars, all_avatars_name, dump_avatars +from func.fetch_avatars import read_avatars, all_avatars_name, dump_avatars, all_avatars, all_avatars_map from .client import client from .url import avatar_config, text_map, base_station_url, avatar_url from models.avatar_config import AvatarConfig, AvatarIcon @@ -28,9 +28,11 @@ async def fetch_config(text_map_data: Dict[str, str]) -> List[AvatarConfig]: return datas -async def parse_station(datas, name: str, tag: Tag, avatar: AvatarConfig): +async def parse_station(datas, name: str, tag: Tag, cid: int): second_pic = "" - if avatar_model := all_avatars_name.get(name): + if avatar_model := all_avatars_map.get(cid): + second_pic = avatar_model.icon + elif avatar_model := all_avatars_name.get(name): second_pic = avatar_model.icon third_pic = f'{base_station_url}{tag.find("img").get("src")}' html = await client.get(f'{base_station_url}{tag.get("href")}') @@ -40,8 +42,8 @@ async def parse_station(datas, name: str, tag: Tag, avatar: AvatarConfig): first_pic = f'{base_station_url}{soup.find("img", {"class": "ac39b a6602"}).get("src")}' datas.append( AvatarIcon( - id=avatar.AvatarID, - name=avatar.name, + id=cid, + name=name, icon=[first_pic, second_pic, third_pic, four_pic], ) ) @@ -54,6 +56,18 @@ async def dump_icons(path: Path, datas: List[AvatarIcon]): await f.write(ujson.dumps(data, indent=4, ensure_ascii=False)) +async def fetch_station_ktz(tasks, datas, player_avatars: List[Tag]): + data_map = { + "开拓者·毁灭": (8001, 8002), + "开拓者·存护": (8003, 8004) + } + idx = 0 + for key, value in data_map.items(): + tasks.append(parse_station(datas, key, player_avatars[idx], value[0])) + tasks.append(parse_station(datas, key, player_avatars[idx + 1], value[1])) + idx += 2 + + async def fetch_station(configs_map: Dict[str, AvatarConfig]) -> List[AvatarIcon]: print("开始获取角色素材") html = await client.get(avatar_url) @@ -61,38 +75,51 @@ async def fetch_station(configs_map: Dict[str, AvatarConfig]) -> List[AvatarIcon avatars = soup.find_all("a", {"class": "char-entry-select-option"}) tasks = [] datas: List[AvatarIcon] = [] - ktz = False + player_avatars = [] for avatar in avatars: name = avatar.find("span").get_text().strip() - if name == "开拓者" and ktz: + if name == "开拓者": + player_avatars.append(avatar) continue if avatar_model := configs_map.get(name): - tasks.append(parse_station(datas, name, avatar, avatar_model)) - if name == "开拓者": - ktz = True + tasks.append(parse_station(datas, name, avatar, avatar_model.AvatarID)) else: print(f"未找到角色 {name} 的数据") + await fetch_station_ktz(tasks, datas, player_avatars) await asyncio.gather(*tasks) return datas +async def fix_avatar_config_ktz(): + data_map = {"开拓者·毁灭": (8001, 8002), "开拓者·存护": (8003, 8004)} + for key, value in data_map.items(): + one = all_avatars_name[key] + one.name = key + two = one.copy() + one.id = value[0] + two.id = value[1] + all_avatars.append(two) + all_avatars_map[value[0]] = one + all_avatars_map[value[1]] = two + all_avatars_name[one.name] = one + + async def fix_avatar_config(text_map_data: Dict[str, str]): configs = await fetch_config(text_map_data) configs_map: Dict[str, AvatarConfig] = {config.name: config for config in configs} - configs_map["开拓者"] = configs_map["{NICKNAME}"] print(f"读取到原始数据:{list(configs_map.keys())}") data_path = Path("data") await read_avatars(data_path / "avatars.json") for key, value in all_avatars_name.items(): if key.startswith("开拓者"): - config = configs_map["{NICKNAME}"] - config.name = "开拓者" + continue else: config = configs_map.get(key) if config is None: print(f"错误:未找到角色 {key} 的配置") continue value.id = config.AvatarID + await fix_avatar_config_ktz() icons = await fetch_station(configs_map) await dump_icons(data_path / "avatar_icons.json", icons) await dump_avatars(data_path / "avatars.json")