refactor(coords): 提取点击坐标常量,消除硬编码
在 coords.py 添加 DETAIL_OUTSIDE_CLICK、PARTICIPATE_BTN_CLICK、 FANSCLUB_JOIN_CLICK、FANSCLUB_JOIN_FALLBACK_CLICK 常量, 替换 fudai_attend/fansclub_handler/join_decision 中的硬编码坐标。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d19d5bfc56
commit
c4544489ac
4 files changed
+35
-19
No files matched your search
@@ -63,7 +63,18 @@ ROBOT_VERIFY = (100, 1200, 980, 1780)
|
||||
# 诊断购物红包(弹窗快速检测区域 - 文字区域)
|
||||
DIAG_SHOPPING_REDPACKET = (200, 300, 880, 1000)
|
||||
|
||||
|
||||
# 倒计时、任务、按钮等常用区域(保留占位,可根据需要填写)
|
||||
# COUNTDOWN_BOX = (390, 1140, 570, 1290)
|
||||
# BUTTON_BOX = (306, 2030, 780, 2180)
|
||||
# CONTENT_BOX = (200, 600, 880, 900)
|
||||
|
||||
# 点击坐标常量(基准分辨率 1080x2400)
|
||||
# 关闭详情页:点击详情页旁边空白区域
|
||||
DETAIL_OUTSIDE_CLICK = (500, 470)
|
||||
# 参与抽奖按钮
|
||||
PARTICIPATE_BTN_CLICK = (543, 2070)
|
||||
# 粉丝团加入按钮
|
||||
FANSCLUB_JOIN_CLICK = (540, 2006)
|
||||
# 粉丝团加入按钮(回退坐标)
|
||||
FANSCLUB_JOIN_FALLBACK_CLICK = (500, 2060)
|
||||
@@ -11,6 +11,8 @@ from typing import Any
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
from .coords import DETAIL_OUTSIDE_CLICK, PARTICIPATE_BTN_CLICK
|
||||
|
||||
|
||||
def attend_choujiang(analyser) -> bool:
|
||||
"""点击参与抽奖。"""
|
||||
@@ -149,7 +151,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return False
|
||||
|
||||
@@ -168,7 +170,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return False
|
||||
elif (
|
||||
@@ -281,7 +283,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
analyser.click(500, 470) # 点击刚才打开福袋的旁边位置
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK) # 点击刚才打开福袋的旁边位置
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return True
|
||||
elif attend_button_text and (
|
||||
@@ -317,7 +319,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
analyser.operation.delay(0.5)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
@@ -337,7 +339,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return False
|
||||
elif attend_button_text and "无法参与" in attend_button_text:
|
||||
@@ -353,7 +355,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return False
|
||||
elif attend_button_text and "时长不足" in attend_button_text:
|
||||
@@ -369,13 +371,13 @@ def attend_choujiang(analyser) -> bool:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return False
|
||||
elif attend_button_text and "评论" in attend_button_text:
|
||||
# 基于截图优化坐标:OCR区域(306,2030)-(780,2110),尺寸474x80
|
||||
# 区域中心X = (306+780)/2 = 543,Y = (2030+2110)/2 = 2070
|
||||
analyser.click(543, 2070)
|
||||
analyser.click(*PARTICIPATE_BTN_CLICK)
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"点击参与抽奖(基于截图优化坐标)",
|
||||
@@ -400,7 +402,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
elif attend_button_text and "参与抽奖" in attend_button_text:
|
||||
# 基于截图优化坐标:OCR区域(306,2030)-(780,2110),尺寸474x80
|
||||
# 区域中心X = (306+780)/2 = 543,Y = (2030+2110)/2 = 2070
|
||||
analyser.click(543, 2070)
|
||||
analyser.click(*PARTICIPATE_BTN_CLICK)
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"点击参与抽奖(基于截图优化坐标)",
|
||||
@@ -527,7 +529,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
elif attend_button_text and "开始观看" in attend_button_text:
|
||||
# 基于截图优化坐标:OCR区域(306,2030)-(780,2110),尺寸474x80
|
||||
# 区域中心X = (306+780)/2 = 543,Y = (2030+2110)/2 = 2070
|
||||
analyser.click(543, 2070)
|
||||
analyser.click(*PARTICIPATE_BTN_CLICK)
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"点击开始观看(基于截图优化坐标)",
|
||||
@@ -540,7 +542,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
elif attend_button_text and "参与" in attend_button_text:
|
||||
# 基于截图优化坐标:OCR区域(306,2030)-(780,2110),尺寸474x80
|
||||
# 区域中心X = (306+780)/2 = 543,Y = (2030+2110)/2 = 2070
|
||||
analyser.click(543, 2070)
|
||||
analyser.click(*PARTICIPATE_BTN_CLICK)
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"点击参与(基于截图优化坐标)",
|
||||
|
||||
@@ -13,6 +13,8 @@ from typing import Any
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
from douyin.fudai.core.coords import DETAIL_OUTSIDE_CLICK, PARTICIPATE_BTN_CLICK, FANSCLUB_JOIN_CLICK, FANSCLUB_JOIN_FALLBACK_CLICK
|
||||
|
||||
|
||||
def handle_fansclub_branch(analyser: Any, attend_button_text: str) -> bool:
|
||||
"""处理"需要粉丝团门槛"分支:先点参与按钮 → OCR 找加入粉丝团按钮 → 点击 → 关闭详情 → 等待 → 恢复 → 返回 True。"""
|
||||
@@ -54,7 +56,7 @@ def handle_fansclub_branch(analyser: Any, attend_button_text: str) -> bool:
|
||||
pass
|
||||
|
||||
# 第一步:先点击参与按钮(基于OCR区域中心:OCR区域(306,2030)-(780,2110),区域中心(543, 2070))
|
||||
analyser.click(543, 2070)
|
||||
analyser.click(*PARTICIPATE_BTN_CLICK)
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"粉丝团门槛:先点击参与按钮",
|
||||
@@ -306,7 +308,7 @@ def handle_fansclub_branch(analyser: Any, attend_button_text: str) -> bool:
|
||||
analyser._log_kv("参与", "点击加入粉丝团按钮失败", error=str(e))
|
||||
|
||||
# 第三步:关闭详情页
|
||||
analyser.click(500, 470) # 点击详情页旁边位置关闭详情页
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK) # 点击详情页旁边位置关闭详情页
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
|
||||
if not analyser.auto_join_fansclub:
|
||||
@@ -627,11 +629,11 @@ def handle_fansclub_branch(analyser: Any, attend_button_text: str) -> bool:
|
||||
except Exception:
|
||||
# 如果新坐标失败,回退到优化后的坐标(粉丝团加入按钮)
|
||||
try:
|
||||
analyser.click(540, 2006) # 粉丝团加入按钮优化坐标
|
||||
analyser.click(*FANSCLUB_JOIN_CLICK) # 粉丝团加入按钮优化坐标
|
||||
except Exception:
|
||||
# 最后回退到旧坐标
|
||||
try:
|
||||
analyser.click(500, 2060)
|
||||
analyser.click(*FANSCLUB_JOIN_FALLBACK_CLICK)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -686,7 +688,7 @@ def handle_fansclub_branch(analyser: Any, attend_button_text: str) -> bool:
|
||||
analyser.operation.delay(1.0) # 等待点击完成
|
||||
|
||||
# 关闭详情页
|
||||
analyser.click(500, 470) # 点击详情页旁边位置关闭详情页
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK) # 点击详情页旁边位置关闭详情页
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
analyser.operation.delay(1.0) # 等待关闭完成
|
||||
except Exception as e:
|
||||
|
||||
@@ -12,6 +12,7 @@ from typing import Any, Tuple
|
||||
|
||||
from .helpers import _is_short_countdown_text, is_watch_task_fudai
|
||||
from .should_skip import should_skip_fudai_by_config
|
||||
from douyin.fudai.core.coords import DETAIL_OUTSIDE_CLICK
|
||||
|
||||
|
||||
def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
|
||||
@@ -275,7 +276,7 @@ def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
|
||||
pass
|
||||
# 关闭详情页
|
||||
try:
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
@@ -414,7 +415,7 @@ def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
|
||||
pass
|
||||
# 关闭详情页
|
||||
try:
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
@@ -518,7 +519,7 @@ def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
|
||||
pass
|
||||
# 丢弃时,尽量关闭详情,避免停留在详情页
|
||||
try:
|
||||
analyser.click(500, 470)
|
||||
analyser.click(*DETAIL_OUTSIDE_CLICK)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
|
||||
Reference in new issue
Block a user