import gzip import json from concurrent.futures import ProcessPoolExecutor MONTHS = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"] def filter_month(month: str): with gzip.open(f"all/2022-{month}.jsonl.gz", "rb") as f: with gzip.open(f"rapid-classical-correspondence/2022-{month}.jsonl.gz", "wb") as fo: for i, line in enumerate(f): d = json.loads(line) s = d["event"] if "Rapid" in s or "Classical" in s or "Correspondence" in s: fo.write((json.dumps(d) + '\n').encode()) return 0 ppe = ProcessPoolExecutor(12) for _ in ppe.map(filter_month, MONTHS): ... ppe.shutdown() print("Done!")