File size: 715 Bytes
51cff15 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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!")
|