feat: 更新筛选逻辑,添加按钮文本记录和条件跳过原因,优化日志记录

This commit is contained in:
Your Name committed 2026-01-16 19:58:19 +08:00
1 parent ca77862a86
commit 44519f2f6b
5 files changed
+229 -196

No files matched your search

+2 -2
View File
@@ -70,7 +70,7 @@
"fudai_quiet_hours_enabled": true,
"fudai_quiet_start_hour": 2,
"fudai_quiet_end_hour": 9,
"yanghao_enabled": true,
"yanghao_enabled": false,
"yanghao_enable_actions": true,
"yanghao_like_icon_x": 988,
"yanghao_like_icon_y": 1218,
@@ -201,7 +201,7 @@
"log_on_complete": false
},
"fudai_detail_template_threshold": 0.52,
"switch_room_wait_after_stage_diag_seconds": 7.0,
"switch_room_wait_after_stage_diag_seconds": 7.5,
"coupon_template_match_threshold": 0.35,
"attend_button_red_ratio_threshold": 0.25,
"fansclub_join_red_ratio_threshold": 0.25,
+80 -99
View File
@@ -143,6 +143,7 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
elapsed_seconds=round(elapsed, 2),
)
return True, "watch_task_detected"
time_text = str(detail[1] or "")
try:
participants = int(detail[2] or 0)
@@ -227,6 +228,9 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
except Exception:
skip_if_lt = 0
# 获取按钮文本,用于记录
button_text = str(getattr(analyser, "button_text_raw", "") or "").strip()
# 记录所有配置值和实际值,便于调试
try:
analyser._log_kv(
@@ -242,25 +246,29 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
实际_份数=copies,
实际_剩余秒数=int(remain_seconds) if remain_seconds is not None else None,
实际_内容=content[:60] if content else "",
按钮文本=button_text if button_text else "未识别",
)
except Exception:
pass
# 并行检查所有筛选条件,收集所有不符合的原因
skip_reasons = []
# 1) 价值过滤
if min_value > 0:
if prize_value_yuan > 0:
if prize_value_yuan < min_value:
skip_reasons.append(f"value_lt_{min_value}")
try:
analyser._log_kv(
"筛选",
"价值过滤:丢弃",
原因=f"value_lt_{min_value}",
"价值过滤:不符合(价值过低)",
实际价值=prize_value_yuan,
配置最小价值=min_value,
判断条件=f"{prize_value_yuan} < {min_value} = True",
)
except Exception:
pass
return True, f"value_lt_{min_value}"
else:
try:
analyser._log_kv(
@@ -268,6 +276,7 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"价值过滤:通过",
实际价值=prize_value_yuan,
配置最小价值=min_value,
判断条件=f"{prize_value_yuan} >= {min_value} = True",
)
except Exception:
pass
@@ -285,17 +294,17 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
if min_participants > 0:
if participants > 0:
if participants < min_participants:
skip_reasons.append(f"participants_lt_{min_participants}")
try:
analyser._log_kv(
"筛选",
"参与人数过滤:丢弃(小于最小值)",
原因=f"participants_lt_{min_participants}",
"参与人数过滤:不符合(小于最小值)",
实际参与人数=participants,
配置最小参与人数=min_participants,
判断条件=f"{participants} < {min_participants} = True",
)
except Exception:
pass
return True, f"participants_lt_{min_participants}"
else:
try:
analyser._log_kv(
@@ -303,6 +312,7 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"参与人数过滤:通过(最小值检查)",
实际参与人数=participants,
配置最小参与人数=min_participants,
判断条件=f"{participants} >= {min_participants} = True",
)
except Exception:
pass
@@ -319,17 +329,17 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
if max_participants > 0:
if participants > 0:
if participants > max_participants:
skip_reasons.append(f"participants_gt_{max_participants}")
try:
analyser._log_kv(
"筛选",
"参与人数过滤:丢弃(大于最大值)",
原因=f"participants_gt_{max_participants}",
"参与人数过滤:不符合(大于最大值)",
实际参与人数=participants,
配置最大参与人数=max_participants,
判断条件=f"{participants} > {max_participants} = True",
)
except Exception:
pass
return True, f"participants_gt_{max_participants}"
else:
try:
analyser._log_kv(
@@ -337,6 +347,7 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"参与人数过滤:通过(最大值检查)",
实际参与人数=participants,
配置最大参与人数=max_participants,
判断条件=f"{participants} <= {max_participants} = True",
)
except Exception:
pass
@@ -346,44 +357,27 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
if skip_if_lt > 0:
if remain_seconds is not None:
if remain_seconds < skip_if_lt:
skip_reasons.append(f"countdown_lt_{skip_if_lt}")
try:
analyser._log_kv(
"筛选",
"倒计时过滤:丢弃(剩余秒数小于阈值,不参与)",
原因=f"countdown_lt_{skip_if_lt}",
"倒计时过滤:不符合(剩余秒数小于阈值)",
实际剩余秒数=int(remain_seconds),
配置阈值秒数=skip_if_lt,
判断条件=f"{remain_seconds} < {skip_if_lt} = True",
)
except Exception:
pass
return True, f"countdown_lt_{skip_if_lt}"
# 3.2) 倒计时大于阈值:不参与(但如果价值达到高价值阈值,可以预约)
# 注意:这个过滤在 basic_join_decision 中会被特殊处理,如果价值达到高价值阈值,即使倒计时大于阈值也会记录预约
if skip_if_gt > 0:
try:
analyser._log_kv(
"筛选",
"倒计时过滤:开始检查",
配置阈值秒数=skip_if_gt,
实际剩余秒数=(
int(remain_seconds) if remain_seconds is not None else None
),
是否有倒计时数据=remain_seconds is not None,
说明="如果剩余秒数大于阈值,则不参与(但高价值福袋可预约)",
)
except Exception:
pass
if remain_seconds is not None:
# 如果剩余秒数 > 阈值,就丢弃(不参与)
if remain_seconds > skip_if_gt:
skip_reasons.append(f"countdown_gt_{skip_if_gt}")
try:
analyser._log_kv(
"筛选",
"倒计时过滤:丢弃(剩余秒数大于阈值,不参与)",
原因=f"countdown_gt_{skip_if_gt}",
"倒计时过滤:不符合(剩余秒数大于阈值)",
实际剩余秒数=int(remain_seconds),
配置阈值秒数=skip_if_gt,
判断条件=f"{remain_seconds} > {skip_if_gt} = True",
@@ -391,21 +385,14 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(倒计时大于阈值)",
elapsed_seconds=round(elapsed, 2),
)
return True, f"countdown_gt_{skip_if_gt}"
else:
try:
analyser._log_kv(
"筛选",
"倒计时过滤:通过(剩余秒数小于等于阈值,可以参与)",
"倒计时过滤:通过",
实际剩余秒数=int(remain_seconds),
配置阈值秒数=skip_if_gt,
判断条件=f"{remain_seconds} > {skip_if_gt} = False",
判断条件=f"{remain_seconds} <= {skip_if_gt} = True",
)
except Exception:
pass
@@ -415,9 +402,6 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"筛选",
"倒计时过滤:跳过(未识别到倒计时或倒计时已过期)",
剩余秒数=remain_seconds,
cd_start=cd_start,
cd_end=cd_end,
now=now,
)
except Exception:
pass
@@ -434,22 +418,15 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
# 4) 内容关键词过滤(复用 check_contain 逻辑)
content_check_result = check_contain(analyser, content)
if content_check_result:
skip_reasons.append("content_not_wanted")
try:
analyser._log_kv(
"筛选",
"内容关键词过滤:丢弃",
原因="content_not_wanted",
"内容关键词过滤:不符合",
内容=content[:60] if content else "",
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(内容关键词过滤)",
elapsed_seconds=round(elapsed, 2),
)
return True, "content_not_wanted"
else:
try:
analyser._log_kv(
@@ -462,7 +439,6 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
# 5) 按钮文本过滤:检查按钮是否显示无法参与、还需看播等状态
try:
button_text = str(getattr(analyser, "button_text_raw", "") or "").strip()
if button_text:
# 检查是否包含无法参与的关键词
unable_to_participate_keywords = [
@@ -488,53 +464,42 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
# 检查无法参与关键词
for keyword in unable_to_participate_keywords:
if keyword in button_text:
skip_reasons.append("button_unable_to_participate")
try:
analyser._log_kv(
"筛选",
"按钮文本过滤:丢弃(无法参与)",
原因="button_unable_to_participate",
"按钮文本过滤:不符合(无法参与)",
按钮文本=button_text,
匹配关键词=keyword,
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(按钮文本过滤)",
elapsed_seconds=round(elapsed, 2),
)
return True, "button_unable_to_participate"
break
# 检查观看要求关键词
for keyword in watch_required_keywords:
if keyword in button_text:
skip_reasons.append("button_watch_required")
try:
analyser._log_kv(
"筛选",
"按钮文本过滤:丢弃(观看任务)",
原因="button_watch_required",
"按钮文本过滤:不符合(观看任务)",
按钮文本=button_text,
匹配关键词=keyword,
)
except Exception:
pass
elapsed = time.time() - start_time
break
if not any(reason.startswith("button_") for reason in skip_reasons):
try:
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(按钮文本过滤)",
elapsed_seconds=round(elapsed, 2),
"按钮文本过滤:通过",
按钮文本=button_text,
)
return True, "button_watch_required"
try:
analyser._log_kv(
"筛选",
"按钮文本过滤:通过",
按钮文本=button_text,
)
except Exception:
pass
except Exception:
pass
else:
try:
analyser._log_kv(
@@ -554,6 +519,23 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
except Exception:
pass
# 如果有任何不符合的条件,就跳过
if skip_reasons:
elapsed = time.time() - start_time
try:
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(不符合条件,跳过)",
不符合原因=skip_reasons,
总原因数=len(skip_reasons),
elapsed_seconds=round(elapsed, 2),
)
except Exception:
pass
# 返回第一个原因作为主要原因
return True, skip_reasons[0]
# 所有条件都通过
try:
analyser._log_kv(
"筛选",
@@ -635,33 +617,32 @@ def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
# 强制参与标志已移除:始终进行正常验证流程
force_attend = False
# 继续走后续验证分支
if False:
# 额外验证:使用验证函数检查数据合理性
try:
# 在函数开头导入,避免作用域问题
from douyin.fudai import douyin_fudai_detail as dfd_module
# 额外验证:使用验证函数检查数据合理性
try:
# 在函数开头导入,避免作用域问题
from douyin.fudai import douyin_fudai_detail as dfd_module
is_valid, reason = dfd_module.validate_fudai_detail(detail, analyser)
if not is_valid:
try:
analyser._log_kv(
"参与",
"basic_join_decision:福袋详情数据验证失败,识别出错",
validation_reason=reason,
content=content[:50] if content else "",
prize_value_yuan=prize_value_yuan,
)
except Exception:
pass
elapsed = time.time() - start_time
is_valid, reason = dfd_module.validate_fudai_detail(detail, analyser)
if not is_valid:
try:
analyser._log_kv(
"参与",
"basic_join_decision完成(验证失败)",
elapsed_seconds=round(elapsed, 2),
"basic_join_decision:福袋详情数据验证失败,识别出错",
validation_reason=reason,
content=content[:50] if content else "",
prize_value_yuan=prize_value_yuan,
)
return False
except Exception:
pass
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"参与",
"basic_join_decision完成(验证失败)",
elapsed_seconds=round(elapsed, 2),
)
return False
except Exception:
pass
# 兜底检查:如果价值为0且内容为空,也可能是优惠券弹窗或识别错误
if not content and prize_value_yuan == 0.0:
+77 -95
View File
@@ -4070,40 +4070,55 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
except Exception:
skip_if_lt = 0
# 获取按钮文本,用于记录
button_text = str(getattr(analyser, "button_text_raw", "") or "").strip()
# 记录所有配置值和实际值,便于调试
try:
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config 开始检查",
配置_最小价值=min_value,
配置_最小参与人数=min_participants,
配置_最大参与人数=max_participants,
配置_倒计时大于秒数=skip_if_gt,
配置_倒计时小于秒数=skip_if_lt,
实际_价值=prize_value_yuan,
实际_参与人数=participants,
实际_份数=copies,
实际_剩余秒数=int(remain_seconds) if remain_seconds is not None else None,
实际_内容=content[:60] if content else "",
)
analyser._log_kv(
"筛选",
"配置参数",
最小价值=min_value,
最小参与人数=min_participants,
最大参与人数=max_participants,
倒计时大于秒数=skip_if_gt,
倒计时小于秒数=skip_if_lt,
)
analyser._log_kv(
"筛选",
"实际数据",
价值=prize_value_yuan,
参与人数=participants,
份数=copies,
剩余秒数=int(remain_seconds) if remain_seconds is not None else None,
内容=content[:60] if content else "",
按钮文本=button_text if button_text else "未识别",
)
except Exception:
pass
# 并行检查所有筛选条件,收集所有不符合的原因
skip_reasons = []
# 1) 价值过滤
if min_value > 0:
if prize_value_yuan > 0:
if prize_value_yuan < min_value:
skip_reasons.append(f"value_lt_{min_value}")
try:
analyser._log_kv(
"筛选",
"价值过滤:丢弃",
原因=f"value_lt_{min_value}",
"价值过滤:不符合(价值过低)",
实际价值=prize_value_yuan,
配置最小价值=min_value,
判断条件=f"{prize_value_yuan} < {min_value} = True",
)
except Exception:
pass
return True, f"value_lt_{min_value}"
else:
try:
analyser._log_kv(
@@ -4111,6 +4126,7 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"价值过滤:通过",
实际价值=prize_value_yuan,
配置最小价值=min_value,
判断条件=f"{prize_value_yuan} >= {min_value} = True",
)
except Exception:
pass
@@ -4128,17 +4144,17 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
if min_participants > 0:
if participants > 0:
if participants < min_participants:
skip_reasons.append(f"participants_lt_{min_participants}")
try:
analyser._log_kv(
"筛选",
"参与人数过滤:丢弃(小于最小值)",
原因=f"participants_lt_{min_participants}",
"参与人数过滤:不符合(小于最小值)",
实际参与人数=participants,
配置最小参与人数=min_participants,
判断条件=f"{participants} < {min_participants} = True",
)
except Exception:
pass
return True, f"participants_lt_{min_participants}"
else:
try:
analyser._log_kv(
@@ -4146,6 +4162,7 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"参与人数过滤:通过(最小值检查)",
实际参与人数=participants,
配置最小参与人数=min_participants,
判断条件=f"{participants} >= {min_participants} = True",
)
except Exception:
pass
@@ -4162,17 +4179,17 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
if max_participants > 0:
if participants > 0:
if participants > max_participants:
skip_reasons.append(f"participants_gt_{max_participants}")
try:
analyser._log_kv(
"筛选",
"参与人数过滤:丢弃(大于最大值)",
原因=f"participants_gt_{max_participants}",
"参与人数过滤:不符合(大于最大值)",
实际参与人数=participants,
配置最大参与人数=max_participants,
判断条件=f"{participants} > {max_participants} = True",
)
except Exception:
pass
return True, f"participants_gt_{max_participants}"
else:
try:
analyser._log_kv(
@@ -4180,17 +4197,18 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"参与人数过滤:通过(最大值检查)",
实际参与人数=participants,
配置最大参与人数=max_participants,
判断条件=f"{participants} <= {max_participants} = True",
)
except Exception:
pass
# 2.5) 倒计时文本过滤:如果OCR识别的倒计时文本表示剩余时间很短,直接跳过
if _is_short_countdown_text(time_text):
skip_reasons.append("countdown_text_short")
try:
analyser._log_kv(
"筛选",
"倒计时文本过滤:丢弃(OCR识别到剩余时间很短)",
原因="countdown_text_short",
"倒计时文本过滤:不符合(OCR识别到剩余时间很短)",
倒计时文本=time_text,
实际剩余秒数=(
int(remain_seconds) if remain_seconds is not None else None
@@ -4198,57 +4216,33 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(倒计时文本过滤)",
elapsed_seconds=round(elapsed, 2),
)
return True, "countdown_text_short"
# 3) 倒计时过滤
# 3.1) 倒计时小于阈值:直接丢弃(不参与)
if skip_if_lt > 0:
if remain_seconds is not None:
if remain_seconds < skip_if_lt:
skip_reasons.append(f"countdown_lt_{skip_if_lt}")
try:
analyser._log_kv(
"筛选",
"倒计时过滤:丢弃(剩余秒数小于阈值,不参与)",
原因=f"countdown_lt_{skip_if_lt}",
"倒计时过滤:不符合(剩余秒数小于阈值)",
实际剩余秒数=int(remain_seconds),
配置阈值秒数=skip_if_lt,
判断条件=f"{remain_seconds} < {skip_if_lt} = True",
)
except Exception:
pass
return True, f"countdown_lt_{skip_if_lt}"
# 3.2) 倒计时大于阈值:不参与(但如果价值达到高价值阈值,可以预约)
# 注意:这个过滤在 basic_join_decision 中会被特殊处理,如果价值达到高价值阈值,即使倒计时大于阈值也会记录预约
if skip_if_gt > 0:
try:
analyser._log_kv(
"筛选",
"倒计时过滤:开始检查",
配置阈值秒数=skip_if_gt,
实际剩余秒数=(
int(remain_seconds) if remain_seconds is not None else None
),
是否有倒计时数据=remain_seconds is not None,
说明="如果剩余秒数大于阈值,则不参与(但高价值福袋可预约)",
)
except Exception:
pass
if remain_seconds is not None:
# 如果剩余秒数 > 阈值,就丢弃(不参与)
if remain_seconds > skip_if_gt:
skip_reasons.append(f"countdown_gt_{skip_if_gt}")
try:
analyser._log_kv(
"筛选",
"倒计时过滤:丢弃(剩余秒数大于阈值,不参与)",
原因=f"countdown_gt_{skip_if_gt}",
"倒计时过滤:不符合(剩余秒数大于阈值)",
实际剩余秒数=int(remain_seconds),
配置阈值秒数=skip_if_gt,
判断条件=f"{remain_seconds} > {skip_if_gt} = True",
@@ -4256,21 +4250,14 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(倒计时大于阈值)",
elapsed_seconds=round(elapsed, 2),
)
return True, f"countdown_gt_{skip_if_gt}"
else:
try:
analyser._log_kv(
"筛选",
"倒计时过滤:通过(剩余秒数小于等于阈值,可以参与)",
"倒计时过滤:通过",
实际剩余秒数=int(remain_seconds),
配置阈值秒数=skip_if_gt,
判断条件=f"{remain_seconds} > {skip_if_gt} = False",
判断条件=f"{remain_seconds} <= {skip_if_gt} = True",
)
except Exception:
pass
@@ -4280,9 +4267,6 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
"筛选",
"倒计时过滤:跳过(未识别到倒计时或倒计时已过期)",
剩余秒数=remain_seconds,
cd_start=cd_start,
cd_end=cd_end,
now=now,
)
except Exception:
pass
@@ -4299,22 +4283,15 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
# 4) 内容关键词过滤(复用 check_contain 逻辑)
content_check_result = check_contain(analyser, content)
if content_check_result:
skip_reasons.append("content_not_wanted")
try:
analyser._log_kv(
"筛选",
"内容关键词过滤:丢弃",
原因="content_not_wanted",
"内容关键词过滤:不符合",
内容=content[:60] if content else "",
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(内容关键词过滤)",
elapsed_seconds=round(elapsed, 2),
)
return True, "content_not_wanted"
else:
try:
analyser._log_kv(
@@ -4327,7 +4304,6 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
# 5) 按钮文本过滤:检查按钮是否显示无法参与、还需看播等状态
try:
button_text = str(getattr(analyser, "button_text_raw", "") or "").strip()
if button_text:
# 检查是否包含无法参与的关键词
unable_to_participate_keywords = [
@@ -4353,53 +4329,42 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
# 检查无法参与关键词
for keyword in unable_to_participate_keywords:
if keyword in button_text:
skip_reasons.append("button_unable_to_participate")
try:
analyser._log_kv(
"筛选",
"按钮文本过滤:丢弃(无法参与)",
原因="button_unable_to_participate",
"按钮文本过滤:不符合(无法参与)",
按钮文本=button_text,
匹配关键词=keyword,
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(按钮文本过滤)",
elapsed_seconds=round(elapsed, 2),
)
return True, "button_unable_to_participate"
break
# 检查观看要求关键词
for keyword in watch_required_keywords:
if keyword in button_text:
skip_reasons.append("button_watch_required")
try:
analyser._log_kv(
"筛选",
"按钮文本过滤:丢弃(观看任务)",
原因="button_watch_required",
"按钮文本过滤:不符合(观看任务)",
按钮文本=button_text,
匹配关键词=keyword,
)
except Exception:
pass
elapsed = time.time() - start_time
break
if not any(reason.startswith("button_") for reason in skip_reasons):
try:
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(按钮文本过滤)",
elapsed_seconds=round(elapsed, 2),
"按钮文本过滤:通过",
按钮文本=button_text,
)
return True, "button_watch_required"
try:
analyser._log_kv(
"筛选",
"按钮文本过滤:通过",
按钮文本=button_text,
)
except Exception:
pass
except Exception:
pass
else:
try:
analyser._log_kv(
@@ -4419,6 +4384,23 @@ def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str
except Exception:
pass
# 如果有任何不符合的条件,就跳过
if skip_reasons:
elapsed = time.time() - start_time
try:
analyser._log_kv(
"筛选",
"should_skip_fudai_by_config完成(不符合条件,跳过)",
不符合原因=skip_reasons,
总原因数=len(skip_reasons),
elapsed_seconds=round(elapsed, 2),
)
except Exception:
pass
# 返回第一个原因作为主要原因
return True, skip_reasons[0]
# 所有条件都通过
try:
analyser._log_kv(
"筛选",
+35
View File
@@ -254,6 +254,23 @@ class LoggingWrapper:
"检测结果": "检测结果",
"检测方法": "检测方法",
"耗时(ms)": "耗时",
# 筛选相关字段映射
"配置_最小价值": "最小价值",
"配置_最小参与人数": "最小参与人数",
"配置_最大参与人数": "最大参与人数",
"配置_倒计时大于秒数": "倒计时大于阈值",
"配置_倒计时小于秒数": "倒计时小于阈值",
"实际_价值": "实际价值",
"实际_参与人数": "实际参与人数",
"实际_份数": "实际份数",
"实际_剩余秒数": "剩余秒数",
"实际_内容": "福袋内容",
"配置阈值秒数": "阈值秒数",
"实际剩余秒数": "剩余秒数",
"判断条件": "判断条件",
"说明": "说明",
"是否有倒计时数据": "有倒计时数据",
"按钮文本": "按钮文本",
}
# 构建简洁的日志行:时间 [级别] [标签] 消息 关键字段
@@ -309,6 +326,24 @@ class LoggingWrapper:
"value_raw",
"button_text_raw",
"live_room_title_raw",
# 筛选相关字段
"配置_最小价值",
"配置_最小参与人数",
"配置_最大参与人数",
"配置_倒计时大于秒数",
"配置_倒计时小于秒数",
"实际_价值",
"实际_参与人数",
"实际_份数",
"实际_剩余秒数",
"实际_内容",
"配置阈值秒数",
"实际剩余秒数",
"判断条件",
"说明",
"原因",
"是否有倒计时数据",
"按钮文本",
):
key_cn = key_map.get(str(k), k)
if isinstance(v, float):
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
import time
# 添加项目根目录到路径
sys.path.insert(0, os.path.dirname(__file__))
from douyin.fudai.douyin_fudai_core import should_skip_fudai_by_config
# 创建一个模拟的 analyser 对象
class MockAnalyser:
def _log_kv(self, category, message, **kwargs):
print(f"[{category}] {message}")
for key, value in kwargs.items():
print(f" {key}: {value}")
# 测试筛选逻辑
analyser = MockAnalyser()
# 测试数据:detail 是一个元组,包含福袋的详细信息
# 格式为 (prize_value_yuan, participants, copies, content, button_text, countdown_tuple, ...)
detail = (
75.0, # prize_value_yuan
10, # participants
1, # copies
"", # content
"一键发表评论", # button_text
(time.time() + 120, time.time() + 120), # countdown (start, end)
)
result, reason = should_skip_fudai_by_config(analyser=analyser, detail=detail)
print(f"\n筛选结果: {'跳过' if result else '参与'}, 原因: {reason}")