Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with single values (name-only author, only one publication) #3

Open
mslw opened this issue Jun 22, 2023 · 0 comments
Open

Dealing with single values (name-only author, only one publication) #3

mslw opened this issue Jun 22, 2023 · 0 comments

Comments

@mslw
Copy link

mslw commented Jun 22, 2023

  1. If one publication is defined, the main parsing loop will produce a dict. Subsequent code expects a list, and would iterate over a dictionary instead.
  2. When an author is provided with only a name (only mandatory), and no subsequent columns, it will be parsed as a string. Subsequent code expects a dict, and would try to get by key.

This is a simple patch that deals with this cases "downstream", but maybe it would be better to change the main parsing loop.

diff --git a/bin/tubby2catalog b/bin/tubby2catalog
index e8488d5..84d3cc5 100755
--- a/bin/tubby2catalog
+++ b/bin/tubby2catalog
@@ -212,10 +212,15 @@ def map_to_catalog(metadata, config):
         elif key == 'publications':
             if key not in meta_item.keys():
                 meta_item[key] = []
-            for pub in metadata[key]:
-                meta_item[key].append(
-                    get_publication(pub)
-                )
+            if isinstance(metadata[key], dict):
+                # only a single item was found, do not iterate
+                pub = metadata[key]
+                meta_item[key].append(get_publication(pub))
+            else:
+                for pub in metadata[key]:
+                    meta_item[key].append(
+                        get_publication(pub)
+                    )
         else:
             meta_item[key] = metadata[key]
 
@@ -250,9 +255,16 @@ def get_dataset_version(input):
 
 
 def get_author(author):
-    full_name = author.get('full_name', None)
-    email = author.get('email', None)
-    orcid = author.get('orcid', None)
+    if isinstance(author, str):
+        # single-values are not mapped into dictionaries
+        # putting more tabs doesn't help because rstrip strips them all
+        full_name = author
+        email = None
+        orcid = None
+    else:
+        full_name = author.get('full_name', None)
+        email = author.get('email', None)
+        orcid = author.get('orcid', None)
     identifiers = [{
         'type': 'ORCID',
         'identifier': orcid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant