File size: 703 Bytes
52a5af7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Read compressed StreamStop JSONL records without extracting the full collection."""
from pathlib import Path
import argparse
import gzip
import json
import lzma


def iter_records(path):
    path = Path(path)
    opener = lzma.open if path.suffix == ".xz" else gzip.open
    with opener(path, "rt", encoding="utf-8") as stream:
        for line in stream:
            if line.strip():
                yield json.loads(line)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("path", type=Path)
    args = parser.parse_args()
    row = next(iter_records(args.path))
    print("Record fields:", ", ".join(sorted(row)))