Skip to content

Commit

Permalink
harvester: better author parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Dec 3, 2018
1 parent cbbcb83 commit fd4f0af
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions asclepias_broker/harvester/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ def crossref_metadata(doi: str) -> dict:
}
if metadata.get('title'):
result['Title'] = metadata['title'][0]
creators = []
for author_field in ('author', 'editor'):
if metadata.get(author_field):
result['Creator'] = [{'Name': '{family}, {given}'.format_map(a)}
for a in metadata[author_field]]
authors = metadata.get(author_field, [])
for author in authors:
if author.get('family') and author.get('given'):
creators.append(
'{}, {}'.format(author['family'], author['given']))
if creators:
result['Creator'] = [{'Name': c} for c in creators]

if metadata.get('publisher'):
result['Publisher'] = [{'Name': metadata['publisher']}]

Expand Down Expand Up @@ -81,16 +87,20 @@ def datacite_metadata(doi: str) -> dict:
}
if metadata.get('title'):
result['Title'] = metadata['title']

creators = []
if metadata.get('creator'):
result['Creator'] = []
for author in metadata['creator']:
if isinstance(author, str):
result['Creator'].append({'Name': author})
creators.append(author)
elif author.get('name'):
result['Creator'].append({'Name': author['name']})
creators.append(author['name'])
elif author.get('familyName') and author.get('givenName'):
result['Creator'].append(
{'Name': '{familyName}, {givenName}'.format_map(author)})
creators.append(
'{}, {}'.format(author['familyName'], author['givenName']))
if creators:
result['Creator'] = [{'Name': c} for c in creators]

result['PublicationDate'] = metadata['date_published']
return result

Expand Down

0 comments on commit fd4f0af

Please sign in to comment.