support: square icon

This commit is contained in:
xtaodada 2023-04-28 19:32:53 +08:00
parent faf212844b
commit 6a1333ebb5
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
8 changed files with 42 additions and 12 deletions

View File

@ -27,6 +27,7 @@ async def fetch_avatars(data: Children):
avatar = Avatar(
id=content.content_id,
name=content.title,
icon=content.icon,
quality=m_quality,
element=m_element,
destiny=m_destiny,

View File

@ -1,7 +1,7 @@
from typing import List
from pydantic import BaseModel
from models.enums import Quality, Destiny, Element
from models.material import Material
from .enums import Quality, Destiny, Element
from .material import Material
class AvatarInfo(BaseModel):
@ -44,6 +44,8 @@ class Avatar(BaseModel):
"""角色ID"""
name: str
"""名称"""
icon: str
"""图标"""
quality: Quality
"""品质"""
destiny: Destiny

View File

@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional
from pydantic import BaseModel
@ -22,3 +22,19 @@ class AvatarIcon(BaseModel):
"""名称"""
icon: List[str]
"""图标(从小到大)"""
@property
def gacha(self) -> str:
return self.icon[3]
@property
def icon_(self) -> str:
return self.icon[0]
@property
def square(self) -> Optional[str]:
return self.icon[1]
@property
def normal(self) -> str:
return self.icon[2]

View File

@ -1,8 +1,8 @@
# 光锥
from pydantic import BaseModel
from models.enums import Quality, Destiny
from models.material import Material
from .enums import Quality, Destiny
from .material import Material
class LightConeItem(BaseModel):

View File

@ -10,3 +10,11 @@ class LightConeIcon(BaseModel):
"""名称"""
icon: List[str]
"""图标(从小到大)"""
@property
def gacha(self) -> str:
return self.icon[1]
@property
def icon_(self) -> str:
return self.icon[0]

View File

@ -1,7 +1,7 @@
# 材料
from pydantic import BaseModel
from models.enums import Quality, MaterialType
from .enums import Quality, MaterialType
class Material(BaseModel):

View File

@ -1,7 +1,7 @@
# 敌对物种
from pydantic import BaseModel
from models.enums import MonsterType, Area
from .enums import MonsterType, Area
class Monster(BaseModel):

View File

@ -28,18 +28,21 @@ async def fetch_config(text_map: Dict[str, str]) -> List[AvatarConfig]:
return datas
async def parse_station(datas, tag: Tag, avatar: AvatarConfig):
second_pic = f'{base_station_url}{tag.find("img").get("src")}'
async def parse_station(datas, name: str, tag: Tag, avatar: AvatarConfig):
second_pic = ""
if 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")}')
soup = BeautifulSoup(html.text, "lxml")
text = soup.find("div", {"class": "a6678 a4af5"}).get("style")
third_pic = f'{base_station_url}{text[text.find("(") + 2:text.find(")") - 1]}' if text else ""
four_pic = f'{base_station_url}{text[text.find("(") + 2:text.find(")") - 1]}' if text else ""
first_pic = f'{base_station_url}{soup.find("img", {"class": "ac39b a6602"}).get("src")}'
datas.append(
AvatarIcon(
id=avatar.AvatarID,
name=avatar.name,
icon=[first_pic, second_pic, third_pic],
icon=[first_pic, second_pic, third_pic, four_pic],
)
)
@ -64,7 +67,7 @@ async def fetch_station(configs_map: Dict[str, AvatarConfig]) -> List[AvatarIcon
if name == "开拓者" and ktz:
continue
if avatar_model := configs_map.get(name):
tasks.append(parse_station(datas, avatar, avatar_model))
tasks.append(parse_station(datas, name, avatar, avatar_model))
if name == "开拓者":
ktz = True
else: