Files
mama-box/tools/whcm/build.py

32 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""孕妈悄悄话置顶笔记的 100 条模拟祝福评论(11-07 用户:「评论里按正常评论放上 100 个」)。
lines.txt 一行一条,「||」后面是楼中楼回复(其他孕妈/宝妈)。人设从 cm.json 的 1000 人里挑:主评论用孕期人设、回复混宝妈;
尽量挑在别的帖子下出现少的人。确定性(固定种子),重跑结果不变;只追加/覆盖 c[TARGET],不动其他帖子。"""
import json, random
from collections import Counter
TARGET = 'wh-20260928'
P = 'guangchang/cm.json'
d = json.load(open(P, encoding='utf-8'))
used = Counter(c[0] for k, L in d['c'].items() if k != TARGET for c in L)
rnd = random.Random(20261107)
import re
def wk(p):
m = re.match(r'孕 ?(\d+)', p[2]); return int(m.group(1)) if m else 0
# 内容多是胎动、产检、待产(孕中晚期的事)→ 主评论只用孕 24 周以上的人设,免得「孕 6 周」说「头朝下了」
preg = sorted([i for i, p in enumerate(d['p']) if wk(p) >= 24], key=lambda i: (used[i], i))
anyp = sorted(range(len(d['p'])), key=lambda i: (used[i], i))
mains = preg[:200]; rnd.shuffle(mains)
reps = anyp[:300]; rnd.shuffle(reps)
lines = [l.strip() for l in open('tools/whcm/lines.txt', encoding='utf-8') if l.strip()]
assert len(lines) == 100, len(lines)
out, ri = [], 0
for k, l in enumerate(lines):
parts = l.split('||')
likes = max(3, int(520 * (0.965 ** k)) + rnd.randint(-18, 18))
rr = []
for t in parts[1:]:
rr.append([reps[ri], t]); ri += 1
out.append([mains[k], parts[0], likes, rr])
d['c'][TARGET] = out
json.dump(d, open(P, 'w', encoding='utf-8'), ensure_ascii=False, separators=(',', ':'))
print('ok', len(out), 'replies', ri)