Exemplo n.º 1
0
def do_we_want_it(isbn, work_id):
    """
    Returns True if we don't have this edition (or other editions of
    the same work), if the isbn has not been promised to us, has not
    yet been sponsored, and is not already in our possession.

    :param str isbn: isbn10 or isbn13
    :param str work_id: e.g. OL123W
    :rtype: (bool, list)
    :return: bool answer to do-we-want-it, list of matching books
    """
    availability = lending.get_work_availability(work_id)  # checks all editions
    if availability and availability.get(work_id, {}).get('status', 'error') != 'error':
        return False, availability

    # We don't have any of these work's editions available to borrow
    # Let's confirm this edition hasn't already been sponsored or promised
    params = {
        'search_field': 'isbn',
        'include_promises': 'true',  # include promises and sponsored books
        'search_id': isbn
    }
    url = '%s/book/marc/ol_dedupe.php?%s' % (lending.config_ia_domain,  urllib.urlencode(params))
    r = requests.get(url)
    try:
        data = r.json()
        dwwi = data.get('response', 0)
        return dwwi==1, data.get('books', [])
    except:
        logger.error("DWWI Failed for isbn %s" % isbn, exc_info=True)
    # err on the side of false negative
    return False, []
Exemplo n.º 2
0
    def get_representative_edition(self):
        """When we have confidence we can direct patrons to the best edition
        of a work (for them), return qualifying edition key. Attempts
        to find best (most available) edition of work using
        archive.org work availability API. May be extended to support language

        :rtype str: infogami edition key or url which resolves to an edition
        """
        work_id = self.key.replace('/works/', '')
        availability = lending.get_work_availability(work_id)
        if work_id in availability:
            if 'openlibrary_edition' in availability[work_id]:
                return '/books/%s' % availability[work_id]['openlibrary_edition']