feat: 优化代码格式,提升可读性和一致性
This commit is contained in:
1 parent
68295e564e
commit
c6eb76845f
7 files changed
+82
-36
No files matched your search
@@ -2318,7 +2318,9 @@ class fudai_analyse:
|
||||
self.operation.delay(self.ENTER_LIVE_CLICK_DELAY)
|
||||
# 小延迟,避免界面卡顿导致第二次点击未生效
|
||||
try:
|
||||
self.operation.delay(getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
self.operation.delay(
|
||||
getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
self.operation.delay(0.8)
|
||||
self.operation.click(self.device_id, enter_live_x, enter_live_y)
|
||||
@@ -2332,7 +2334,9 @@ class fudai_analyse:
|
||||
# 进入后等待(保留原有最终等待)
|
||||
try:
|
||||
# 小延迟,确保界面就绪(可配置)
|
||||
self.operation.delay(getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
self.operation.delay(
|
||||
getattr(self, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
self.operation.delay(0.8)
|
||||
self.operation.delay(self.ENTER_LIVE_FINAL_DELAY)
|
||||
|
||||
@@ -250,7 +250,9 @@ class SwipeHandler:
|
||||
|
||||
# 小延迟,避免卡顿导致下一步截图/判断失败
|
||||
try:
|
||||
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
analyser.operation.delay(
|
||||
getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
analyser.operation.delay(0.8)
|
||||
|
||||
@@ -290,7 +292,9 @@ class SwipeHandler:
|
||||
# 标记:本轮处于重置/回退流程中,防止其他路径触发返回键退出
|
||||
try:
|
||||
setattr(analyser, "_recent_reset_ts", time.time())
|
||||
setattr(analyser, "_recent_reset_by", "reset_after_swipes_swipe")
|
||||
setattr(
|
||||
analyser, "_recent_reset_by", "reset_after_swipes_swipe"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 向上回退:从上往下滑动(start_y < end_y)
|
||||
@@ -329,7 +333,9 @@ class SwipeHandler:
|
||||
# 注意:这里使用 ADB 直调绕过了 operation.swipe,需要手动标记页面已变化
|
||||
try:
|
||||
if hasattr(analyser.operation, "_mark_screen_dirty"):
|
||||
analyser.operation._mark_screen_dirty(analyser.device_id)
|
||||
analyser.operation._mark_screen_dirty(
|
||||
analyser.device_id
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
@@ -397,7 +403,9 @@ class SwipeHandler:
|
||||
|
||||
# 小延迟,等待页面卡顿恢复再点击进入
|
||||
try:
|
||||
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
analyser.operation.delay(
|
||||
getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
analyser.operation.delay(0.8)
|
||||
|
||||
@@ -412,7 +420,9 @@ class SwipeHandler:
|
||||
|
||||
# 点击间隔稍微加长,避免卡顿导致第二次点击未生效
|
||||
try:
|
||||
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
analyser.operation.delay(
|
||||
getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
analyser.operation.delay(0.8)
|
||||
|
||||
|
||||
@@ -888,12 +888,16 @@ def yanghao_check_and_recover_from_desktop(analyser) -> bool:
|
||||
print(f"[养号] 点击进入直播间 -> ({ex},{ey}) 连点两次")
|
||||
analyser.click(ex, ey)
|
||||
try:
|
||||
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
analyser.operation.delay(
|
||||
getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
analyser.operation.delay(0.8)
|
||||
analyser.click(ex, ey)
|
||||
try:
|
||||
analyser.operation.delay(getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 2.0))
|
||||
analyser.operation.delay(
|
||||
getattr(analyser, "ENTER_LIVE_FINAL_DELAY", 2.0)
|
||||
)
|
||||
except Exception:
|
||||
analyser.operation.delay(2.0)
|
||||
except Exception:
|
||||
@@ -967,7 +971,9 @@ def yanghao_recommend_flow(analyser, total_seconds: int) -> None:
|
||||
print("[养号] step5: 坐标点击进入直播间 -> ({},{}) 连点两次".format(ex, ey))
|
||||
analyser.click(ex, ey)
|
||||
try:
|
||||
analyser.operation.delay(getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8))
|
||||
analyser.operation.delay(
|
||||
getattr(analyser, "RETURN_STEP_DELAY_SECONDS", 0.8)
|
||||
)
|
||||
except Exception:
|
||||
analyser.operation.delay(0.8)
|
||||
analyser.click(ex, ey)
|
||||
|
||||
+6
-2
@@ -2484,12 +2484,16 @@ def main():
|
||||
if "耗时" not in line:
|
||||
return None
|
||||
# 尝试提取耗时数字
|
||||
m = re.search(r"耗时[:=]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*s", line)
|
||||
m = re.search(
|
||||
r"耗时[:=]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*s", line
|
||||
)
|
||||
dur = None
|
||||
if m:
|
||||
dur = m.group(1) + "s"
|
||||
else:
|
||||
m2 = re.search(r"([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*s", line)
|
||||
m2 = re.search(
|
||||
r"([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*s", line
|
||||
)
|
||||
if m2:
|
||||
dur = m2.group(1) + "s"
|
||||
|
||||
|
||||
+13
-4
@@ -293,7 +293,9 @@ class Runner:
|
||||
s,
|
||||
)
|
||||
if not m:
|
||||
m = re.search(r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s)
|
||||
m = re.search(
|
||||
r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
with self._lock:
|
||||
@@ -421,13 +423,17 @@ class Runner:
|
||||
self._inc("fudai_skip_value_low")
|
||||
# 提取实际价值和阈值
|
||||
meta = self._snapshot_fudai()
|
||||
m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["prize_value_yuan"] = float(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
m = re.search(r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["threshold"] = float(m.group(1))
|
||||
@@ -483,7 +489,10 @@ class Runner:
|
||||
self._inc("fudai_reserved_high_value")
|
||||
# 提取价值和倒计时信息
|
||||
meta = self._snapshot_fudai()
|
||||
m = re.search(r"(?:价值|价值元)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"(?:价值|价值元)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)",
|
||||
s,
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["prize_value_yuan"] = float(m.group(1))
|
||||
|
||||
+19
-6
@@ -354,7 +354,9 @@ class ProcRunner:
|
||||
s,
|
||||
)
|
||||
if not m:
|
||||
m = re.search(r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s)
|
||||
m = re.search(
|
||||
r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
self._fudai_last["prize_value_yuan"] = float(m.group(1))
|
||||
@@ -430,13 +432,17 @@ class ProcRunner:
|
||||
self._inc("fudai_skip_value_low")
|
||||
# 提取实际价值和阈值
|
||||
meta = self._snapshot_fudai()
|
||||
m = re.search(r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["prize_value_yuan"] = float(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
m = re.search(r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["threshold"] = float(m.group(1))
|
||||
@@ -768,13 +774,17 @@ class ProcRunner:
|
||||
m = re.search(r"阶段[=:]?\s*(\w+)", s)
|
||||
if m:
|
||||
meta["stage"] = m.group(1)
|
||||
m = re.search(r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒", s)
|
||||
m = re.search(
|
||||
r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["elapsed_seconds"] = float(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
m = re.search(r"分数[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"分数[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
meta["score"] = float(m.group(1))
|
||||
@@ -794,7 +804,9 @@ class ProcRunner:
|
||||
self._inc("ocr_failed")
|
||||
|
||||
# --- 性能统计 ---
|
||||
m = re.search(r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒", s)
|
||||
m = re.search(
|
||||
r"耗时[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*秒", s
|
||||
)
|
||||
if m:
|
||||
try:
|
||||
elapsed = float(m.group(1))
|
||||
@@ -1899,6 +1911,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
self.send_error(HTTPStatus.NOT_FOUND)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
host = "127.0.0.1"
|
||||
# 支持 PORT / WEB_GUI_PORT 两种环境变量,默认 8000
|
||||
|
||||
+14
-14
@@ -1,18 +1,18 @@
|
||||
from douyin.utils.douyin_utils import extract_prize_value_yuan
|
||||
|
||||
tests=[
|
||||
'¥12.34',
|
||||
'¥12·34',
|
||||
'¥12.34',
|
||||
'¥12.34',
|
||||
'12.34元',
|
||||
'12,345.67',
|
||||
'¥O2.5O',
|
||||
'¥1O.5',
|
||||
'价值:12.5',
|
||||
'价值12。5',
|
||||
'价值12·5',
|
||||
'随机文本 0.5 元',
|
||||
tests = [
|
||||
"¥12.34",
|
||||
"¥12·34",
|
||||
"¥12.34",
|
||||
"¥12.34",
|
||||
"12.34元",
|
||||
"12,345.67",
|
||||
"¥O2.5O",
|
||||
"¥1O.5",
|
||||
"价值:12.5",
|
||||
"价值12。5",
|
||||
"价值12·5",
|
||||
"随机文本 0.5 元",
|
||||
]
|
||||
for t in tests:
|
||||
print(t, '->', extract_prize_value_yuan(t))
|
||||
print(t, "->", extract_prize_value_yuan(t))
|
||||
Reference in new issue
Block a user