#!/usr/bin/env python3 """ scripts/export_jsonl.py ----------------------- Export all metadata as a single JSONL file for downstream use. Usage: python scripts/export_jsonl.py --meta-dir metadata/ --out corpus.jsonl """ from __future__ import annotations import argparse import json from pathlib import Path from rich.console import Console console = Console() def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Export metadata as JSONL.") parser.add_argument("--meta-dir", default=Path("metadata"), type=Path) parser.add_argument("--out", default=Path("corpus.jsonl"), type=Path) return parser.parse_args() def main() -> None: args = parse_args() meta_dir: Path = args.meta_dir.resolve() out_file: Path = args.out.resolve() files = sorted(meta_dir.glob("*.json")) if not files: console.print(f"[yellow]No metadata found in {meta_dir}[/yellow]") return with out_file.open("w", encoding="utf-8") as fout: for f in files: try: data = json.loads(f.read_text(encoding="utf-8")) fout.write(json.dumps(data, ensure_ascii=False) + "\n") except json.JSONDecodeError as exc: console.print(f"[red]Skipping {f.name}: {exc}[/red]") console.print(f"[green]✓ Exported {len(files)} records to {out_file}[/green]") if __name__ == "__main__": main()