How to use the isbnlib.meta 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 materialsintelligence / propnet / propnet / core / utils.py View on Github external
if ref in _REFERENCE_CACHE:
            parsed_ref = _REFERENCE_CACHE[ref]
        elif ref.startswith('@'):
            parsed_ref = ref
        elif ref.startswith('url:'):
            # uses arbitrary key
            url = ref.split('url:')[1]
            parsed_ref = """@misc{{url:{0},
                       url = {{{1}}}
                       }}""".format(str(abs(url.__hash__()))[0:6], url)
        elif ref.startswith('doi:'):
            doi = ref.split('doi:')[1]
            parsed_ref = content_negotiation(doi, format='bibentry')
        elif ref.startswith('isbn:'):
            isbn = ref.split('isbn:')[1]
            parsed_ref = bibformatters['bibtex'](meta(isbn))
        else:
            raise ValueError('Unknown reference style for '
                             'reference: {} (please either '
                             'supply a BibTeX string, or a string '
                             'starting with url: followed by a URL or '
                             'starting with doi: followed by a DOI)'.format(ref))

        if check_if_valid_citation:
            try:
                _ = references_to_markdown(parsed_ref)
            except Exception as ex:
                raise ValueError("Reference '{}' returned the following error.\n"
                                 "You may need to manually generate a bibtex string:\n"
                                 "{}".format(ref, ex))
        if ref not in _REFERENCE_CACHE:
            _REFERENCE_CACHE[ref] = parsed_ref
github EugenePig / ebook-isbn / bookinfo / metasearch.py View on Github external
def call_isbnlin_meta(self, isbn):

        meta = {}
        logger.debug('Searching ' + isbn + ' on ' + self.isbndb)
        count = 0
        while count <= self.MAX_HTTP_RETRY:
            try:
                meta = isbnlib.meta(isbn,  self.isbndb)
            except Exception as ex:
                if ex.message.startswith('an HTTP error has ocurred'):
                    logger.debug('HTTP error ... ...')
                    logger.debug('Sleep Start : %s' % time.ctime())
                    count += 1
                    time.sleep(self.LONG_SLEEP * count)
                    logger.debug('Sleep End : %s' % time.ctime())
                    logger.debug('End of Try ' + str(count))
                elif ex.message.startswith('an URL error has ocurred'):
                    logger.debug('URL error ... ...')
                    count += 1
                else:
                    logger.debug('Exception: ' + ex.message)
                    logger.debug('Metadata of ISBN ' + isbn + ' Not Found')
                    logger.debug('')
                    if self.status != self.STATUS_HTTPERROR:
github Phyks / libbmc / libbmc / isbn.py View on Github external
Get a BibTeX string for the given ISBN.

    :param isbn_identifier: ISBN to fetch BibTeX entry for.
    :returns: A BibTeX string or ``None`` if could not fetch it.

    >>> get_bibtex('9783161484100')
    '@book{9783161484100,\\n     title = {Berkeley, Oakland: Albany, Emeryville, Alameda, Kensington},\\n    author = {Peekaboo Maps},\\n      isbn = {9783161484100},\\n      year = {2009},\\n publisher = {Peek A Boo Maps}\\n}'
    """
    # Try to find the BibTeX using associated DOIs
    bibtex = doi.get_bibtex(to_doi(isbn_identifier))
    if bibtex is None:
        # In some cases, there are no DOIs for a given ISBN. In this case, try
        # to fetch bibtex directly from the ISBN, using a combination of
        # Google Books and worldcat.org results.
        bibtex = isbnlib.registry.bibformatters['bibtex'](
            isbnlib.meta(isbn_identifier, 'default'))
    return bibtex
github akkana / scripts / bookfind.py View on Github external
def book_by_ISBN(self, isbn):
        # print("Looking up ISBN", isbn)
        meta = isbnlib.meta(isbn)
        return Book(isbn, meta['Title'], meta['Authors'], '',
                    meta['Year'], 0)