Skip to content

Commit 31a8ce7

Browse files
committed
Add notebook to fetch publication information from orcid
1 parent d8c7955 commit 31a8ce7

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

Diff for: scripts/OrcidToBib.ipynb

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "01f0c5c2-619a-48e0-bb7c-e5e0be009f0e",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"orcid = '0000-0000-0000-0000' # Fill your orcid here"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "2fe4bc4e-4574-4322-8b18-0c4d33a749fa",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"import requests"
21+
]
22+
},
23+
{
24+
"cell_type": "markdown",
25+
"id": "44a8b6cd-4034-4fc4-85a8-e3431dc564f1",
26+
"metadata": {},
27+
"source": [
28+
"We use the `/works` api to list all works related to the orcid. This gives a summary of all works, so citation information is not included. We collect the `put-code` of all works to retrieve the citation information later."
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"id": "3b04331e-4149-4ca3-a0aa-89e3ba892723",
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"response = requests.get('https://pub.orcid.org/v3.0/{}/works'.format(orcid),\n",
39+
" headers={\"Accept\": \"application/orcid+json\" })\n",
40+
"record = response.json()"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"id": "16f7c42d-623b-421a-8d87-bbb389313e3b",
47+
"metadata": {
48+
"scrolled": true
49+
},
50+
"outputs": [],
51+
"source": [
52+
"put_codes = []\n",
53+
"for work in record['group']:\n",
54+
" put_code = work['work-summary'][0]['put-code']\n",
55+
" put_codes.append(put_code)\n",
56+
"put_code = put_codes[0]"
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"id": "25e5d2aa-5233-486e-abce-a0d07a36c5ce",
62+
"metadata": {},
63+
"source": [
64+
"We use the `/<orcid>/work/<put-code>` endpoint to retrieve the citation information for each record."
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"id": "dd797a16-0d91-4271-8e1e-b82579a07e45",
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"citations = []\n",
75+
"for put_code in put_codes:\n",
76+
" response = requests.get('https://pub.orcid.org/v3.0/{}/work/{}'.format(orcid, put_code),\n",
77+
" headers={\"Accept\": \"application/orcid+json\" })\n",
78+
" work = response.json()\n",
79+
" if work['citation'] is not None:\n",
80+
" citations.append(work['citation']['citation-value'])"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "ad763df9-261f-41f3-bc32-00921d0a4e11",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"with open('output.bib', 'w') as bibfile:\n",
91+
" for citation in citations:\n",
92+
" bibfile.write(citation)\n",
93+
" bibfile.write('\\n')"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "Python 3 (ipykernel)",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.12.6"
114+
}
115+
},
116+
"nbformat": 4,
117+
"nbformat_minor": 5
118+
}

0 commit comments

Comments
 (0)