Files
Hermes-Skills/okx-auto-position/references/dividend-alert-silent-pattern-2026-09-01.md
T

3.2 KiB

cron silent on success — dividend_alert.py 改造 (2026-09-01)

用户原话: "这个没消息就不推送了" / "这个不需要推, 更新就好了"

事件: dividend_alert_cn_hk.sh cron 11:00 跑, 拉美股+港股没除权票, 还推"✅ 明天没有高息股票除权, 休息一天~" 消息 — 用户怼"没消息就不推送了"。

改造: ~/.hermes/scripts/dividend_alert.py 加 silent 逻辑, 共用 --market cn_hk 和 --market us, 两个 wrapper 都受益。

改动点 (v4.5.70)

1. fmt() 函数末尾 — "没有除权" 标记

位置: ~/.hermes/scripts/dividend_alert.py (原本)

if not has: L += ['✅ 明天没有高息股票除权,休息一天~', '']

保持原样 (主函数调用时还会生成这一行, 后续判断 silent)

2. is_empty_content() 新函数

位置: ~/.hermes/scripts/dividend_alert.py (新增, 紧跟 fmt())

def is_empty_content(content):
    """检测推送内容是否只有'明天没有高息股票除权, 休息一天'的空消息
    (用户偏好 silent on success)"""
    return '✅ 明天没有高息股票除权,休息一天~' in content

3. main() 末尾 — silent exit

位置: ~/.hermes/scripts/dividend_alert.py (main 函数末尾)

# 5. 输出 - 没消息时 silent (stdout 空, no_agent 不推送)
content = fmt(a_h, hk_h, us_h, a_p, hk_p, us_p)
if is_empty_content(content):
    # silent on success: 没明天除权 = 不推
    sys.exit(0)
print(content)

验证

# 模拟空数据 (无除权)
python3 -c "
import sys
sys.path.insert(0, '/home/openclaw/.hermes/scripts')
from dividend_alert import fmt, is_empty_content
content = fmt([], [], [], {}, {}, {})
print('empty?', is_empty_content(content))
"
# → empty? True

cron silent 行为对照

场景 原行为 现行为
明天有除权票 (5+ 只) 推送详细表 推送详细表 ✓
明天只有 1-2 只 推送单行 推送单行 ✓
明天 0 只 推送 "✅ 休息一天" silent (stdout 空) ✓

silent 触发的条件

任何 cron 跑完 → stdout 空 → no_agent 看到空 → 不推 QQ。 stderr 输出 (报错信息) 不影响 stdout 判定。

关联

  • user-communication-style § 27 静默 = OK 推 = 报警
  • user-communication-style § 36 cron silent on success 通用 pattern
  • hermes-cron-mcp-tasks § 7.3 cron silent on success 通用 pattern
  • memory-check-utf8-zombie-lock-fix skill (之前的 silent 实践)

同类 cron 改造清单 (2026-09-01 已改)

Cron job 改造点
dividend_alert.py --market cn_hk ✅ silent on empty
dividend_alert.py --market us ✅ 共享脚本, 同样 silent
memory_check.sh ✅ (2026-08-31 已改)
order-errors-monitor.sh ✅ (2026-08-31 已改)
proxy_speedtest_cron.sh ✅ (2026-08-31 已改)
dca_scanner.py (港/A/美 股高息扫描) ✅ if output.strip(): print(output)
signal_queue_retry.sh ✅ 没任务 exit 0
lottery_特码_cron.sh ✅ silent 兜底
verify_lottery.sh ❌ 不 silent (它本身是核验报告, 没数据 = 不该跑)
daily_t_analysis.py ❌ 不 silent (分析报告, 有内容)