from pathlib import Path
from typing import Optional
import json


def get_n_articles(data_dir: Path) -> Optional[int]:
    """get `n_articles` reported in a processing step's output dir."""
    try:
        return int(
            json.loads(data_dir.joinpath("info.json").read_text("utf-8"))[
                "n_articles"
            ]
        )
    except Exception:
        return None