import sys, io, json, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")

import os
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.dirname(SCRIPT_DIR)

with open(os.path.join(PROJECT_ROOT, "data", "raw-messages", "all_messages_combined.json"), "r", encoding="utf-8") as f:
    data = json.load(f)

feishu_re = re.compile(r"https?://[a-zA-Z0-9.-]+\.feishu\.cn/(?:wiki|docx)/[A-Za-z0-9]+")

# Find feishu links shared around the same time as garden world discussions (05-25 to 06-02)
print("=== 05-25~06-02 期间 dc群所有飞书链接 ===")
for msg in data["dc"]:
    t = msg.get("createTime", "")
    if t >= "2026-05-25" and t <= "2026-06-02":
        content = msg.get("content", "")
        links = feishu_re.findall(content)
        if links:
            sender = msg.get("sender", "")
            for link in links:
                print("  [%s] %s: %s" % (t[:10], sender, link))

# Also find the chat content around 05-25 to 06-02 for garden world discussions
print("\n=== 05-25~06-02 期间 dc群非链接讨论 ===")
for msg in data["dc"]:
    t = msg.get("createTime", "")
    if t >= "2026-05-25" and t <= "2026-06-02":
        content = msg.get("content", "")
        if not feishu_re.search(content) and not content.startswith("[文件]") and not content.startswith("[图片") and not content.startswith("[视频") and len(content) > 10:
            sender = msg.get("sender", "")
            print("  [%s] %s: %s" % (t[:16], sender, content[:200]))

