refactor: 优化代码格式,提升可读性

This commit is contained in:
Your Name committed 2026-01-15 00:20:17 +08:00
1 parent d36b73d3df
commit ea77c0b501
4 files changed
+71 -31

No files matched your search

+18 -6
View File
@@ -797,7 +797,9 @@ class underlying_operations:
# 优先走 exec-out:只需 1 次 adb 调用;不在手机端落盘,减少 I/O 与卡顿
# 为避免被并发读取到"半写入文件",写入 tmp 后再原子替换。
execout_timeout_sec = float(os.environ.get("ADB_EXECOUT_TIMEOUT_SEC", "10"))
execout_warn_after_sec = float(os.environ.get("ADB_EXECOUT_WARN_AFTER_SEC", "3"))
execout_warn_after_sec = float(
os.environ.get("ADB_EXECOUT_WARN_AFTER_SEC", "3")
)
execout_heartbeat_interval_sec = float(
os.environ.get("ADB_EXECOUT_HEARTBEAT_INTERVAL_SEC", "5")
)
@@ -3098,14 +3100,18 @@ class underlying_operations:
# 先确保输入框获得焦点
try:
try:
print(f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})")
print(
f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})"
)
except Exception:
pass
self.click(device_id, int(x), int(y))
time_module.sleep(0.2)
# 有些输入框第一次点不进,补一次轻点
try:
print(f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})")
print(
f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})"
)
except Exception:
pass
self.click(device_id, int(x), int(y))
@@ -3118,11 +3124,15 @@ class underlying_operations:
try:
ok_adbkb = False
try:
ok_adbkb = bool(self.input_text_adbkeyboard(device_id, t, restore_prev=False))
ok_adbkb = bool(
self.input_text_adbkeyboard(device_id, t, restore_prev=False)
)
except Exception:
ok_adbkb = False
try:
print(f"[Underlying] paste_text_at: input_text_adbkeyboard -> {ok_adbkb}")
print(
f"[Underlying] paste_text_at: input_text_adbkeyboard -> {ok_adbkb}"
)
except Exception:
pass
if ok_adbkb:
@@ -3157,7 +3167,9 @@ class underlying_operations:
# 2) 兜底:adb input text(中文可能不稳定)
try:
print(f"[Underlying] paste_text_at: falling back to input_text for device_id={device_id}")
print(
f"[Underlying] paste_text_at: falling back to input_text for device_id={device_id}"
)
except Exception:
pass
return self.input_text(device_id, t)
+1 -1
View File
@@ -220,4 +220,4 @@
"high_value_room_revisit_max_per_run": 9999,
"high_value_room_revisit_min_prize_value": 1000.0,
"high_value_room_revisit_max_age_days": 1
}
}
+6 -2
View File
@@ -431,7 +431,9 @@ class fudai_analyse:
# method directly cannot bypass the main on/off setting.
if not bool(getattr(self, "yanghao_enabled", True)):
try:
self._log_kv("养号", "_yanghao_recommend_flow skipped - yanghao_enabled=0")
self._log_kv(
"养号", "_yanghao_recommend_flow skipped - yanghao_enabled=0"
)
except Exception:
print("[养号] _yanghao_recommend_flow skipped - yanghao_enabled=0")
return
@@ -503,7 +505,9 @@ class fudai_analyse:
pass
try:
reservation_focus_until = float(getattr(self, "reservation_focus_until_ts", 0.0) or 0.0)
reservation_focus_until = float(
getattr(self, "reservation_focus_until_ts", 0.0) or 0.0
)
if reservation_focus_until > time.time():
# 当前处于预约焦点期,跳过养号
return
+46 -22
View File
@@ -322,10 +322,12 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
# 仅在爱心和收藏都实际触发(都被点击)时才考虑评论
# 记录评论是否实际执行
did_comment = False
if did_like and did_fav and float(
getattr(analyser, "yanghao_comment_prob", 0) or 0
) > 0 and random.random() < float(
getattr(analyser, "yanghao_comment_prob", 0) or 0
if (
did_like
and did_fav
and float(getattr(analyser, "yanghao_comment_prob", 0) or 0) > 0
and random.random()
< float(getattr(analyser, "yanghao_comment_prob", 0) or 0)
):
_do_comment(analyser)
did_comment = True
@@ -392,14 +394,22 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
analyser.operation.delay(2)
# 点击直播按钮(备用坐标)
fallback_x = int(getattr(analyser, "yanghao_fallback_live_x", 540) or 540)
fallback_y = int(getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000)
fallback_x = int(
getattr(analyser, "yanghao_fallback_live_x", 540) or 540
)
fallback_y = int(
getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000
)
analyser.operation.click(analyser.device_id, fallback_x, fallback_y)
analyser.operation.delay(1.5)
# 点击进入直播间(备用坐标)
enter_x = int(getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540)
enter_y = int(getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200)
enter_x = int(
getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540
)
enter_y = int(
getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200
)
analyser.operation.click(analyser.device_id, enter_x, enter_y)
analyser.operation.delay(0.6)
analyser.operation.click(analyser.device_id, enter_x, enter_y)
@@ -493,48 +503,62 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
try:
# 获取前台包名
top_pkg = analyser.operation.get_top_package(analyser.device_id) or ""
# 检查是否在抖音前台
is_douyin_pkg = top_pkg and (
"aweme" in top_pkg
or "douyin" in top_pkg
or "com.ss.android.ugc" in top_pkg
)
if top_pkg and not is_douyin_pkg:
print(f"[养号] 自救: 检测到不在抖音前台,前台包名={top_pkg}")
# 执行自救操作
try:
# 点击桌面图标
desktop_x = int(getattr(analyser, "desktop_icon_x", 153) or 153)
desktop_y = int(getattr(analyser, "desktop_icon_y", 260) or 260)
analyser.operation.click(analyser.device_id, desktop_x, desktop_y)
analyser.operation.click(
analyser.device_id, desktop_x, desktop_y
)
analyser.operation.delay(2)
# 点击直播按钮(备用坐标)
fallback_x = int(getattr(analyser, "yanghao_fallback_live_x", 540) or 540)
fallback_y = int(getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000)
analyser.operation.click(analyser.device_id, fallback_x, fallback_y)
fallback_x = int(
getattr(analyser, "yanghao_fallback_live_x", 540) or 540
)
fallback_y = int(
getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000
)
analyser.operation.click(
analyser.device_id, fallback_x, fallback_y
)
analyser.operation.delay(1.5)
# 点击进入直播间(备用坐标)
enter_x = int(getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540)
enter_y = int(getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200)
enter_x = int(
getattr(analyser, "yanghao_fallback_enter_live_x", 540)
or 540
)
enter_y = int(
getattr(analyser, "yanghao_fallback_enter_live_y", 1200)
or 1200
)
analyser.operation.click(analyser.device_id, enter_x, enter_y)
analyser.operation.delay(0.6)
analyser.operation.click(analyser.device_id, enter_x, enter_y)
analyser.operation.delay(2.0)
print("[养号] 自救: 恢复操作完成")
return True
except Exception as e:
print(f"[养号] 自救: 恢复操作失败: {e}")
return False
else:
return False
except Exception as e:
print(f"[养号] 自救: 桌面检测异常: {e}")
return False