def get_value(value): affiliations = [] if value.get('u'): recid = None try: recid = int(value.get('z')) except: pass affiliations = inspire_dojson_utils.remove_duplicates_from_list( utils.force_list(value.get('u'))) record = inspire_dojson_utils.get_record_ref(recid, 'institutions') affiliations = [{ 'value': aff, 'record': record } for aff in affiliations] person_recid = None if value.get('x'): try: person_recid = int(value.get('x')) except: pass inspire_id = '' if value.get('i'): inspire_id = utils.force_list(value.get('i'))[0] person_record = inspire_dojson_utils.get_record_ref( person_recid, 'authors') ret = { 'full_name': value.get('a'), 'role': value.get('e'), 'alternative_name': value.get('q'), 'inspire_id': inspire_id, 'orcid': value.get('j'), 'record': person_record, 'email': value.get('m'), 'affiliations': affiliations, 'profile': { "__url__": inspire_dojson_utils.create_profile_url(value.get('x')) }, 'curated_relation': value.get('y', 0) == 1 } # HACK: This is to workaround broken records where multiple authors # got meshed up together. if isinstance(ret['full_name'], (list, tuple)): import warnings warnings.warn( "Record with mashed-up author list! Taking first author: {}". format(value)) ret['full_name'] = ret['full_name'][0] return ret
def get_value(value): affiliations = [] if value.get('u'): recid = None try: recid = int(value.get('z')) except: pass affiliations = inspire_dojson_utils.remove_duplicates_from_list( utils.force_list(value.get('u'))) record = inspire_dojson_utils.get_record_ref(recid, 'institutions') affiliations = [{'value': aff, 'record': record} for aff in affiliations] person_recid = None if value.get('x'): try: person_recid = int(value.get('x')) except: pass inspire_id = '' if value.get('i'): inspire_id = utils.force_list(value.get('i'))[0] person_record = inspire_dojson_utils.get_record_ref(person_recid, 'authors') ret = { 'full_name': value.get('a'), 'role': value.get('e'), 'alternative_name': value.get('q'), 'inspire_id': inspire_id, 'inspire_bai': value.get('w'), 'orcid': value.get('j'), 'record': person_record, 'email': value.get('m'), 'affiliations': affiliations, 'profile': {"__url__": inspire_dojson_utils.create_profile_url( value.get('x') )}, 'curated_relation': value.get('y', 0) == 1 } # HACK: This is to workaround broken records where multiple authors # got meshed up together. if isinstance(ret['full_name'], (list, tuple)): import warnings warnings.warn("Record with mashed-up author list! Taking first author: {}".format(value)) ret['full_name'] = ret['full_name'][0] return ret
def get_value(value): affiliations = [] curated_relation = False if value.get('u'): recid = '' try: recid = int(value.get('z')) except: pass affiliations = list(set(utils.force_list( value.get('u')))) affiliations = [{'value': aff, 'recid': recid} for aff in affiliations] if value.get('y'): if value.get('y') == '1': curated_relation = True elif value.get('z'): curated_relation = True ret = { 'full_name': value.get('a'), 'role': value.get('e'), 'alternative_name': value.get('q'), 'inspire_id': value.get('i'), 'orcid': value.get('j'), 'recid': value.get('x'), 'email': value.get('m'), 'affiliations': affiliations, 'profile': inspire_dojson_utils.create_profile_url( value.get('x') ), 'curated_relation': curated_relation } # HACK: This is to workaround broken records where multiple authors # got meshed up together. if isinstance(ret['full_name'], list): import warnings warnings.warn("Record with mashed-up author list! Taking first author: {}".format(value)) ret['full_name'] = ret['full_name'][0] return ret
def test_create_profile_url_returns_empty_string_when_not_given_an_int(): expected = '' result = create_profile_url('foo') assert expected == result
def test_create_profile_url_returns_link_when_given_an_int(): expected = 'http://inspirehep.net/record/1010819' result = create_profile_url('1010819') assert expected == result