How to use the isbnlib.to_isbn13 function in isbnlib

To help you get started, we’ve selected a few isbnlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github manubot / manubot / manubot / cite / citekey.py View on Github external
identifier = expand_short_doi(identifier)
            except Exception as error:
                # If DOI shortening fails, return the unshortened DOI.
                # DOI metadata lookup will eventually fail somewhere with
                # appropriate error handling, as opposed to here.
                logging.error(
                    f"Error in expand_short_doi for {identifier} "
                    f"due to a {error.__class__.__name__}:\n{error}"
                )
                logging.info(error, exc_info=True)
        identifier = identifier.lower()

    if source == "isbn":
        from isbnlib import to_isbn13

        identifier = to_isbn13(identifier)

    standard_citekey = f"{source}:{identifier}"
    if warn_if_changed and citekey != standard_citekey:
        logging.warning(
            f"standardize_citekey expected citekey to already be standardized.\n"
            f"Instead citekey was changed from {citekey!r} to {standard_citekey!r}"
        )
    return standard_citekey
github JackPotte / JackBot / core / scripts / isbn.py View on Github external
i = stdnum.isbn.to_isbn13(isbn)
        return i

    try:
        isbnlib
    except NameError:
        pass
    else:
        try:
            is_valid(isbn)
        except InvalidIsbnException:
            return isbn
        # remove hyphenation, otherwise isbnlib.to_isbn13() returns None
        i = isbnlib.canonical(isbn)
        if i == isbn:
            i13 = isbnlib.to_isbn13(i)
            return i13
        # add removed hyphenation
        i13 = isbnlib.to_isbn13(i)
        i13h = hyphenateIsbnNumbers('ISBN ' + i13)
        return i13h[5:]

    try:
        is_valid(isbn)
    except InvalidIsbnException:
        # don't change
        return isbn
    i1x = getIsbn(isbn)
    if not isinstance(i1x, ISBN13):
        i13 = i1x.toISBN13()
    else:
        i13 = i1x
github JackPotte / JackBot / core / scripts / isbn.py View on Github external
try:
        isbnlib
    except NameError:
        pass
    else:
        try:
            is_valid(isbn)
        except InvalidIsbnException:
            return isbn
        # remove hyphenation, otherwise isbnlib.to_isbn13() returns None
        i = isbnlib.canonical(isbn)
        if i == isbn:
            i13 = isbnlib.to_isbn13(i)
            return i13
        # add removed hyphenation
        i13 = isbnlib.to_isbn13(i)
        i13h = hyphenateIsbnNumbers('ISBN ' + i13)
        return i13h[5:]

    try:
        is_valid(isbn)
    except InvalidIsbnException:
        # don't change
        return isbn
    i1x = getIsbn(isbn)
    if not isinstance(i1x, ISBN13):
        i13 = i1x.toISBN13()
    else:
        i13 = i1x
    return i13.code
github wikimedia / pywikibot / scripts / isbn.py View on Github external
try:
        isbnlib
    except NameError:
        pass
    else:
        try:
            is_valid(isbn)
        except InvalidIsbnException:
            return isbn
        # remove hyphenation, otherwise isbnlib.to_isbn13() returns None
        i = isbnlib.canonical(isbn)
        if i == isbn:
            i13 = isbnlib.to_isbn13(i)
            return i13
        # add removed hyphenation
        i13 = isbnlib.to_isbn13(i)
        i13h = hyphenateIsbnNumbers('ISBN ' + i13)
        return i13h[5:]

    try:
        is_valid(isbn)
    except InvalidIsbnException:
        # don't change
        return isbn
    i1x = getIsbn(isbn)
    if not isinstance(i1x, ISBN13):
        i13 = i1x.toISBN13()
    else:
        i13 = i1x
    return i13.code
github manubot / manubot / manubot / cite / isbn.py View on Github external
def get_isbn_csl_item(isbn):
    """
    Generate CSL JSON Data for an ISBN. Converts all ISBNs to 13-digit format.

    This function uses a list of CSL JSON Item metadata retrievers, specified
    by the module-level variable `isbn_retrievers`. The methods are attempted
    in order, with this function returning the metadata from the first
    non-failing method.
    """
    import isbnlib

    isbn = isbnlib.to_isbn13(isbn)
    for retriever in isbn_retrievers:
        try:
            return retriever(isbn)
        except Exception as error:
            logging.warning(
                f"Error in {retriever.__name__} for {isbn} "
                f"due to a {error.__class__.__name__}:\n{error}"
            )
            logging.info(error, exc_info=True)
    raise Exception(f"all get_isbn_csl_item methods failed for {isbn}")
github wikimedia / pywikibot / scripts / isbn.py View on Github external
i = stdnum.isbn.to_isbn13(isbn)
        return i

    try:
        isbnlib
    except NameError:
        pass
    else:
        try:
            is_valid(isbn)
        except InvalidIsbnException:
            return isbn
        # remove hyphenation, otherwise isbnlib.to_isbn13() returns None
        i = isbnlib.canonical(isbn)
        if i == isbn:
            i13 = isbnlib.to_isbn13(i)
            return i13
        # add removed hyphenation
        i13 = isbnlib.to_isbn13(i)
        i13h = hyphenateIsbnNumbers('ISBN ' + i13)
        return i13h[5:]

    try:
        is_valid(isbn)
    except InvalidIsbnException:
        # don't change
        return isbn
    i1x = getIsbn(isbn)
    if not isinstance(i1x, ISBN13):
        i13 = i1x.toISBN13()
    else:
        i13 = i1x
github NYPL-Simplified / circulation / api / odilo.py View on Github external
for format_received in book.get('formats', []):
            if format_received in cls.format_data_for_odilo_format:
                medium = cls.set_format(format_received, formats)
            elif format_received == cls.ACSM and file_format:
                medium = cls.set_format(format_received + '_' + file_format.upper(), formats)
            else:
                cls.log.warn('Unrecognized format received: ' + format_received)

        if not medium:
            medium = Edition.BOOK_MEDIUM

        identifiers = []
        isbn = book.get('isbn')
        if isbn:
            if isbnlib.is_isbn10(isbn):
                isbn = isbnlib.to_isbn13(isbn)
            identifiers.append(IdentifierData(Identifier.ISBN, isbn, 1))

        # A cover
        links = []
        cover_image_url = book.get('coverImageUrl')
        if cover_image_url:
            image_data = cls.image_link_to_linkdata(cover_image_url, Hyperlink.THUMBNAIL_IMAGE)
            if image_data:
                links.append(image_data)

        original_image_url = book.get('originalImageUrl')
        if original_image_url:
            image_data = cls.image_link_to_linkdata(original_image_url, Hyperlink.IMAGE)
            if image_data:
                links.append(image_data)