Merge pull request #1258 from McElaga/main

细节优化,原神今日素材重写
This commit is contained in:
HibiKier 2023-02-18 22:56:43 +08:00 committed by GitHub
commit 40c10e672c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 61 deletions

View File

@ -228,7 +228,6 @@ class HelpImageBuild:
for msg in [ for msg in [
"目前支持的功能列表:", "目前支持的功能列表:",
"可以通过 ‘帮助[功能名称] 来获取对应功能的使用方法", "可以通过 ‘帮助[功能名称] 来获取对应功能的使用方法",
"或者使用 ‘详细帮助’ 来获取所有功能方法",
]: ]:
text = BuildImage( text = BuildImage(
0, 0,

View File

@ -15,7 +15,7 @@ from utils.browser import get_browser
from utils.image_utils import BuildImage from utils.image_utils import BuildImage
from utils.message_builder import image from utils.message_builder import image
__zx_plugin_name__ = "原神今日素材" __zx_plugin_name__ = "今日素材"
__plugin_usage__ = """ __plugin_usage__ = """
usage usage
看看原神今天要刷什么 看看原神今天要刷什么
@ -57,8 +57,8 @@ async def _(event: MessageEvent):
await update_image() await update_image()
await material.send( await material.send(
Message( Message(
image(IMAGE_PATH / "genshin" / "material" / f"{file_name}.png") image(f"{file_name}.png", "genshin/material")
+ "\n※ 每日素材数据来源于 genshin.pub" + "\n※ 每日素材数据来源于米游社"
) )
) )
logger.info( logger.info(
@ -87,63 +87,14 @@ async def update_image():
if not browser: if not browser:
logger.warning("获取 browser 失败,请部署至 linux 环境....") logger.warning("获取 browser 失败,请部署至 linux 环境....")
return False return False
url = "https://genshin.pub/daily" # url = "https://genshin.pub/daily"
page = await browser.new_page() url = "https://bbs.mihoyo.com/ys/obc/channel/map/193"
await page.goto(url, wait_until="networkidle", timeout=10000) page = await browser.new_page(viewport={'width': 860, 'height': 3000})
await page.set_viewport_size({"width": 2560, "height": 1080}) await page.goto(url)
await page.evaluate( await page.wait_for_timeout(3000)
"""
document.getElementsByClassName('GSTitleBar_gs_titlebar__2IJqy')[0].remove();
e = document.getElementsByClassName('GSContainer_gs_container__2FbUz')[0];
e.setAttribute("style", "height:880px");
"""
)
await page.click("button")
div = await page.query_selector(".GSContainer_content_box__1sIXz")
for i, card in enumerate(
await page.query_selector_all(".GSTraitCotainer_trait_section__1f3bc")
):
index = 0
type_ = "char" if not i else "weapons"
for x in await card.query_selector_all("xpath=child::*"):
await x.screenshot(
path=f"{IMAGE_PATH}/genshin/material/{type_}_{index}.png",
timeout=100000,
)
# 下滑两次
for _ in range(3):
await div.press("PageDown")
index += 1
# 结束后上滑至顶
for _ in range(index * 3):
await div.press("PageUp")
file_list = os.listdir(f"{IMAGE_PATH}/genshin/material")
char_img = [
f"{IMAGE_PATH}/genshin/material/{x}"
for x in file_list
if x.startswith("char")
]
weapons_img = [
f"{IMAGE_PATH}/genshin/material/{x}"
for x in file_list
if x.startswith("weapons")
]
char_img.sort()
weapons_img.sort()
height = await asyncio.get_event_loop().run_in_executor(
None, get_background_height, weapons_img
)
background_img = BuildImage(1200, height + 100, color="#f6f2ee")
current_width = 50
for img_list in [char_img, weapons_img]:
current_height = 20
for img in img_list:
x = BuildImage(0, 0, background=img)
background_img.paste(x, (current_width, current_height))
current_height += x.size[1]
current_width += 600
file_name = str((datetime.now() - timedelta(hours=4)).date()) file_name = str((datetime.now() - timedelta(hours=4)).date())
background_img.save(f"{IMAGE_PATH}/genshin/material/{file_name}.png") # background_img.save(f"{IMAGE_PATH}/genshin/material/{file_name}.png")
await page.locator('//*[@id="__layout"]/div/div[2]/div[2]/div/div[1]/div[2]/div/div').screenshot(path=f"{IMAGE_PATH}/genshin/material/{file_name}.png")
await page.close() await page.close()
return True return True
except Exception as e: except Exception as e:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -13,7 +13,7 @@
<div class="transition"></div> <div class="transition"></div>
<div class="wrapper"> <div class="wrapper">
<main class="des"> <main class="des">
<p>可以通过 ‘帮助[功能名称] 来获取对应功能的使用方法。&nbsp;&nbsp;&nbsp;或者使用 ‘详细帮助’ 来获取所有功能方法。</p> <p>可以通过 ‘帮助[功能名称] 来获取对应功能的使用方法。</p>
<p style="color:red;">注:横线字功能被群管理员禁用,浅色字代表功能正在维护&nbsp;&nbsp;&nbsp;&nbsp;真寻机器人免费开源,如果你在任何渠道付费购买了真寻机器人,请退款。</p> <p style="color:red;">注:横线字功能被群管理员禁用,浅色字代表功能正在维护&nbsp;&nbsp;&nbsp;&nbsp;真寻机器人免费开源,如果你在任何渠道付费购买了真寻机器人,请退款。</p>
</main> </main>
<div class="content"> <div class="content">