How to use the isbnlib.get_canonical_isbn 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 EugenePig / ebook-isbn / bookinfo / metasearch.py View on Github external
matches = regex.findall(line)
            if len(matches) > 0:
                logger.debug('Unchecked [' + ' '.join(matches) + ']')
                for match in matches:
                    match = match.strip()
                    match = match.replace('i', 'I')
                    match = match.replace('s', 'S')
                    match = match.replace('b', 'B')
                    match = match.replace('n', 'N')
                    match = re.sub(r'\x20', '', match)
                    match = re.sub(r'ISBN', 'ISBN\x20', match)
                    # logger.debug('match= ' + match)
                    if match not in self.SPECIAL_ISBN:
                        try:
                            # logger.debug('isbn= ' + isbn)
                            isbn = isbnlib.get_canonical_isbn(match)
                        except:
                            logger.error('Error in isbnlib while calling get_canonical_isbn')
                        else:
                            if isbn:
                                isbns.append(isbn)
        return isbns
github Phyks / libbmc / libbmc / isbn.py View on Github external
def extract_from_text(text):
    """
    Extract ISBNs from a text.

    :param text: Some text.
    :returns: A list of canonical ISBNs found in the text.

    >>> extract_from_text("978-3-16-148410-0 9783161484100 9783161484100aa abcd 0136091814 0136091812 9780136091817 123456789X")
    ['9783161484100', '9783161484100', '9783161484100', '0136091814', '123456789X']
    """
    isbns = [isbnlib.get_canonical_isbn(isbn)
             for isbn in isbnlib.get_isbnlike(text)]
    return [i for i in isbns if i is not None]
github michaelmcmillan / LittList / src / book / isbn.py View on Github external
def number(self):
        return get_canonical_isbn(self._number) \
            if self._number else None
github xlcnd / isbnlib / isbnlib / _openled.py View on Github external
data = wquery(SERVICE_URL.format(selectors=CODES.format(isbn=isbn)),
                      user_agent=UA)
        codes = {rec['key'] for rec in data}
        isbnlikes = [isbn]
        for code in codes:
            txt = wquery(
                SERVICE_URL.format(selectors=ISBNS.format(code=code)),
                user_agent=UA,
                parser=None,
            )
            isbnlikes.extend(get_isbnlike(txt))
        isbns = {u(get_canonical_isbn(isbnlike)) for isbnlike in isbnlikes}
    except Exception as ex:  # pragma: no cover
        LOGGER.debug('No data from Open Library for isbn %s -- %s', isbn,
                     str(ex))
        return {get_canonical_isbn(isbn)}
    return isbns
github xlcnd / isbnlib / isbnlib / _openled.py View on Github external
def query(isbn):
    """Query the Open Library for related ISBNs."""
    try:
        data = wquery(SERVICE_URL.format(selectors=CODES.format(isbn=isbn)),
                      user_agent=UA)
        codes = {rec['key'] for rec in data}
        isbnlikes = [isbn]
        for code in codes:
            txt = wquery(
                SERVICE_URL.format(selectors=ISBNS.format(code=code)),
                user_agent=UA,
                parser=None,
            )
            isbnlikes.extend(get_isbnlike(txt))
        isbns = {u(get_canonical_isbn(isbnlike)) for isbnlike in isbnlikes}
    except Exception as ex:  # pragma: no cover
        LOGGER.debug('No data from Open Library for isbn %s -- %s', isbn,
                     str(ex))
        return {get_canonical_isbn(isbn)}
    return isbns
github EugenePig / ebook-isbn / bookinfo / metasearch.py View on Github external
def get_canonical_isbn2(self, line):
        # logger.debug('[ ' + line + ' ]')
        isbns = []
        matches = isbnlib.get_isbnlike(line)
        if len(matches) > 0:
            logger.debug('Unchecked [' + ' '.join(matches) + ']')
        for match in matches:
            if match not in self.SPECIAL_ISBN and not any(match in s for s in isbns):
                try:
                    # logger.debug('isbn= ' + isbn)
                    isbn = isbnlib.get_canonical_isbn(match)
                except:
                    logger.error('Error in isbnlib while calling get_canonical_isbn')
                else:
                    if isbn:
                        isbns.append(isbn)
        return isbns
github Phyks / libbmc / libbmc / isbn.py View on Github external
>>> is_valid("0136091814")
    True

    >>> is_valid("0136091812")
    False

    >>> is_valid("9780136091817")
    False

    >>> is_valid("123456789X")
    True
    """
    return (
        (not isbnlib.notisbn(isbn_id)) and (
            isbnlib.get_canonical_isbn(isbn_id) == isbn_id or
            isbnlib.mask(isbnlib.get_canonical_isbn(isbn_id)) == isbn_id)
    )
github Phyks / libbmc / libbmc / isbn.py View on Github external
>>> is_valid("0136091814")
    True

    >>> is_valid("0136091812")
    False

    >>> is_valid("9780136091817")
    False

    >>> is_valid("123456789X")
    True
    """
    return (
        (not isbnlib.notisbn(isbn_id)) and (
            isbnlib.get_canonical_isbn(isbn_id) == isbn_id or
            isbnlib.mask(isbnlib.get_canonical_isbn(isbn_id)) == isbn_id)
    )