aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools/importers/orcid.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/fatcat_tools/importers/orcid.py')
-rw-r--r--python/fatcat_tools/importers/orcid.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/python/fatcat_tools/importers/orcid.py b/python/fatcat_tools/importers/orcid.py
index 3bdd23a1..b514e6e5 100644
--- a/python/fatcat_tools/importers/orcid.py
+++ b/python/fatcat_tools/importers/orcid.py
@@ -1,4 +1,3 @@
-
import sys
import fatcat_openapi_client
@@ -8,7 +7,7 @@ from .common import EntityImporter, clean
def value_or_none(e):
if type(e) == dict:
- e = e.get('value')
+ e = e.get("value")
if type(e) == str and len(e) == 0:
e = None
# TODO: this is probably bogus; patched in desperation; remove?
@@ -21,18 +20,17 @@ def value_or_none(e):
return None
return e
-class OrcidImporter(EntityImporter):
+class OrcidImporter(EntityImporter):
def __init__(self, api, **kwargs):
- eg_desc = kwargs.get('editgroup_description',
- "Automated import of ORCID metadata, from official bulk releases.")
- eg_extra = kwargs.get('editgroup_extra', dict())
- eg_extra['agent'] = eg_extra.get('agent', 'fatcat_tools.OrcidImporter')
- super().__init__(api,
- editgroup_description=eg_desc,
- editgroup_extra=eg_extra,
- **kwargs)
+ eg_desc = kwargs.get(
+ "editgroup_description",
+ "Automated import of ORCID metadata, from official bulk releases.",
+ )
+ eg_extra = kwargs.get("editgroup_extra", dict())
+ eg_extra["agent"] = eg_extra.get("agent", "fatcat_tools.OrcidImporter")
+ super().__init__(api, editgroup_description=eg_desc, editgroup_extra=eg_extra, **kwargs)
def want(self, raw_record):
return True
@@ -43,16 +41,16 @@ class OrcidImporter(EntityImporter):
returns a CreatorEntity
"""
- if 'person' not in obj:
+ if "person" not in obj:
return False
- name = obj['person']['name']
+ name = obj["person"]["name"]
if not name:
return None
extra = None
- given = value_or_none(name.get('given-names'))
- sur = value_or_none(name.get('family-name'))
- display = value_or_none(name.get('credit-name'))
+ given = value_or_none(name.get("given-names"))
+ sur = value_or_none(name.get("family-name"))
+ display = value_or_none(name.get("credit-name"))
if display is None:
# TODO: sorry human beings
if given and sur:
@@ -61,7 +59,7 @@ class OrcidImporter(EntityImporter):
display = sur
elif given:
display = given
- orcid = obj['orcid-identifier']['path']
+ orcid = obj["orcid-identifier"]["path"]
if not self.is_orcid(orcid):
sys.stderr.write("Bad ORCID: {}\n".format(orcid))
return None
@@ -74,7 +72,8 @@ class OrcidImporter(EntityImporter):
given_name=clean(given),
surname=clean(sur),
display_name=display,
- extra=extra)
+ extra=extra,
+ )
return ce
def try_update(self, raw_record):
@@ -88,14 +87,17 @@ class OrcidImporter(EntityImporter):
# eventually we'll want to support "updates", but for now just skip if
# entity already exists
if existing:
- self.counts['exists'] += 1
+ self.counts["exists"] += 1
return False
return True
def insert_batch(self, batch):
- self.api.create_creator_auto_batch(fatcat_openapi_client.CreatorAutoBatch(
- editgroup=fatcat_openapi_client.Editgroup(
- description=self.editgroup_description,
- extra=self.editgroup_extra),
- entity_list=batch))
+ self.api.create_creator_auto_batch(
+ fatcat_openapi_client.CreatorAutoBatch(
+ editgroup=fatcat_openapi_client.Editgroup(
+ description=self.editgroup_description, extra=self.editgroup_extra
+ ),
+ entity_list=batch,
+ )
+ )