{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "The ORCID API documentation is [here](http://support.orcid.org/knowledgebase/articles/116874-orcid-api-guide)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "import requests" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "'2.22.0'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "requests.__version__" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "ORCID = '0000-0002-9653-4458'\n", "ORCID_URL = \"http://pub.orcid.org/%s/orcid-works\"\n", "DOI_BASE_URL = 'http://dx.doi.org/'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "headers = {'accept': 'application/orcid+json'}\n", "r = requests.get(ORCID_URL % ORCID, headers=headers)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n" ] } ], "source": [ "print (r.ok)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'Server': 'nginx/1.10.0', 'Date': 'Sun, 24 Nov 2019 13:50:14 GMT', 'Content-Type': 'application/orcid+json; qs=2;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip'}\n" ] } ], "source": [ "printr.headers" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\"message-version\":\"1.0.15\",\"orcid-profile\":{\"orcid\":{\"value\":\"0000-0002-9653-4458\"},\"orcid-id\":\"http://orcid.org/0000-0002-9653-4458\",\"orcid-history\":{\"creation-method\":\"WEBSITE\",\"completion-date\":{\"value\":1350396328015},\"submission-date\":{\"value\":1350392628869},\"last-modified-date\":{\"value\":1373804852054},\"claimed\":{\"value\":true},\"source\":null,\"visibility\":null},\"orcid-activities\":{\"orcid-works\":{\"orcid-work\":[{\"put-code\":\"9381344\",\"work-title\":{\"title\":{\"value\":\"Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments\"},\"subtitle\":{\"value\":\"BMC Evolutionary Biology\"}},\"work-citation\":{\"work-citation-type\":\"BIBTEX\",\"citation\":\"@article{Gueijman_Ayali_Ram_Hadany_2013, title={Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments}, volume={13}, url={http://dx.doi.org/10.1186/1471-2148-13-125}, DOI={10.1186/1471-2148-13-125}, number={1}, journal={BMC Evolutionary Biology}, publisher={Springer (Biomed Central Ltd.)}, author={Gueijman, Ariel and Ayali, Amir and Ram, Yoav and Hadany, Lilach}, year={2013}, pages={125}}\"},\"work-type\":\"JOURNAL_ARTICLE\",\"publication-date\":{\"year\":{\"value\":\"2013\"},\"month\":null,\"day\":null,\"media-type\":null},\"work-external-identifiers\":{\"work-external-identifier\":[{\"work-external-identifier-type\":\"DOI\",\"work-external-identifier-id\":{\"value\":\"10.1186/1471-2148-13-125\"}},{\"work-external-identifier-type\":\"ISSN\",\"work-external-identifier-id\":{\"value\":\"1471-2148\"}}],\"scope\":null},\"url\":null,\"work-source\":{\"value\":\"0000-0002-3054-1567\"},\"visibility\":null},{\"put-code\":\"9381343\",\"work-title\":{\"title\":{\"value\":\"EVOLUTION OF STRESS-INDUCED HYPERMUTATION\"},\"subtitle\":{\"value\":\"Evolution\"}},\"work-citation\":{\"work-citation-type\":\"BIBTEX\",\"citation\":\"@article{Ram_Hadany_2012, title={THE EVOLUTION OF STRESS-INDUCED HYPERMUTATION IN ASEXUAL POPULATIONS}, volume={66}, url={http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x}, DOI={10.1111/j.1558-5646.2012.01576.x}, number={7}, journal={Evolution}, publisher={Wiley Blackwell (Blackwell Publishing)}, author={Ram, Yoav and Hadany, Lilach}, year={2012}, month={Jul}, pages={2315-2328}}\"},\"work-type\":\"JOURNAL_ARTICLE\",\"publication-date\":{\"year\":{\"value\":\"2012\"},\"month\":null,\"day\":null,\"media-type\":null},\"work-external-identifiers\":{\"work-external-identifier\":[{\"work-external-identifier-type\":\"DOI\",\"work-external-identifier-id\":{\"value\":\"10.1111/j.1558-5646.2012.01576.x\"}},{\"work-external-identifier-type\":\"ISSN\",\"work-external-identifier-id\":{\"value\":\"0014-3820\"}}],\"scope\":null},\"url\":null,\"work-source\":{\"value\":\"0000-0002-3054-1567\"},\"visibility\":null}],\"scope\":null}},\"type\":\"USER\"}}\n" ] } ], "source": [ "print r.content" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{u'message-version': u'1.0.15', u'orcid-profile': {u'orcid': {u'value': u'0000-0002-9653-4458'}, u'orcid-id': u'http://orcid.org/0000-0002-9653-4458', u'type': u'USER', u'orcid-activities': {u'orcid-works': {u'scope': None, u'orcid-work': [{u'put-code': u'9381344', u'work-title': {u'subtitle': {u'value': u'BMC Evolutionary Biology'}, u'title': {u'value': u'Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments'}}, u'work-citation': {u'citation': u'@article{Gueijman_Ayali_Ram_Hadany_2013, title={Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments}, volume={13}, url={http://dx.doi.org/10.1186/1471-2148-13-125}, DOI={10.1186/1471-2148-13-125}, number={1}, journal={BMC Evolutionary Biology}, publisher={Springer (Biomed Central Ltd.)}, author={Gueijman, Ariel and Ayali, Amir and Ram, Yoav and Hadany, Lilach}, year={2013}, pages={125}}', u'work-citation-type': u'BIBTEX'}, u'work-type': u'JOURNAL_ARTICLE', u'publication-date': {u'month': None, u'day': None, u'media-type': None, u'year': {u'value': u'2013'}}, u'visibility': None, u'url': None, u'work-external-identifiers': {u'scope': None, u'work-external-identifier': [{u'work-external-identifier-id': {u'value': u'10.1186/1471-2148-13-125'}, u'work-external-identifier-type': u'DOI'}, {u'work-external-identifier-id': {u'value': u'1471-2148'}, u'work-external-identifier-type': u'ISSN'}]}, u'work-source': {u'value': u'0000-0002-3054-1567'}}, {u'put-code': u'9381343', u'work-title': {u'subtitle': {u'value': u'Evolution'}, u'title': {u'value': u'EVOLUTION OF STRESS-INDUCED HYPERMUTATION'}}, u'work-citation': {u'citation': u'@article{Ram_Hadany_2012, title={THE EVOLUTION OF STRESS-INDUCED HYPERMUTATION IN ASEXUAL POPULATIONS}, volume={66}, url={http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x}, DOI={10.1111/j.1558-5646.2012.01576.x}, number={7}, journal={Evolution}, publisher={Wiley Blackwell (Blackwell Publishing)}, author={Ram, Yoav and Hadany, Lilach}, year={2012}, month={Jul}, pages={2315-2328}}', u'work-citation-type': u'BIBTEX'}, u'work-type': u'JOURNAL_ARTICLE', u'publication-date': {u'month': None, u'day': None, u'media-type': None, u'year': {u'value': u'2012'}}, u'visibility': None, u'url': None, u'work-external-identifiers': {u'scope': None, u'work-external-identifier': [{u'work-external-identifier-id': {u'value': u'10.1111/j.1558-5646.2012.01576.x'}, u'work-external-identifier-type': u'DOI'}, {u'work-external-identifier-id': {u'value': u'0014-3820'}, u'work-external-identifier-type': u'ISSN'}]}, u'work-source': {u'value': u'0000-0002-3054-1567'}}]}}, u'orcid-history': {u'source': None, u'creation-method': u'WEBSITE', u'submission-date': {u'value': 1350392628869L}, u'last-modified-date': {u'value': 1373804852054L}, u'visibility': None, u'completion-date': {u'value': 1350396328015L}, u'claimed': {u'value': True}}}}\n" ] } ], "source": [ "data = r.json()\n", "print data" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "(dict, 2)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(data),len(data)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[u'message-version', u'orcid-profile']" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.keys()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "u'1.0.15'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data['message-version']" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "data = data['orcid-profile']" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[u'orcid', u'orcid-id', u'type', u'orcid-activities', u'orcid-history']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.keys()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "data = data['orcid-activities']" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[u'orcid-works']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.keys()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[u'scope', u'orcid-work']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data['orcid-works'].keys()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "data = data['orcid-works']['orcid-work']" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "(list, 2)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(data),len(data)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[u'put-code',\n", " u'work-title',\n", " u'work-citation',\n", " u'work-type',\n", " u'publication-date',\n", " u'visibility',\n", " u'url',\n", " u'work-external-identifiers',\n", " u'work-source']" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[0].keys()" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments\n" ] } ], "source": [ "title = data[0]['work-title']['title']['value']\n", "print title" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "@article{Gueijman_Ayali_Ram_Hadany_2013, title={Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments}, volume={13}, url={http://dx.doi.org/10.1186/1471-2148-13-125}, DOI={10.1186/1471-2148-13-125}, number={1}, journal={BMC Evolutionary Biology}, publisher={Springer (Biomed Central Ltd.)}, author={Gueijman, Ariel and Ayali, Amir and Ram, Yoav and Hadany, Lilach}, year={2013}, pages={125}}\n" ] } ], "source": [ "bibtex = data[0]['work-citation']['citation']\n", "print bibtex" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "u'2013'" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[0]['publication-date']['year']['value']" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "u'BMC Evolutionary Biology'" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "journal = data[0]['work-title']['subtitle']['value']\n", "print journal" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "url = ''\n", "if data[0]['url']:\n", " url = data[0]['url']['value']\n", "print url" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10.1186/1471-2148-13-125\n", "http://dx.doi.org/10.1186/1471-2148-13-125\n" ] } ], "source": [ "doi = ''\n", "for v in data[0]['work-external-identifiers']['work-external-identifier']:\n", " if v['work-external-identifier-type'] == 'DOI':\n", " doi = v['work-external-identifier-id']['value']\n", " url = DOI_BASE_URL + doi\n", "print doi\n", "print url" ] }, { "cell_type": "code", "execution_count": 101, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "def parse_item(data):\n", " title = data['work-title']['title']['value']\n", " citation = data['work-citation']['citation']\n", " journal = data['work-title']['subtitle']['value']\n", " url = ''\n", " if data['url']:\n", " url = data[0]['url']['value']\n", " doi = ''\n", " for v in data['work-external-identifiers']['work-external-identifier']:\n", " if v['work-external-identifier-type'] == 'DOI':\n", " doi = v['work-external-identifier-id']['value']\n", " url = DOI_BASE_URL + doi\n", " return {'title':title, 'journal':journal, 'url':url, 'doi':doi, 'citation':citation}" ] }, { "cell_type": "code", "execution_count": 103, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "{'citation': u'@article{Ram_Hadany_2012, title={THE EVOLUTION OF STRESS-INDUCED HYPERMUTATION IN ASEXUAL POPULATIONS}, volume={66}, url={http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x}, DOI={10.1111/j.1558-5646.2012.01576.x}, number={7}, journal={Evolution}, publisher={Wiley Blackwell (Blackwell Publishing)}, author={Ram, Yoav and Hadany, Lilach}, year={2012}, month={Jul}, pages={2315-2328}}',\n", " 'doi': u'10.1111/j.1558-5646.2012.01576.x',\n", " 'journal': u'Evolution',\n", " 'title': u'EVOLUTION OF STRESS-INDUCED HYPERMUTATION',\n", " 'url': u'http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x'}" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "parse_item(data[1])" ] }, { "cell_type": "code", "execution_count": 105, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "def extract_items(request):\n", " data = request.json()\n", " data = data['orcid-profile']\n", " data = data['orcid-activities']\n", " data = data['orcid-works']['orcid-work']\n", " return [parse_item(item) for item in data]" ] }, { "cell_type": "code", "execution_count": 106, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[{'citation': u'@article{Gueijman_Ayali_Ram_Hadany_2013, title={Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments}, volume={13}, url={http://dx.doi.org/10.1186/1471-2148-13-125}, DOI={10.1186/1471-2148-13-125}, number={1}, journal={BMC Evolutionary Biology}, publisher={Springer (Biomed Central Ltd.)}, author={Gueijman, Ariel and Ayali, Amir and Ram, Yoav and Hadany, Lilach}, year={2013}, pages={125}}',\n", " 'doi': u'10.1186/1471-2148-13-125',\n", " 'journal': u'BMC Evolutionary Biology',\n", " 'title': u'Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments',\n", " 'url': u'http://dx.doi.org/10.1186/1471-2148-13-125'},\n", " {'citation': u'@article{Ram_Hadany_2012, title={THE EVOLUTION OF STRESS-INDUCED HYPERMUTATION IN ASEXUAL POPULATIONS}, volume={66}, url={http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x}, DOI={10.1111/j.1558-5646.2012.01576.x}, number={7}, journal={Evolution}, publisher={Wiley Blackwell (Blackwell Publishing)}, author={Ram, Yoav and Hadany, Lilach}, year={2012}, month={Jul}, pages={2315-2328}}',\n", " 'doi': u'10.1111/j.1558-5646.2012.01576.x',\n", " 'journal': u'Evolution',\n", " 'title': u'EVOLUTION OF STRESS-INDUCED HYPERMUTATION',\n", " 'url': u'http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x'}]" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "extract_items(r)" ] }, { "cell_type": "code", "execution_count": 110, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "def orcid_items(orcid):\n", " headers = {'accept': 'application/orcid+json'}\n", " r = requests.get(ORCID_URL % orcid, headers=headers)\n", " if r.ok:\n", " return extract_items(r)\n", " else:\n", " return []" ] }, { "cell_type": "code", "execution_count": 111, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "[{'citation': u'@article{Gueijman_Ayali_Ram_Hadany_2013, title={Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments}, volume={13}, url={http://dx.doi.org/10.1186/1471-2148-13-125}, DOI={10.1186/1471-2148-13-125}, number={1}, journal={BMC Evolutionary Biology}, publisher={Springer (Biomed Central Ltd.)}, author={Gueijman, Ariel and Ayali, Amir and Ram, Yoav and Hadany, Lilach}, year={2013}, pages={125}}',\n", " 'doi': u'10.1186/1471-2148-13-125',\n", " 'journal': u'BMC Evolutionary Biology',\n", " 'title': u'Dispersing away from bad genotypes: the evolution of Fitness-Associated Dispersal (FAD) in homogeneous environments',\n", " 'url': u'http://dx.doi.org/10.1186/1471-2148-13-125'},\n", " {'citation': u'@article{Ram_Hadany_2012, title={THE EVOLUTION OF STRESS-INDUCED HYPERMUTATION IN ASEXUAL POPULATIONS}, volume={66}, url={http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x}, DOI={10.1111/j.1558-5646.2012.01576.x}, number={7}, journal={Evolution}, publisher={Wiley Blackwell (Blackwell Publishing)}, author={Ram, Yoav and Hadany, Lilach}, year={2012}, month={Jul}, pages={2315-2328}}',\n", " 'doi': u'10.1111/j.1558-5646.2012.01576.x',\n", " 'journal': u'Evolution',\n", " 'title': u'EVOLUTION OF STRESS-INDUCED HYPERMUTATION',\n", " 'url': u'http://dx.doi.org/10.1111/j.1558-5646.2012.01576.x'}]" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "orcid_items(ORCID)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }