How to use the isbntools.config.options.get function in isbntools

To help you get started, we’ve selected a few isbntools 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 / isbntools / isbntools / _metadata.py View on Github external
try:
        # try write conf for the next time!
        from .contrib._hook import mk_conf
        mk_conf()
    except:
        pass
    # only useful for development
    DEFAULT_CACHE = os.path.join(os.path.dirname(
        os.path.abspath(__file__)), CACHE_FILE)
    try:
        writable = os.access(DEFAULT_CACHE, os.W_OK)
    except:
        writable = False

DEFAULT_CACHE = DEFAULT_CACHE if writable else 'no'
CACHE = options.get('CACHE', DEFAULT_CACHE)
CACHE = None if CACHE.lower() == 'no' else CACHE


def query(isbn, service='default', cache=CACHE):
    """Query worldcat.org, Google Books (JSON API), ... for metadata."""
    ean = EAN13(isbn)
    if not ean:
        raise NotValidISBNError(isbn)
    isbn = ean
    if service != 'default' and service not in services:
        raise NotRecognizedServiceError(service)
    if cache is None:  # pragma: no cover
        return services[service](isbn)
    kache = Cache(cache)
    key = isbn + service
    if kache[key]:
github xlcnd / isbntools / isbntools / _merge.py View on Github external
def query(isbn, processor=None):
    """Query function for the `merge provider` (waterfall model)."""
    if not processor:
        processor = config.options.get('VIAS_MERGE', processor)
        if not processor:     # pragma: no cover
            processor = 'serial'

    named_tasks = (('wcat', qwcat), ('goob', qgoob))
    if processor == 'parallel':
        results = vias.parallel(named_tasks, isbn)
    elif processor == 'serial':
        results = vias.serial(named_tasks, isbn)
    elif processor == 'multi':
        results = vias.multi(named_tasks, isbn)

    rw = results.get('wcat')
    rg = results.get('goob')

    md = Metadata(rw) if rw else None
github xlcnd / isbntools / isbntools / _metadata.py View on Github external
# -*- coding: utf-8 -*-
"""Query providers for metadata."""

import os
from .registry import services
from .exceptions import NotRecognizedServiceError
from .config import options, CONF_PATH, CACHE_FILE
from ._cache import Cache


if CONF_PATH:
    DEFAULT_CACHE = os.path.join(CONF_PATH, CACHE_FILE)
else:           # pragma: no cover
    DEFAULT_CACHE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 CACHE_FILE)
CACHE = options.get('CACHE', DEFAULT_CACHE)
CACHE = None if CACHE.lower() == 'no' else CACHE


def query(isbn, service='default', cache=CACHE):
    """Query worldcat.org, Google Books (JSON API), ... for metadata."""
    if service != 'default' and service not in services:
        raise NotRecognizedServiceError(service)
    if not cache:
        return services[service](isbn)
    kache = Cache() if cache == 'default' else Cache(cache)
    key = isbn + service
    if kache[key]:
        return kache[key]
    meta = services[service](isbn)
    if meta and service != 'cache':
        kache[key] = meta