Run the refresh-lsst-bib program's logic: iterates through bib URLs,
    downloads the file from GitHub, and writes it to a local directory.

    Parameters
    ----------
    local_dir : `str`
        Directory to write bib files into.

    Returns
    -------
    error_count : `int`
        Number of download errors.

def process_bib_files(local_dir):
    """Run the refresh-lsst-bib program's logic: iterates through bib URLs,
    downloads the file from GitHub, and writes it to a local directory.

    Parameters
    ----------
    local_dir : `str`
        Directory to write bib files into.

    Returns
    -------
    error_count : `int`
        Number of download errors.
    """
    logger = logging.getLogger(__name__)

    # check the output directory exists
    if not os.path.isdir(local_dir):
        logger.error('Output directory "{}" does not exist'.format(local_dir))
        sys.exit(1)

    root_blob_url = ('https://raw.githubusercontent.com/lsst/lsst-texmf/'
                     'master/texmf/bibtex/bib/')
    bib_filenames = ['books.bib', 'lsst-dm.bib', 'lsst.bib', 'refs.bib',
                     'refs_ads.bib']

    error_count = 0
    for bib_filename in bib_filenames:
        url = urllib.parse.urljoin(root_blob_url, bib_filename)
        logger.info('Downloading {}'.format(url))
        try:
            content = _get_content(url)
        except requests.HTTPError as e:
            logger.exception(str(e))
            logger.warning('Could not download {}'.format(url))
            error_count += 1
            continue

        local_filename = os.path.join(local_dir, bib_filename)
        with open(local_filename, 'w') as f:
            f.write(content)

    return error_count