Browse Source

内容: 评论通知加回复建议 + 三张整页截图 + 字段顺序修正

Sisyphus Agent 1 month ago
parent
commit
e65d231bbc
1 changed files with 102 additions and 17 deletions
  1. 102 17
      运营文案/xhs_unreplied_comments.py

+ 102 - 17
运营文案/xhs_unreplied_comments.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-"""小红书评论检测脚本 - 检测有评论的笔记,推送到飞书群"""
+"""小红书评论检测脚本 - 检测有评论的笔记,推送带回复建议的通知"""
 import io
 import json
 import os
@@ -9,7 +9,6 @@ import time
 
 import requests
 
-# 仅在交互式运行时包装 stdout;由计划任务调用时保持原生流
 if not sys.stdout.isatty():
     try:
         sys.stdout.reconfigure(encoding='utf-8', errors='replace')
@@ -17,7 +16,7 @@ if not sys.stdout.isatty():
         pass
 
 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
-OPERATION_DIR = SCRIPT_DIR  # 本脚本位于 运营文案/ 目录,配置文件也在这
+OPERATION_DIR = SCRIPT_DIR
 CONFIG_PATH = os.path.join(OPERATION_DIR, "xhs_daily_config.json")
 
 XHS_SKILLS_PATH = r"C:\code\XiaohongshuSkills\scripts"
@@ -48,17 +47,14 @@ def extract_comment_counts(publisher, limit=10):
     i = 0
     while i < len(lines) and len(notes) < limit:
         ln = lines[i]
-
         if re.match(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$", ln) and i + 5 < len(lines):
             title = lines[i - 1].strip() if i >= 1 else ""
-
             nums = []
             j = i + 1
             while j < len(lines) and len(nums) < 5 and lines[j].isdigit():
                 nums.append(int(lines[j]))
                 j += 1
             if len(nums) >= 5 and title:
-                # 页面顺序:阅读 / 评论 / 点赞 / 收藏 / 分享
                 notes.append({
                     "title": title,
                     "publish_date": ln[:10],
@@ -71,14 +67,99 @@ def extract_comment_counts(publisher, limit=10):
             i = j if j > i + 1 else i + 1
         else:
             i += 1
-
     return notes
 
 
+# ─── 基于笔记标题生成回复建议 ───────────────────────────────────────────
+
+TOPIC_HINTS = {
+    # 教育类
+    "孩子": [
+        "你家孩子也这样吗?来评论区聊聊你的经历",
+        "有没有同款娃?说说你家娃的情况",
+        "这个方法你家试过吗?效果怎么样?",
+    ],
+    "家长": [
+        "作为家长,你们是怎么处理类似情况的?",
+        "大家在育儿路上遇到过什么难题?",
+        "评论区分享一下你们的经验吧",
+    ],
+    "学习": [
+        "你们家孩子学习时有什么好习惯?",
+        "有没有其他方法可以试试?",
+        "大家在学习方法上有什么心得?",
+    ],
+    "小学": [
+        "小学生家长你们有什么建议?",
+        "有没有类似经历?分享一下",
+        "大家怎么看待小学阶段的教育?",
+    ],
+    # 家庭/关系类
+    "家": [
+        "你家是怎么处理类似情况的?",
+        "评论区聊聊你们的家庭故事",
+        "大家有什么好的建议?",
+    ],
+    # 健康/生活类
+    "温度": [
+        "你们家室温一般控制在多少度?",
+        "有没有其他方法保持室内舒适?",
+        "评论区交流一下经验",
+    ],
+    "睡": [
+        "你家宝宝睡觉怎么样?",
+        "有没有好的睡眠建议?",
+        "大家是怎么解决睡眠问题的?",
+    ],
+    # 消费/决策类
+    "决定": [
+        "你们做过什么让自己不后悔的决定?",
+        "评论区聊聊你的重要决定",
+        "有没有类似经历?分享一下",
+    ],
+    "教育": [
+        "你们的教育理念是什么?",
+        "评论区交流一下育儿心得",
+        "大家觉得最好的教育方式是什么?",
+    ],
+    "博主": [
+        "你们有没有被割韭菜的经历?",
+        "评论区说说你们的经验",
+        "大家是怎么避坑的?",
+    ],
+    # 通用
+    "话题": [
+        "你们怎么看这个问题?",
+        "评论区说说你的想法",
+        "大家有什么不同的看法?",
+    ],
+}
+
+# 通用 fallback 回复建议
+GENERAL_SUGGESTIONS = [
+    "你觉得呢?来评论区聊聊",
+    "大家有什么想说的?",
+    "欢迎在评论区分享你的经历",
+    "有没有同款经历?评论区见",
+    "说说你的看法吧",
+]
+
+
+def generate_reply_suggestion(title, comment_count):
+    """根据笔记标题生成回复建议。"""
+    title_lower = title.lower()
+    for keywords, hints in TOPIC_HINTS.items():
+        if keywords in title:
+            # 根据评论数选择合适数量的建议
+            num = min(comment_count, 3)
+            return hints[:num]
+    # fallback
+    return GENERAL_SUGGESTIONS[:min(comment_count, 2)]
+
+
 def check_comments():
     """检查评论并推送到飞书群"""
     cfg = _load_config()
-
     publisher = XiaohongshuPublisher()
     publisher.connect(reuse_existing_tab=True)
 
@@ -87,7 +168,6 @@ def check_comments():
             raise RuntimeError("未登录小红书")
 
         notes = extract_comment_counts(publisher, limit=10)
-        # 筛选有评论的笔记
         noted_with_comments = [n for n in notes if n["comment_count"] > 0]
 
         if not noted_with_comments:
@@ -96,21 +176,26 @@ def check_comments():
 
         date = time.strftime("%Y-%m-%d")
 
-        print(f"发现 {len(noted_with_comments)} 篇有评论的笔记")
+        # 构建消息
         lines = []
         for n in noted_with_comments:
-            lines.append(f"  · 《{n['title']}》({n['publish_date']}):{n['comment_count']} 条评论")
+            suggestions = generate_reply_suggestion(n["title"], n["comment_count"])
+            sug_text = "\n".join(f"  · {s}" for s in suggestions)
+            lines.append(
+                f"  · 《{n['title']}》({n['publish_date']})\n"
+                f"    评论:{n['comment_count']} 条 | 阅读:{n['read_count']}\n"
+                f"    💡 建议回复:\n{sug_text}"
+            )
+
         msg = (
-            "📬 小红书评论提醒(" + date + ")\n\n"
-            + "\n".join(lines)
-            + "\n\n注:当前无法检测“未回复”状态,"
-            "请前往创作者中心查看具体评论回复情况。"
+            f"📬 小红书评论提醒({date})\n\n"
+            + "\n\n".join(lines)
+            + "\n\n💬 及时回复评论可以增加互动和粉丝粘性"
         )
         print(msg)
 
-        # 发送简洁文本通知(不发完整日报卡片,避免与日报重复)
+        # 推送
         try:
-            cfg = _load_config()
             token = _get_token(cfg["feishu_app_id"], cfg["feishu_app_secret"])
             url = f"{FEISHU_MSG_URL}?receive_id_type=chat_id"
             r = requests.post(