From 30818559cd76d33d7792b2760c20e64173243138 Mon Sep 17 00:00:00 2001 From: qwerdvd <105906879+qwerdvd@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:55:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E5=87=A0=E4=B8=AA=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starrailuid_charinfo/draw_char_img.py | 38 +++++++++--------- .../utils/resource/download_from_cos.py | 40 +++++++++---------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/StarRailUID/starrailuid_charinfo/draw_char_img.py b/StarRailUID/starrailuid_charinfo/draw_char_img.py index d9c2a4f..95913c5 100644 --- a/StarRailUID/starrailuid_charinfo/draw_char_img.py +++ b/StarRailUID/starrailuid_charinfo/draw_char_img.py @@ -1,32 +1,18 @@ +import copy import json import math import textwrap from pathlib import Path from typing import Dict, Union -import copy -from PIL import Image, ImageDraw + from gsuid_core.logger import logger from gsuid_core.utils.image.convert import convert_img from gsuid_core.utils.image.image_tools import draw_text_by_line +from PIL import Image, ImageDraw -from .to_data import api_to_dict from ..utils.error_reply import CHAR_HINT -from .cal_damage import cal, cal_char_info, cal_info -from ..utils.fonts.first_world import fw_font_28 from ..utils.excel.read_excel import light_cone_ranks -from ..utils.map.name_covert import name_to_avatar_id, alias_to_char_name -from ..utils.map.SR_MAP_PATH import ( - RelicId2Rarity, - AvatarRelicScore, - avatarId2Name, -) -from ..utils.resource.RESOURCE_PATH import ( - RELIC_PATH, - SKILL_PATH, - PLAYER_PATH, - WEAPON_PATH, - CHAR_PORTRAIT_PATH, -) +from ..utils.fonts.first_world import fw_font_28 from ..utils.fonts.starrail_fonts import ( sr_font_18, sr_font_20, @@ -37,6 +23,21 @@ from ..utils.fonts.starrail_fonts import ( sr_font_34, sr_font_38, ) +from ..utils.map.name_covert import alias_to_char_name, name_to_avatar_id +from ..utils.map.SR_MAP_PATH import ( + AvatarRelicScore, + RelicId2Rarity, + avatarId2Name, +) +from ..utils.resource.RESOURCE_PATH import ( + CHAR_PORTRAIT_PATH, + PLAYER_PATH, + RELIC_PATH, + SKILL_PATH, + WEAPON_PATH, +) +from .cal_damage import cal_char_info, cal_info +from .to_data import api_to_dict Excel_path = Path(__file__).parent / 'damage' with Path.open(Excel_path / 'Excel' / 'SkillData.json', encoding='utf-8') as f: @@ -611,6 +612,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str): if damage_len > 0: damage_title_img = Image.open(TEXT_PATH / 'base_info_pure.png') char_info.paste(damage_title_img, (0, 2028), damage_title_img) + damage_list = [] # damage_list = await cal(char_data) # 写伤害 char_img_draw.text( diff --git a/StarRailUID/utils/resource/download_from_cos.py b/StarRailUID/utils/resource/download_from_cos.py index 15e7b19..c9ff315 100644 --- a/StarRailUID/utils/resource/download_from_cos.py +++ b/StarRailUID/utils/resource/download_from_cos.py @@ -2,33 +2,33 @@ import asyncio from pathlib import Path from typing import Dict, List, Tuple, Union -from bs4 import BeautifulSoup -from msgspec import json as msgjson -from gsuid_core.logger import logger +from aiohttp import ClientTimeout, TCPConnector from aiohttp.client import ClientSession -from aiohttp import TCPConnector, ClientTimeout -from gsuid_core.utils.download_resource.download_file import download +from bs4 import BeautifulSoup +from gsuid_core.logger import logger from gsuid_core.utils.download_resource.download_core import check_url +from gsuid_core.utils.download_resource.download_file import download +from msgspec import json as msgjson from .download_url import download_file from .RESOURCE_PATH import ( - WIKI_PATH, + CHAR_ICON_PATH, + CHAR_PORTRAIT_PATH, + CHAR_PREVIEW_PATH, + CONSUMABLE_PATH, + ELEMENT_PATH, + GUIDE_CHARACTER_PATH, + GUIDE_LIGHT_CONE_PATH, GUIDE_PATH, RELIC_PATH, + RESOURCE_PATH, SKILL_PATH, WEAPON_PATH, - ELEMENT_PATH, - RESOURCE_PATH, - CHAR_ICON_PATH, - WIKI_ROLE_PATH, - CONSUMABLE_PATH, - WIKI_RELIC_PATH, - CHAR_PREVIEW_PATH, - CHAR_PORTRAIT_PATH, - GUIDE_CHARACTER_PATH, WIKI_LIGHT_CONE_PATH, - GUIDE_LIGHT_CONE_PATH, WIKI_MATERIAL_FOR_ROLE, + WIKI_PATH, + WIKI_RELIC_PATH, + WIKI_ROLE_PATH, ) with Path.open( @@ -45,15 +45,15 @@ async def find_fastest_url(urls: Dict[str, str]): for tag in urls: tasks.append(asyncio.create_task(check_url(tag, urls[tag]))) - results: list[tuple[str, str, float]] = await asyncio.gather( - *tasks, return_exceptions=True - ) + results: list[ + tuple[str, str, float] | BaseException + ] = await asyncio.gather(*tasks, return_exceptions=True) fastest_tag = '' fastest_url = None fastest_time = float('inf') for result in results: - if isinstance(result, Exception): + if isinstance(result, BaseException): continue tag, url, elapsed_time = result if elapsed_time < fastest_time: