Ejemplo n.º 1
0
def mef_person_resolver(pid):
    """MEF person resolver."""
    mef_url = '{url}{pid}'.format(
        url=current_app.config.get('RERO_ILS_MEF_URL'), pid=pid)

    request = requests_get(url=mef_url, params=dict(resolve=1, sources=1))
    if request.status_code == requests_codes.ok:
        data = request.json().get('metadata')
        if data:
            author = {'type': 'person', 'pid': pid}
            for language in get_defined_languages():
                author['name_{language}'.format(
                    language=language)] = localized_data(
                        data, 'preferred_name_for_person', language)
            # date
            date_of_birth = get_mef_value(data, 'date_of_birth', '')
            date_of_death = get_mef_value(data, 'date_of_death', '')
            if date_of_birth or date_of_death:
                date = '{date_of_birth}-{date_of_death}'.format(
                    date_of_birth=date_of_birth, date_of_death=date_of_death)
                author['date'] = date
            # variant_name
            variant_person = []
            for source in data['sources']:
                if 'variant_name_for_person' in data[source]:
                    variant_person = variant_person +\
                        data[source]['variant_name_for_person']
            if variant_person:
                author['variant_name'] = unique_list(variant_person)
            return author
        else:
            current_app.logger.error(
                'Mef resolver no metadata: {result} {url}'.format(
                    result=request.json(), url=mef_url))
    else:
        current_app.logger.error(
            'Mef resolver request error: {result} {url}'.format(
                result=request.status_code, url=mef_url))
        raise Exception('unable to resolve')
Ejemplo n.º 2
0
def test_unique_list():
    """Test unicity of list."""
    list = ['python', 'snail', 'python', 'snail']
    assert ['python', 'snail'] == unique_list(list)