feat: 更多的字体

This commit is contained in:
2024-04-05 07:02:18 +08:00
parent 813f1c2ded
commit c5d2c040fe
37 changed files with 485 additions and 158 deletions

View File

@ -31,6 +31,21 @@ from nonebot_plugin_htmlrender import *
# """
# return await html_to_pic(html, wait=wait, template_path=template_path, scale_factor=scale_factor)
async def template2html(
template: str,
templates: dict,
) -> str:
"""
Args:
template: str: 模板文件
**templates: dict: 模板参数
Returns:
HTML 正文
"""
template_path = os.path.dirname(template)
template_name = os.path.basename(template)
return await template_to_html(template_path, template_name, **templates)
async def template2image(
template: str,
@ -81,3 +96,32 @@ async def template2image(
wait=wait,
device_scale_factor=scale_factor,
)
async def url2image(
url: str,
wait: int = 0,
scale_factor: float = 1,
type: str = "png",
quality: int = 100,
**kwargs
) -> bytes:
"""
Args:
quality:
type:
url: str: URL
wait: int: 等待时间
scale_factor: float: 缩放因子
**kwargs: page 参数
Returns:
图片二进制数据
"""
async with get_new_page(scale_factor) as page:
await page.goto(url)
await page.wait_for_timeout(wait)
return await page.screenshot(
full_page=True,
type=type,
quality=quality
)

View File

@ -67,8 +67,8 @@ def init_log():
warning = lang.get("log.warning", default="WARNING")
error = lang.get("log.error", default="==ERROR")
logger.level("DEBUG", color="<blue>", icon=f"{'*️⃣' if show_icon else ''}{debug}")
logger.level("INFO", color="<white>", icon=f"{'' if show_icon else ''}{info}")
logger.level("DEBUG", color="<blue>", icon=f"{'🐛' if show_icon else ''}{debug}")
logger.level("INFO", color="<normal>", icon=f"{'' if show_icon else ''}{info}")
logger.level("SUCCESS", color="<green>", icon=f"{'' if show_icon else ''}{success}")
logger.level("WARNING", color="<yellow>", icon=f"{'⚠️' if show_icon else ''}{warning}")
logger.level("ERROR", color="<red>", icon=f"{'' if show_icon else ''}{error}")

View File

@ -15,13 +15,13 @@ def clamp(value: float, min_value: float, max_value: float) -> float | int:
return max(min(value, max_value), min_value)
def convert_size(size: int, precision: int = 2, add_unit: bool = True, suffix: str = "iB") -> str:
def convert_size(size: int, precision: int = 2, add_unit: bool = True, suffix: str = " XiB") -> str | float:
"""把字节数转换为人类可读的字符串,计算正负
Args:
add_unit: 是否添加单位False后则suffix无效
suffix: iB或B
suffix: XiB或XB
precision: 浮点数的小数点位数
size (int): 字节数
@ -29,23 +29,18 @@ def convert_size(size: int, precision: int = 2, add_unit: bool = True, suffix: s
str: The human-readable string, e.g. "1.23 GB".
"""
is_negative = False
if size < 0:
is_negative = True
size = -size
for unit in ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]:
is_negative = size < 0
size = abs(size)
for unit in ("", "K", "M", "G", "T", "P", "E", "Z"):
if size < 1024:
if add_unit:
result = f"{size:.{precision}f} {unit}" + suffix
return f"-{result}" if is_negative else result
else:
return f"{size:.{precision}f}"
break
size /= 1024
if is_negative:
size = -size
if add_unit:
return f"{size:.{precision}f} Y" + suffix
return f"{size:.{precision}f}{suffix.replace('X', unit)}"
else:
return f"{size:.{precision}f}"
return size
def keywords_in_text(keywords: list[str], text: str, all_matched: bool) -> bool: