# Prerequisites:
import requests # dependency to make HTTP calls
from benedict import benedict # dependency for dealing with json
10 Query ORCID for works authored by a person
Taken from Project TAPIR’s repository of Jupyter Notebooks: https://github.com/Project-TAPIR/pidgraph-notebooks
This notebook queries the ORCID Public API to retrieve works listed in a person’s ORCID record. It takes an ORCID URL or iD as input to retrieve the ORCID record of a person and the works listed on it. From the resulting list of works we output all DOIs.
The input for this notebook is an ORCID URL or iD, e.g. ‘https://orcid.org/0000-0003-2499-7741
’ or ‘0000-0003-2499-7741
’.
# input parameter
="https://orcid.org/0000-0002-2437-589X" example_orcid
We use it to query ORCID’s Public API for the person’s metadata and all works connected to them.
# URL for ORCID API
= "https://pub.orcid.org/v3.0/"
ORCID_RECORD_API
# query ORCID for an ORCID record
def query_orcid_for_record(orcid_id):
= requests.get(url=requests.utils.requote_uri(ORCID_RECORD_API + orcid_id),
response ={'Accept': 'application/json'})
headers
response.raise_for_status()=response.json()
resultreturn result
#-- example execution
=example_orcid.replace("https://orcid.org/", "")
orcid_id=query_orcid_for_record(orcid_id)
orcid_record# uncomment next lines to see complete metadata for given ORCID
#import pprint
#pprint.pprint(orcid_record)
From the complete ORCID metadata we extract the works section and print out title and DOI of each first work-summary
(the first item in a personal information section has the highest display index).
Note: works that do not have a DOI assigned, will not be printed.
# extract works section from ORCID profile
def extract_works_section(orcid_record):
=benedict.from_json(orcid_record)
orcid_dict=orcid_dict.get('activities-summary.works.group') or []
worksreturn works
# for each work in the work section: extract title and DOI
def extract_doi(work):
=benedict.from_json(work)
work_dict=work_dict.get('work-summary[0].title.title.value')
title= [doi['external-id-value'] for doi in work_dict.get('work-summary[0].external-ids.external-id', []) if doi['external-id-type']=="doi"]
dois# if there is a DOI assigned to the work, the list of dois is not empty and we can extract the first one
=dois[0] if dois else None
doireturn doi, title
# ---- example execution
=extract_works_section(orcid_record)
worksfor work in works:
= extract_doi(work)
doi,title if doi:
print(f"{doi}, {title}")
10.21428/785a6451.af466093, What is computational publishing?
10.21428/785a6451.1792b84f, Books Contain Multitudes
10.21428/785a6451.0ed93b68, Part 1: Mapping & Situating Experimental Books
10.21428/785a6451.cd58a48e, Part 2: A Typology of Experimental Books
10.21428/785a6451.c4d3ffa1, Introducing COPIM's new website
10.17613/d4rs-rx03, Posthumanism in Outer Wilds
10.17613/5SJE-W447, New Sincerity, the Weird, and the post-ironic turn in contemporary indie video games
10.20944/preprints202001.0240.v1, Open or Ajar? Openness within the Neoliberal Academy