import json, re P = json.load(open("posts.json", encoding="utf-8")) rel = [p for p in P if re.search(r"capsule", p["text"], re.I) or re.search(r"steam (store )?page", p["text"], re.I)] ask = re.compile(r"\?|feedback|help|size|resolution|pixel|crop|readab|small|thumbnail|struggl|hate|confus|tips|advice|which one|vote|A or B|option", re.I) cand = [p for p in rel if ask.search(p["text"])] print("relevant", len(rel), "candidates", len(cand)) json.dump(cand, open("candidates.json", "w", encoding="utf-8"), ensure_ascii=False, indent=1) with open("cand.txt", "w", encoding="utf-8") as f: for i, p in enumerate(cand): f.write(f"[{i}] {p['handle']} bot={p['bot']} L{p['likes']} R{p['replies']} reply={p['is_reply']} {p['url']}\n{p['text'][:400]}\n\n")