File size: 654 Bytes
0a3edb6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | """saves_lanes_{i}.jsonl.gz -> per_save/<sha10>.jsonl.gz, one file per save (written atomically)."""
import collections, gzip, json, os, sys
from pathlib import Path
out = Path(sys.argv[1])
by = collections.defaultdict(list)
for p in sys.argv[2:]:
with gzip.open(p, "rt") as f:
for line in f:
rec = json.loads(line)
by[rec["id"].split("#")[0].removesuffix(".zip")].append(line)
for sha, lines in by.items():
tmp = out / f"{sha}.jsonl.gz.tmp"
with gzip.open(tmp, "wt") as f:
f.writelines(lines)
os.replace(tmp, out / f"{sha}.jsonl.gz")
print(len(by), "saves", sum(map(len, by.values())), "records")
|