From 7de80cd1641f575795067bcfa6aefca6eaa7f052 Mon Sep 17 00:00:00 2001 From: Vinay Goel Date: Thu, 21 Jun 2018 21:23:54 +0000 Subject: ORCID importer tweaks --- python/fatcat/orcid_importer.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/python/fatcat/orcid_importer.py b/python/fatcat/orcid_importer.py index fb4716df..a480be16 100644 --- a/python/fatcat/orcid_importer.py +++ b/python/fatcat/orcid_importer.py @@ -11,6 +11,14 @@ def value_or_none(e): e = e.get('value') if type(e) == str and len(e) == 0: e = None + # TODO: this is probably bogus; patched in desperation; remove? + if e: + try: + e.encode() + except UnicodeEncodeError: + # Invalid JSON? + print("BAD UNICODE") + return None return e class FatcatOrcidImporter(FatcatImporter): @@ -29,7 +37,15 @@ class FatcatOrcidImporter(FatcatImporter): display = value_or_none(name.get('credit-name')) if display is None: # TODO: sorry human beings - display = "{} {}".format(given, sur) + if given and sur: + display = "{} {}".format(given, sur) + elif sur: + display = sur + elif given: + display = given + else: + # must have *some* name + return None ce = fatcat_client.CreatorEntity( orcid=obj['orcid-identifier']['path'], given_name=given, -- cgit v1.2.3