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

28 lines
1.4 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)
preg = sorted([i for i, p in enumerate(d['p']) if p[2].startswith('孕')], 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)