'commit'
This commit is contained in:
@@ -4,7 +4,9 @@ import logging
|
||||
import os
|
||||
import time
|
||||
import uiautomator2 as u2
|
||||
import uuid
|
||||
from Apps.AiTeJiYiChong.Kit import click_image_template, take_screenshot
|
||||
from Apps.AiTeJiYiChong.ReadImageKit import ReadImageKit
|
||||
from Config.Config import TEMP_IMAGE_DIR
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -15,6 +17,45 @@ logger = logging.getLogger("OpenAiTeJiYiChong")
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
async def check_and_close_ad(d):
|
||||
"""
|
||||
检测并关闭广告弹窗(循环检测直至无广告)
|
||||
"""
|
||||
max_loops = 3 # 最大检测 3 轮,防止死循环
|
||||
device_info = d.info
|
||||
w, h = d.window_size()
|
||||
device_info['displayWidth'] = w
|
||||
device_info['displayHeight'] = h
|
||||
|
||||
for loop_idx in range(max_loops):
|
||||
logger.info(f"开始第 {loop_idx + 1} 轮广告检测...")
|
||||
|
||||
image_uuid = f"ad_check_{int(time.time())}"
|
||||
screenshot_path = take_screenshot(d, image_uuid, save_dir=TEMP_IMAGE_DIR)
|
||||
|
||||
ad_result = await ReadImageKit.detect_ad_popup(screenshot_path, device_info=device_info)
|
||||
|
||||
if ad_result:
|
||||
x, y = ad_result['x'], ad_result['y']
|
||||
ad_type = ad_result.get("ad_type", "unknown")
|
||||
logger.info(f"检测到广告 [{ad_type}],坐标: ({x}, {y}),执行关闭操作...")
|
||||
|
||||
if ad_type == "rabbit":
|
||||
# 针对“兔子”广告的特殊处理
|
||||
d.double_click(x, y, duration=0.05)
|
||||
else:
|
||||
d.click(x, y)
|
||||
|
||||
await asyncio.sleep(2.0)
|
||||
|
||||
# 清理截图并继续下一轮检测
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
else:
|
||||
logger.info("未检测到广告弹窗。")
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
break
|
||||
return True
|
||||
|
||||
async def open_mini_program():
|
||||
"""
|
||||
异步形式的进入微信小程序: 艾特吉易充
|
||||
@@ -48,6 +89,10 @@ async def open_mini_program():
|
||||
logger.info("已点击搜索结果第一项")
|
||||
|
||||
await asyncio.sleep(8)
|
||||
|
||||
# 5. 进入后的广告检测 (只在进入时执行一次)
|
||||
await check_and_close_ad(d)
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user