#!/usr/bin/env python3
"""Download abstract metadata from INSPIRE-HEP and save as markdown and HTML.\n
Given an arXiv ID (e.g. 2604.20797 or hep-ph/0603175), resolves the paper on
INSPIRE-HEP, fetches its record metadata, and writes ``_abstract.md`` and
``_abstract.html`` files in the same format used by the arXiv-based abstract
workflow.\n
Usage:
    python scripts/download_inspire_abstract.py 2604.20797
    python scripts/download_inspire_abstract.py hep-ph/0603175
    python scripts/download_inspire_abstract.py 2604.20797 2604.12345
"""

import argparse
import os
import sys

sys.path.insert(0, os.path.dirname(__file__))

from action_lib import download_and_save_abstract
from inspire_lib import log_to_stderr

def main() -> None:
    """Parse CLI arguments and download abstracts for the given arXiv IDs."""
    parser = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument(
        "arxiv_ids",
        nargs="+",
        help="arXiv paper ID(s), e.g. 2604.20797 or hep-ph/0603175",
    )
    args = parser.parse_args()
    #
    for arxiv_id in args.arxiv_ids:
        download_and_save_abstract(arxiv_id)
    #
    log_to_stderr("All done.")

if __name__ == "__main__":
    main()
