"""Keep posts that actually ASK for / wish for a tool (regex on the text), drop labelled bots. Writes candidates.json + cand.txt.""" import json, re d = json.load(open("posts.json", encoding="utf-8")) ASK = re.compile(r"(is there (a|an|any) (free |good |simple |easy )?(tool|app|script|website|site|extension|plugin|program|service|way)" r"|wish (there was|there were|someone (would )?(made|make|built|build))" r"|(anyone|anybody|does anyone|do you) (know|recommend|have)( of)? (a|an|any|good) (tool|app|script|site|website|extension|plugin|program|service)" r"|looking for (a|an) (tool|app|script|extension|plugin|service)" r"|need (a|an) (tool|app|script|extension|plugin) (that|to|for)" r"|someone (should|needs to) (build|make|create)" r"|(i'?d|i would|would) (happily |gladly )?pay for (a|an|something|this|that|a tool|an app)" r"|why (is there|isn't there) no (tool|app|way)" r"|how (do|can) (i|you) automatically)", re.I) c = [p for p in d["posts"] if not p["bot"] and ASK.search(p["text"])] c.sort(key=lambda p: p["time"]) json.dump(c, 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(c): f.write(f"[{i}] {p['handle']} {p['time'][:10]} L{p['likes']} R{p['replies']} {'reply' if p['is_reply'] else 'top'}\n{p['text'].replace(chr(10),' ')}\n\n") print(len(d["posts"]), "->", len(c))