How to use the isbnlib.dev._bouth23.u 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 / _wcat.py View on Github external
def _mapper(isbn, records):
    """Map: canonical <- records."""
    # canonical: ISBN-13, Title, Authors, Publisher, Year, Language
    try:
        canonical = {}
        canonical['ISBN-13'] = u(isbn)
        canonical['Title'] = records.get('title', u('')).replace(' :', ':')
        buf = records.get('author', u(''))
        canonical['Authors'] = [x.strip('. ') for x in buf.split(';')]
        canonical['Publisher'] = records.get('publisher', u(''))
        canonical['Year'] = records.get('year', u(''))
        canonical['Language'] = records.get('lang', u(''))
    except:  # pragma: no cover
        LOGGER.debug("RecordMappingError for %s with data %s", isbn, records)
        raise RecordMappingError(isbn)
    # call stdmeta for extra cleanning and validation
    return stdmeta(canonical)
github xlcnd / isbntools / isbntools / contrib / modules / rename / _rename.py View on Github external
if d['title'] == u('UNKNOWN') or d['isbn'] == u('UNKNOWN'):
        LOGGER.critical('Not enough metadata')
        return None
    d['title'] = cleannewname(d['title'])
    cutoff = min(len(d['title']), CUTOFF)
    d['title'] = ' '.join(cutoff_tokens(d['title'].split(' '), cutoff))

    authorslastnames = [
        last_first(authorname)['last'] for authorname in metadata['Authors']
    ]
    d['authorsLastNames'] = ','.join(authorslastnames)
    d['firstAuthorLastName'] = authorslastnames[0]

    try:
        formatted = u(pattern).format(**d)
        return cleannewname(formatted)
    except KeyError as e:
        LOGGER.warning('Error with placeholder: %s', e)
        return None
github xlcnd / isbnlib / isbnlib / _wiki.py View on Github external
def _mapper(isbn, records):
    """Map canonical <- records."""
    # canonical:
    # -> ISBN-13, Title, Authors, Publisher, Year, Language
    try:
        # mapping: canonical <- records
        canonical = {}
        canonical['ISBN-13'] = u(isbn)
        canonical['Title'] = records.get('title', u('')).replace(' :', ':')
        # try to handle the inconsistent use of fields by Wikipedia (issue #65)!
        try:
            authors = [
                author for sublist in records.get('authors', [])
                for author in sublist if author
            ]
            canonical['Authors'] = [
                author.replace('.', u('')) for author in authors
            ]
            if not canonical['Authors']:
                raise IndexError
        except IndexError:
            try:
                authors = [
                    author for sublist in records.get('contributor', [])
                    for author in sublist if author
github xlcnd / isbnlib / isbnlib / _isbndb.py View on Github external
# -> ISBN-13, Title, Authors, Publisher, Year, Language
    try:
        # mapping: canonical <- records
        canonical = {}
        canonical['ISBN-13'] = u(isbn)
        # assert isbn == records['isbn13'], "isbn was mungled!"
        canonical['Title'] = records.get('title', u(''))
        authors = [a['name'] for a in records['author_data']]
        canonical['Authors'] = authors
        canonical['Publisher'] = records.get('publisher_name', u(''))
        canonical['Year'] = u('')
        if 'edition_info' in records:
            match = re.search(PATT_YEAR, records['edition_info'])
            if match:
                canonical['Year'] = str(match.group(0))
        canonical['Language'] = records.get('language', u(''))
    except:
        raise RecordMappingError(isbn)
    # call stdmeta for extra cleanning and validation
    return stdmeta(canonical)
github xlcnd / isbnlib / isbnlib / _wiki.py View on Github external
def _mapper(isbn, records):
    """Map canonical <- records."""
    # canonical:
    # -> ISBN-13, Title, Authors, Publisher, Year, Language
    try:
        # mapping: canonical <- records
        canonical = {}
        canonical['ISBN-13'] = u(isbn)
        canonical['Title'] = records.get('title', u('')).replace(' :', ':')
        # try to handle the inconsistent use of fields by Wikipedia (issue #65)!
        try:
            authors = [
                author for sublist in records.get('authors', [])
                for author in sublist if author
            ]
            canonical['Authors'] = [
                author.replace('.', u('')) for author in authors
            ]
            if not canonical['Authors']:
                raise IndexError
        except IndexError:
            try:
                authors = [
                    author for sublist in records.get('contributor', [])
github xlcnd / isbnlib / isbnlib / dev / _data.py View on Github external
def _set_empty(self):
        """Set an empty value record."""
        self._content = dict.fromkeys(list(FIELDS), u(''))
        self._content['Authors'] = [u('')]
github xlcnd / isbnlib / isbnlib / _goob.py View on Github external
def _records(isbn, data):
    """Classify (canonically) the parsed data."""
    # put the selected data in records
    try:
        recs = data['items'][0]['volumeInfo']
    except Exception:  # pragma: no cover
        # don't raise exception!
        LOGGER.debug('No data from "goob" for isbn %s', isbn)
        return {}
    # consistency check (isbn request = isbn response)
    if recs:
        ids = recs.get('industryIdentifiers', '')
        if u('ISBN_13') in repr(ids) and isbn not in repr(
                ids):  # pragma: no cover
            LOGGER.debug('ISBNNotConsistentError for %s (%s)', isbn, repr(ids))
            raise ISBNNotConsistentError('{0} not in {1}'.format(
                isbn, repr(ids)))
    else:
        return {}  # pragma: no cover
    # map canonical <- records
    return _mapper(isbn, recs)
github xlcnd / isbnlib / isbnlib / _wiki.py View on Github external
author.replace('.', u('')) for author in authors
            ]
            if not canonical['Authors']:
                raise IndexError
        except IndexError:
            try:
                authors = [
                    author for sublist in records.get('contributor', [])
                    for author in sublist if author
                ]
                canonical['Authors'] = [
                    author.replace('.', u('')) for author in authors
                ]
            except IndexError:
                pass
        canonical['Publisher'] = records.get('publisher', u('')) or ' '.join(
            [pub for pub in records.get('contributor', [])[0] if pub])
        canonical['Year'] = u('')
        strdate = records.get('date', u(''))
        if strdate:  # pragma: no cover
            match = re.search(r'\d{4}', strdate)
            if match:
                canonical['Year'] = match.group(0)
    except Exception:  # pragma: no cover
        LOGGER.debug('RecordMappingError for %s with data %s', isbn, records)
        raise RecordMappingError(isbn)
    # call stdmeta for extra cleanning and validation
    return stdmeta(canonical)