Skip to content

Commit

Permalink
update pve.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fllesser committed Jan 11, 2025
1 parent f65fa44 commit 058f103
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions nonebot_plugin_fortnite/pve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from .config import data_dir

vb_file = data_dir / "vb.png"
hot_info_1_path = data_dir / 'hot_info_1.png'
container_hidden_xs_path = data_dir / 'container_hidden_xs.png'
hot_info_2_path = data_dir / 'hot_info_2.png'

async def screenshot_vb_img() -> Path:
url = "https://freethevbucks.com/timed-missions"
Expand All @@ -20,22 +23,28 @@ async def screenshot_vb_img() -> Path:
async def take_screenshot(locator, path):
try:
await locator.scroll_into_view_if_needed()
await locator.wait_for_element_state('visible', timeout=5000)
await locator.screenshot(path=path)

# 检查元素内容是否为空
content = await locator.inner_html()
if content.strip(): # 如果内容不为空
await asyncio.wait_for(locator.screenshot(path=path), timeout=5)
else:
logger.warning(f"Locator for {path.name} is empty.")
except Exception:
pass


# 截取第一个 <div class="hot-info">
hot_info_1 = page.locator('div.hot-info').nth(0)
await take_screenshot(hot_info_1, data_dir / 'hot_info_1.png')
await take_screenshot(hot_info_1, hot_info_1_path)

# 截取 <div class="container hidden-xs">
container_hidden_xs = page.locator('div.container.hidden-xs')
await take_screenshot(container_hidden_xs, data_dir / 'container_hidden_xs.png')
await take_screenshot(container_hidden_xs, container_hidden_xs_path)

# 截取第二个 <div class="hot-info">
hot_info_2 = page.locator('div.hot-info').nth(1)
await take_screenshot(hot_info_2, data_dir / 'hot_info_2.png')
await take_screenshot(hot_info_2, hot_info_2_path)

combine_imgs()
finally:
Expand All @@ -48,8 +57,8 @@ def combine_imgs():
try:
# 打开截图文件(如果存在)
images = []
for img_name in ['hot_info_1.png', 'container_hidden_xs.png', 'hot_info_2.png']:
img_path = data_dir / img_name
image_paths = [hot_info_1_path, container_hidden_xs_path, hot_info_2_path]:
for image_path in image_paths:
if img_path.exists():
images.append(Image.open(img_path))

Expand All @@ -71,7 +80,7 @@ def combine_imgs():
# 关闭并删除所有截图文件
for img in images:
img.close()
img_path = data_dir / img.filename
for img_path in image_paths:
if img_path.exists():
img_path.unlink()
img_path.filename.unlink()
combined_image.close()

0 comments on commit 058f103

Please sign in to comment.