# /// script # requires-python = ">=3.12" # dependencies = ["websockets>=13"] # /// """Sample post texts from a jetstream-compatible feed into a local JSONL corpus. usage: uv run scripts/sample_posts.py OUT.jsonl [COUNT] """ import asyncio import json import sys import websockets URL = "wss://stream.waow.tech/subscribe?wantedCollections=app.bsky.feed.post" async def main(out_path: str, count: int) -> None: seen = 0 with open(out_path, "w") as out: async with websockets.connect(URL, max_size=2**22) as ws: async for raw in ws: event = json.loads(raw) commit = event.get("commit") or {} if commit.get("operation") != "create": continue text = (commit.get("record") or {}).get("text") if not text: continue out.write(json.dumps({"text": text}, ensure_ascii=False) + "\n") seen += 1 if seen >= count: return if __name__ == "__main__": asyncio.run(main(sys.argv[1], int(sys.argv[2]) if len(sys.argv) > 2 else 5000))