How to use the isbnlib.dev.cache 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 xlcnd / isbnlib / isbnlib / _goom.py View on Github external
@cache
def query(words):
    """Query the Google Books (JSON API v1) for metadata."""
    words.replace(' ', '+')
    words = quote(words)
    data = wquery(SERVICE_URL.format(words=words), UA)
    return _records(words, data) if data else {}
github xlcnd / isbnlib / isbnlib / _metadata.py View on Github external
@cache
def query(isbn, service='default'):
    """Query services like Google Books (JSON API), ... for metadata."""
    # validate inputs
    ean = EAN13(isbn)
    if not ean:
        LOGGER.critical('%s is not a valid ISBN', isbn)
        raise NotValidISBNError(isbn)
    isbn = ean
    # only import when needed
    from .registry import services

    if service != 'default' and service not in services:  # pragma: no cover
        LOGGER.critical('%s is not a valid service', service)
        raise NotRecognizedServiceError(service)
    meta = services[service](isbn)
    return meta or {}
github xlcnd / isbnlib / isbnlib / _doitotex.py View on Github external
@cache
def doi2tex(doi):
    """Get the bibtex ref for doi."""
    data = query(
        URL.format(DOI=doi),
        user_agent=UA,
        appheaders={
            'Accept': 'application/x-bibtex; charset=utf-8',
        },
    )  # noqa  pragma: no cover
    if not data:  # pragma: no cover
        LOGGER.warning('no data return for doi: %s', doi)
    return data if data else None  # pragma: no cover
github xlcnd / isbnlib / isbnlib / _cover.py View on Github external
@cache
def cover(isbn):
    """Get the urls for covers from Google Books."""
    data = wquery(SERVICE_URL.format(isbn=isbn), user_agent=UA)
    urls = {}
    try:
        urls = data['items'][0]['volumeInfo']['imageLinks']
    except (KeyError, IndexError):  # pragma: no cover
        LOGGER.debug('No cover img data for %s', isbn)
    return urls
github xlcnd / isbnlib / isbnlib / _desc.py View on Github external
@cache
def goo_desc(isbn):
    """Get description from Google Books api."""
    url = SERVICE_URL.format(isbn=isbn)
    content = wsquery(url, user_agent=UA)
    try:
        content = loads(content)
        content = content['items'][0]['volumeInfo']['description']
        # TODO(MV) don't format content here!
        content = fill(content, width=75) if content else ''
        return content
    except Exception:  # pragma: no cover
        LOGGER.debug('No description for %s', isbn)
        return ''
github xlcnd / isbnlib / isbnlib / _oclc.py View on Github external
@cache
def query_classify(isbn):
    """Query the classify.oclc service for classifiers."""
    return (wquery(
        SERVICE_URL.format(isbn=isbn),
        user_agent=UA,
        data_checker=data_checker,
        parser=parser,
    ) or {})
github xlcnd / isbnlib / isbnlib / _gwords.py View on Github external
@cache
def goos(words):
    """Use Google to get an ISBN from words from title and author's name."""
    service_url = 'http://www.google.com/search?q=ISBN+'
    search_url = service_url + quote(words.replace(' ', '+'))

    user_agent = 'w3m/0.5.3'

    content = webservice.query(
        search_url,
        user_agent=user_agent,
        appheaders={
            'Content-Type': 'text/plain; charset="UTF-8"',
            'Content-Transfer-Encoding': 'Quoted-Printable',
        },
    )
    isbns = get_isbnlike(content)
github xlcnd / isbnlib / isbnlib / _editions.py View on Github external
@cache
def get_editions(isbn, service):
    """Select the provider."""
    if service == 'merge':
        eds = _fake_provider_merge(isbn)
    if service == 'any':
        eds = _fake_provider_any(isbn)
    if service == 'openl':
        eds = list(_oed(isbn))
    if service == 'thingl':
        eds = list(_ted(isbn))
    if service == 'wiki':
        eds = list(_wiki(isbn))
    return list(set(map(to_isbn13, eds))) if eds else []