Repository: lubianat/pyorcidator

Issue:
Parse websites and social links
e.g. see https://orcid.org/0000-0002-5292-4083

Discussion:

Patch:
diff --git a/src/pyorcidator/helper.py b/src/pyorcidator/helper.py
index 278e5ea..03d15cc 100644
--- a/src/pyorcidator/helper.py
+++ b/src/pyorcidator/helper.py
@@ -5,6 +5,7 @@ Helper functions for pyorcidator
 import json
 import logging
 import re
+from typing import Mapping
 
 import requests
 
@@ -18,15 +19,30 @@ EXTERNAL_ID_PROPERTIES = {
     "Loop profile": "P2798",
     "Scopus Author ID": "P1153",
     "ResearcherID": "P1053",
+    "github": "P2037",
+    "twitter": "P2002",
+    "scopus": "P1153",
 }
-
-
-def get_external_ids(data):
-    id_list = data["person"]["external-identifiers"]["external-identifier"]
-    id_dict = {}
-    for id in id_list:
-        id_dict[id["external-id-type"]] = id["external-id-value"]
-    return id_dict
+PREFIXES = [
+    ("github", "https://github.com/"),
+    ("twitter", "https://twitter.com/"),
+    ("scopus", "https://www.scopus.com/authid/detail.uri?authorId=")
+    # TODO linkedin, figshare, researchgate, publons, semion, semantic scholar, google scholar, etc.
+]
+
+
+def get_external_ids(data) -> Mapping[str, str]:
+    """Get external identifiers that can be mapped to Wikidata properties."""
+    rv = {}
+    for d in data["person"]["external-identifiers"]["external-identifier"]:
+        rv[d["external-id-type"]] = d["external-id-value"]
+    for d in data["person"]["researcher-urls"].get("researcher-url", []):
+        # url_name = d["url-name"].lower().replace(" ", "")
+        url = d["url"]["value"].rstrip("/")
+        for key, url_prefix in PREFIXES:
+            if url.startswith(url_prefix):
+                rv[key] = url[len(url_prefix):]
+    return rv
 
 
 def render_orcid_qs(orcid):


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index fce1233..ebf0613 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,6 +3,8 @@ from pathlib import Path
 
 import pytest
 
+from pyorcidator.helper import get_external_ids, get_orcid_data
+
 
 @pytest.fixture
 def sample_orcid_data():
@@ -16,3 +18,12 @@ def wikidata_api_result():
     sample_path = Path(__file__).parent.joinpath("wikidata_api_result.json")
 
     return json.loads(sample_path.read_text())
+
+
+@pytest.fixture
+def orcid_w_external_links():
+    orcid = "0000-0002-0791-1347"  #   Selja Seppälä
+    data = get_orcid_data(orcid)
+    ids = get_external_ids(data)
+
+    return ids
diff --git a/tests/test_helper.py b/tests/test_helper.py
index 77e5caa..1f63d81 100644
--- a/tests/test_helper.py
+++ b/tests/test_helper.py
@@ -4,10 +4,11 @@ Tests for the helper module
 
 from pyorcidator.helper import (
     get_date,
+    get_external_ids,
+    get_orcid_data,
     get_organization_list,
     get_paper_dois,
     lookup_id,
-    get_external_ids,
     render_orcid_qs,
 )
 
@@ -57,3 +58,21 @@ def test_get_loop_id(sample_orcid_data):
 
 def test_render_orcid_runs():
     render_orcid_qs("0000-0003-4423-4370")
+
+
+def test_get_github(orcid_w_external_links):
+    """Test getting a github link."""
+    assert orcid_w_external_links["github"] == "seljaseppala"
+
+
+def test_get_twitter():
+    """Test getting a twitter link."""
+    orcid = "0000-0001-7542-0286"  # Egon Willighagen
+    data = get_orcid_data(orcid)
+    ids = get_external_ids(data)
+    assert ids["twitter"] == "egonwillighagen"
+
+
+def test_get_scopus(orcid_w_external_links):
+    """Test getting a scopus ID."""
+    assert orcid_w_external_links["Scopus Author ID"] == "56352777000"