# -*- coding: utf-8 -*-
"""抽取与"第一个月/第二个月/新人/起号"相关的评论与口播，用于估算爬坡期收益"""
import glob, json, os, re, sys

sys.stdout.reconfigure(encoding="utf-8")
ROOT = r"D:\Deepseek\douyin_fengdaquan"
CMT = os.path.join(ROOT, "comments_all")
SUB = os.path.join(ROOT, "subtitles_all")

TIME_KW = ["第一个月", "第二个月", "头一个月", "第一个月", "刚开始", "新人", "半个月", "一个月",
           "两个月", "三个月", "几天", "起号", "新号", "刚做", "入门"]

print("=" * 20, "评论里的爬坡期证据", "=" * 20)
hits = []
for fp in glob.glob(os.path.join(CMT, "*.json")):
    j = json.load(open(fp, encoding="utf-8"))
    for c in j.get("comments", []):
        t = (c.get("text") or "").strip()
        if not t:
            continue
        if any(k in t for k in TIME_KW):
            hits.append((c.get("digg") or 0, c.get("user"), c.get("ip_label"), t))
for d, u, ip, t in sorted(hits, key=lambda x: -x[0])[:40]:
    print(f"[{d}] {u}({ip}): {t[:90]}")
print("命中条数:", len(hits))

print("\n" + "=" * 20, "口播里的新人/起号节奏", "=" * 20)
n = 0
for fp in sorted(glob.glob(os.path.join(SUB, "*.txt"))):
    t = open(fp, encoding="utf-8").read()
    for kw in ["新人", "起号", "第一个月", "第二天", "三天", "一周"]:
        for m in re.finditer(kw, t):
            a = max(0, m.start() - 50); b = min(len(t), m.end() + 60)
            s = t[a:b].replace("\n", " ")
            print(f"[{os.path.basename(fp)[:24]}] ...{s}...")
            n += 1
            break
    if n >= 25:
        break
