ruff lint

This commit is contained in:
qwerdvd 2023-08-18 22:45:12 +08:00
parent 480d741194
commit b79490859e
9 changed files with 33 additions and 37 deletions

View File

@ -158,7 +158,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
if finishTs < recruit[i].finishTs: if finishTs < recruit[i].finishTs:
finishTs = recruit[i].finishTs finishTs = recruit[i].finishTs
if finishTs != -1: if finishTs != -1:
# 获取当前时间与 finishTs 的时间差转换为几小时几分钟 # 获取当前时间与 finishTs 的时间差, 转换为几小时几分钟
now = datetime.now() now = datetime.now()
finishTs = datetime.fromtimestamp(finishTs) finishTs = datetime.fromtimestamp(finishTs)
delta = finishTs - now delta = finishTs - now
@ -209,7 +209,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
grey_bar_bg1_img = grey_bar_bg1.copy() grey_bar_bg1_img = grey_bar_bg1.copy()
grey_bar_bg1_draw = ImageDraw.Draw(grey_bar_bg1_img) grey_bar_bg1_draw = ImageDraw.Draw(grey_bar_bg1_img)
complete_work_time = player_info.building.hire.completeWorkTime complete_work_time = player_info.building.hire.completeWorkTime
# 获取当前时间与 completeWorkTime 的时间差转换为几小时几分钟 # 获取当前时间与 completeWorkTime 的时间差, 转换为几小时几分钟
now = datetime.now() now = datetime.now()
complete_work_time = datetime.fromtimestamp(complete_work_time) complete_work_time = datetime.fromtimestamp(complete_work_time)
delta = complete_work_time - now delta = complete_work_time - now
@ -269,7 +269,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
remain_secs = player_info.building.training.remainSecs remain_secs = player_info.building.training.remainSecs
remain_time = 0 remain_time = 0
if remain_secs != -1: if remain_secs != -1:
# 将remainSecs(剩余秒数) 转换为几小时几分钟 # 将remainSecs(剩余秒数) , 转换为几小时几分钟
remain_time = seconds2hours_zhcn(remain_secs) remain_time = seconds2hours_zhcn(remain_secs)
char_cn_name = Excel.CHARATER_TABLE[training_char].name char_cn_name = Excel.CHARATER_TABLE[training_char].name
@ -338,7 +338,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
anchor='lm', anchor='lm',
) )
# 获取当前时间与下一周周一早上4点的时间差转换为几天几小时 # 获取当前时间与下一周周一早上4点的时间差, 转换为几天几小时
now = datetime.now() now = datetime.now()
next_monday = now + timedelta(days=-now.weekday(), weeks=1) next_monday = now + timedelta(days=-now.weekday(), weeks=1)
next_monday = next_monday.replace(hour=4, minute=0, second=0, microsecond=0) next_monday = next_monday.replace(hour=4, minute=0, second=0, microsecond=0)
@ -364,7 +364,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
# routine daily check # routine daily check
routine_daily = player_info.routine.daily routine_daily = player_info.routine.daily
# 获取当前时间与下一天早上4点的时间差转换为几小时几分钟 # 获取当前时间与下一天早上4点的时间差, 转换为几小时几分钟
now = datetime.now() now = datetime.now()
next_day = now + timedelta(days=1) next_day = now + timedelta(days=1)
next_day = next_day.replace(hour=4, minute=0, second=0, microsecond=0) next_day = next_day.replace(hour=4, minute=0, second=0, microsecond=0)
@ -401,7 +401,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
# routine weekly check # routine weekly check
routine_weekly = player_info.routine.weekly routine_weekly = player_info.routine.weekly
# 获取当前时间与下一周周一早上4点的时间差转换为几天几小时 # 获取当前时间与下一周周一早上4点的时间差, 转换为几天几小时
now = datetime.now() now = datetime.now()
next_monday = now + timedelta(days=-now.weekday(), weeks=1) next_monday = now + timedelta(days=-now.weekday(), weeks=1)
next_monday = next_monday.replace(hour=4, minute=0, second=0, microsecond=0) next_monday = next_monday.replace(hour=4, minute=0, second=0, microsecond=0)
@ -440,7 +440,7 @@ async def draw_ap_img(uid: str) -> Image.Image:
tower_reward = player_info.tower.reward tower_reward = player_info.tower.reward
higher_item = tower_reward.higherItem higher_item = tower_reward.higherItem
term_ts = tower_reward.termTs term_ts = tower_reward.termTs
# 获取当前时间与 termTs 的时间差转换为几天几小时 # 获取当前时间与 termTs 的时间差, 转换为几天几小时
now = datetime.now() now = datetime.now()
term_ts = datetime.fromtimestamp(term_ts) term_ts = datetime.fromtimestamp(term_ts)
delta = term_ts - now delta = term_ts - now

View File

@ -7,17 +7,17 @@ from ..utils.database.models import ArknightsPush, ArknightsUser
from ..utils.models.skland.models import ArknightsPlayerInfoModel from ..utils.models.skland.models import ArknightsPlayerInfoModel
from .utils import now_ap from .utils import now_ap
MR_NOTICE = '\n可发送[arkmr]或者[ark每日]来查看更多信息\n' MR_NOTICE = '\n可发送[arkmr]或者[ark每日]来查看更多信息!\n'
NOTICE = { NOTICE = {
'ap': f'你的理智快满啦{MR_NOTICE}', 'ap': f'你的理智快满啦!{MR_NOTICE}',
'training': f'你的专精即将可收取{MR_NOTICE}', 'training': f'你的专精即将可收取!{MR_NOTICE}',
} }
async def get_notice_list() -> dict[str, dict[str, dict]]: async def get_notice_list() -> dict[str, dict[str, dict]]:
msg_dict: dict[str, dict[str, dict]] = {} msg_dict: dict[str, dict[str, dict]] = {}
for bot_id in gss.active_bot: for _bot_id in gss.active_bot:
user_list = await ArknightsUser.get_all_push_user_list() user_list = await ArknightsUser.get_all_push_user_list()
for user in user_list: for user in user_list:
if user.uid is not None: if user.uid is not None:

View File

@ -21,7 +21,7 @@ async def send_download_resource_msg(bot: Bot, ev: Event):
async def startup(): async def startup():
logger.info('[资源文件下载] 正在检查与下载缺失的资源文件,可能需要较长时间,请稍等') logger.info('[资源文件下载] 正在检查与下载缺失的资源文件, 可能需要较长时间, 请稍等')
await download_all_resource() await download_all_resource()
logger.info('[资源文件下载] 检查完毕, 正在加载 gamedata') logger.info('[资源文件下载] 检查完毕, 正在加载 gamedata')

View File

@ -22,7 +22,7 @@ async def get_role_img(uid: str):
player_save_path = get_res_path(['ArknightsUID', 'players']) player_save_path = get_res_path(['ArknightsUID', 'players'])
with open(player_save_path / f'{player_info.status.uid}.json', 'wb') as file: with Path.open(player_save_path / f'{player_info.status.uid}.json', 'wb') as file:
file.write(msgjson.format(msgjson.encode(player_info), indent=4)) file.write(msgjson.format(msgjson.encode(player_info), indent=4))
# 放 background # 放 background

View File

@ -42,16 +42,16 @@ async def send_link_uid_msg(bot: Bot, ev: Event):
bot, bot,
data, data,
{ {
0: f'绑定ARK_UID{ark_uid}成功', 0: f'绑定ARK_UID{ark_uid}成功!',
-1: f'ARK_UID{ark_uid}的位数不正确', -1: f'ARK_UID{ark_uid}的位数不正确!',
-2: f'ARK_UID{ark_uid}已经绑定过了', -2: f'ARK_UID{ark_uid}已经绑定过了!',
-3: '你输入了错误的格式!', -3: '你输入了错误的格式!',
}, },
) )
elif '切换' in ev.command: elif '切换' in ev.command:
data = await ArknightsBind.switch_uid_by_game(qid, ev.bot_id, ark_uid) data = await ArknightsBind.switch_uid_by_game(qid, ev.bot_id, ark_uid)
if isinstance(data, list): if isinstance(data, list):
return await bot.send(f'切换ARK_UID{ark_uid}成功') return await bot.send(f'切换ARK_UID{ark_uid}成功!')
else: else:
return await bot.send(f'尚未绑定该ARK_UID{ark_uid}') return await bot.send(f'尚未绑定该ARK_UID{ark_uid}')
else: else:
@ -60,8 +60,8 @@ async def send_link_uid_msg(bot: Bot, ev: Event):
bot, bot,
data, data,
{ {
0: f'删除ARK_UID{ark_uid}成功', 0: f'删除ARK_UID{ark_uid}成功!',
-1: f'该ARK_UID{ark_uid}不在已绑定列表中', -1: f'该ARK_UID{ark_uid}不在已绑定列表中!',
}, },
) )

View File

@ -1,7 +1,7 @@
from ..utils.ark_api import ark_skd_api from ..utils.ark_api import ark_skd_api
from ..utils.database.models import ArknightsBind, ArknightsUser from ..utils.database.models import ArknightsBind, ArknightsUser
ERROR_HINT = '添加失败格式为: skd添加cred Cred 例如: skd添加cred VropL583Sb1hClS5buQ4nSASkDlL8tMT' ERROR_HINT = '添加失败, 格式为: skd添加cred Cred 例如: skd添加cred VropL583Sb1hClS5buQ4nSASkDlL8tMT'
UID_HINT = '添加失败, 请先绑定明日方舟UID' UID_HINT = '添加失败, 请先绑定明日方舟UID'

View File

@ -1,5 +1,5 @@
from copy import deepcopy from copy import deepcopy
from typing import Any, Literal from typing import Any, ClassVar, Literal
import msgspec import msgspec
from aiohttp import ClientSession, ContentTypeError, TCPConnector from aiohttp import ClientSession, ContentTypeError, TCPConnector
@ -12,7 +12,7 @@ from .api import ARK_PLAYER_INFO, ARK_USER_ME
class BaseArkApi: class BaseArkApi:
ssl_verify = True ssl_verify = True
_HEADER = { _HEADER: ClassVar[dict[str, str]] = {
'Host': 'zonai.skland.com', 'Host': 'zonai.skland.com',
'Origin': 'https://www.skland.com', 'Origin': 'https://www.skland.com',
'Referer': 'https://www.skland.com/', 'Referer': 'https://www.skland.com/',
@ -95,9 +95,6 @@ class BaseArkApi:
) as resp: ) as resp:
try: try:
raw_data = await resp.json() raw_data = await resp.json()
with open('test.json', 'w', encoding='utf-8') as f:
import json
json.dump(raw_data, f, ensure_ascii=False, indent=4)
except ContentTypeError: except ContentTypeError:
_raw_data = await resp.text() _raw_data = await resp.text()
raw_data = {'code': -999, 'data': _raw_data} raw_data = {'code': -999, 'data': _raw_data}

View File

@ -1,5 +1,4 @@
import asyncio import asyncio
import os
from pathlib import Path from pathlib import Path
from aiohttp.client import ClientSession from aiohttp.client import ClientSession
@ -9,7 +8,9 @@ from msgspec import json as msgjson
from .download_url import download_file from .download_url import download_file
from .RESOURCE_PATH import RESOURCE_PATH from .RESOURCE_PATH import RESOURCE_PATH
with open( MAX_DOWNLOAD = 10
with Path.open(
Path(__file__).parent / 'resource_map.json', encoding='UTF-8' Path(__file__).parent / 'resource_map.json', encoding='UTF-8'
) as f: ) as f:
resource_map = msgjson.decode( resource_map = msgjson.decode(
@ -48,12 +49,12 @@ async def download_all_file_from_cos():
continue continue
path = Path(RESOURCE_PATH / resource_type / name) path = Path(RESOURCE_PATH / resource_type / name)
if path.exists(): if path.exists():
is_diff = size == os.stat(path).st_size is_diff = size == Path.stat(path).st_size
else: else:
is_diff = True is_diff = True
if ( if (
not path.exists() not path.exists()
or not os.stat(path).st_size or not Path.stat(path).st_size
or not is_diff or not is_diff
): ):
logger.info(f'[cos]开始下载[{resource_type}]_[{name}]...') logger.info(f'[cos]开始下载[{resource_type}]_[{name}]...')
@ -67,10 +68,9 @@ async def download_all_file_from_cos():
) )
) )
# await download_file(url, FILE_TO_PATH[file], name) # await download_file(url, FILE_TO_PATH[file], name)
if len(TASKS) >= 10: if len(TASKS) >= MAX_DOWNLOAD:
await _download(TASKS) await _download(TASKS)
else: await _download(TASKS)
await _download(TASKS)
if temp_num == 0: if temp_num == 0:
im = f'[cos]数据库[{resource_type}]无需下载!' im = f'[cos]数据库[{resource_type}]无需下载!'
else: else:
@ -86,9 +86,8 @@ async def download_all_file_from_cos():
timeout=60, timeout=60,
) )
) )
if len(TASKS) >= 10: if len(TASKS) >= MAX_DOWNLOAD:
await _download(TASKS) await _download(TASKS)
else: await _download(TASKS)
await _download(TASKS)
if count := len(failed_list): if count := len(failed_list):
logger.error(f'[cos]仍有{count}个文件未下载请使用命令 `下载全部资源` 重新下载') logger.error(f'[cos]仍有{count}个文件未下载, 请使用命令 `下载全部资源` 重新下载')

View File

@ -24,7 +24,7 @@ async def download(
* url: `str` * url: `str`
资源下载地址 资源下载地址
* res_type: `str` * res_type: `str`
资源类型`resource``wiki` 资源类型, `resource``wiki`
* resource_type: `str` * resource_type: `str`
资源文件夹名 资源文件夹名
* name: `str` * name: `str`