-
-
Save rdhyee/f6339bead9112619a20c to your computer and use it in GitHub Desktop.
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Goal\n", | |
"\n", | |
"Try out the capabilities of the [DMPTool API](https://github.com/CDLUC3/dmptool/wiki/API).\n", | |
"\n", | |
"I created a private DMP with id " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import requests\n", | |
"\n", | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"from pandas import (DataFrame, Series)\n", | |
"\n", | |
"from settings import DMPTOOL_TOKEN\n", | |
"\n", | |
"# https://dmptool.org/plans/16453.pdf\n", | |
"# private\n", | |
"\n", | |
"MY_TEST_DMP_ID = 16453\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>full_name</th>\n", | |
" <th>id</th>\n", | |
" <th>plans_count</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>Non partner institution</td>\n", | |
" <td>0</td>\n", | |
" <td>3706</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>University of Virginia</td>\n", | |
" <td>2</td>\n", | |
" <td>363</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>University of California, San Diego</td>\n", | |
" <td>3</td>\n", | |
" <td>183</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>Smithsonian Institution</td>\n", | |
" <td>4</td>\n", | |
" <td>56</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>University of Illinois at Urbana-Champaign</td>\n", | |
" <td>5</td>\n", | |
" <td>295</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" full_name id plans_count\n", | |
"0 Non partner institution 0 3706\n", | |
"1 University of Virginia 2 363\n", | |
"2 University of California, San Diego 3 183\n", | |
"3 Smithsonian Institution 4 56\n", | |
"4 University of Illinois at Urbana-Champaign 5 295" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# get counts for various institutions \n", | |
"# https://via.hypothes.is/https://github.com/CDLUC3/dmptool/wiki/API#for-a-list-of-institutions-and-plans-count\n", | |
"# curl -v -X GET \"https://dmptool.org/api/v1/institutions_plans_count\"\n", | |
"\n", | |
"plans_counts = requests.get(\"https://dmptool.org/api/v1/institutions_plans_count\").json()\n", | |
"\n", | |
"df = DataFrame([r.get('institution') for r in plans_counts])\n", | |
"df.head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>full_name</th>\n", | |
" <th>id</th>\n", | |
" <th>plans_count</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>Non partner institution</td>\n", | |
" <td>0</td>\n", | |
" <td>3706</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>University of Virginia</td>\n", | |
" <td>2</td>\n", | |
" <td>363</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>University of Illinois at Urbana-Champaign</td>\n", | |
" <td>5</td>\n", | |
" <td>295</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>UCLA</td>\n", | |
" <td>9</td>\n", | |
" <td>211</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>64</th>\n", | |
" <td>University of North Texas</td>\n", | |
" <td>65</td>\n", | |
" <td>206</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" full_name id plans_count\n", | |
"0 Non partner institution 0 3706\n", | |
"1 University of Virginia 2 363\n", | |
"4 University of Illinois at Urbana-Champaign 5 295\n", | |
"8 UCLA 9 211\n", | |
"64 University of North Texas 65 206" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df.sort('plans_count', ascending=False).head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[{u'plan': {u'coowners': [{u'coowner': {u'email': u'[email protected]',\n", | |
" u'full_name': u'Steven Foga'}}],\n", | |
" u'created': u'01/07/2013',\n", | |
" u'institution': u'Non partner institution',\n", | |
" u'modified': u'04/28/2015',\n", | |
" u'name': u'USGS CDR/ECV DMP',\n", | |
" u'owner': {u'email': u'[email protected]',\n", | |
" u'full_name': u'Calli Jenkerson'},\n", | |
" u'state': u'revised',\n", | |
" u'template': {u'active': True,\n", | |
" u'name': u'NSF-AGS: Atmospheric and Geospace Sciences',\n", | |
" u'review_type': u'no_review',\n", | |
" u'start_date': u'11/21/2011'},\n", | |
" u'visibility': u'public'}},\n", | |
" {u'plan': {u'created': u'12/04/2013',\n", | |
" u'institution': u'University of California, Office of the President',\n", | |
" u'modified': u'06/05/2014',\n", | |
" u'name': u'A unified approach to preserving cultural software objects and their development histories ',\n", | |
" u'owner': {u'email': u'[email protected]',\n", | |
" u'full_name': u'DMP dmpcurator'},\n", | |
" u'state': u'committed',\n", | |
" u'template': {u'active': True,\n", | |
" u'name': u'NEH-ODH: Office of Digital Humanities',\n", | |
" u'review_type': u'no_review',\n", | |
" u'start_date': u'10/14/2011'},\n", | |
" u'visibility': u'public'}}]" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# list of plans\n", | |
"# curl -H \"Authorization: Token token=token_number\" https://dmptool.org/api/v1/plans\n", | |
"\n", | |
"headers = {'Authorization': DMPTOOL_TOKEN}\n", | |
"r = requests.get(\"https://dmptool.org/api/v1/plans\", headers=headers)\n", | |
"r.json()[:2]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>coowners</th>\n", | |
" <th>created</th>\n", | |
" <th>institution</th>\n", | |
" <th>modified</th>\n", | |
" <th>name</th>\n", | |
" <th>owner</th>\n", | |
" <th>solicitation_identifier</th>\n", | |
" <th>state</th>\n", | |
" <th>template</th>\n", | |
" <th>visibility</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>[{u'coowner': {u'email': u'[email protected]', u'...</td>\n", | |
" <td>01/07/2013</td>\n", | |
" <td>Non partner institution</td>\n", | |
" <td>04/28/2015</td>\n", | |
" <td>USGS CDR/ECV DMP</td>\n", | |
" <td>{u'email': u'[email protected]', u'full_name'...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>revised</td>\n", | |
" <td>{u'active': True, u'review_type': u'no_review'...</td>\n", | |
" <td>public</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>NaN</td>\n", | |
" <td>12/04/2013</td>\n", | |
" <td>University of California, Office of the President</td>\n", | |
" <td>06/05/2014</td>\n", | |
" <td>A unified approach to preserving cultural soft...</td>\n", | |
" <td>{u'email': u'[email protected]', u'full_nam...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>committed</td>\n", | |
" <td>{u'active': True, u'review_type': u'no_review'...</td>\n", | |
" <td>public</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>NaN</td>\n", | |
" <td>12/04/2013</td>\n", | |
" <td>University of California, Office of the President</td>\n", | |
" <td>05/30/2014</td>\n", | |
" <td>Atmospheric CO2 Concentrations, Mauna Loa Obse...</td>\n", | |
" <td>{u'email': u'[email protected]', u'full_nam...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>new</td>\n", | |
" <td>{u'active': True, u'review_type': u'no_review'...</td>\n", | |
" <td>public</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>NaN</td>\n", | |
" <td>12/04/2013</td>\n", | |
" <td>University of California, Office of the President</td>\n", | |
" <td>05/30/2014</td>\n", | |
" <td>Daymet Follow-On: Surface Weather Data with Un...</td>\n", | |
" <td>{u'email': u'[email protected]', u'full_nam...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>new</td>\n", | |
" <td>{u'active': True, u'review_type': u'no_review'...</td>\n", | |
" <td>public</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>NaN</td>\n", | |
" <td>12/11/2013</td>\n", | |
" <td>University of California, Office of the President</td>\n", | |
" <td>05/28/2014</td>\n", | |
" <td>Multimedia Text Annotation for Students</td>\n", | |
" <td>{u'email': u'[email protected]', u'full_nam...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>new</td>\n", | |
" <td>{u'active': True, u'review_type': u'no_review'...</td>\n", | |
" <td>public</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" coowners created \\\n", | |
"0 [{u'coowner': {u'email': u'[email protected]', u'... 01/07/2013 \n", | |
"1 NaN 12/04/2013 \n", | |
"2 NaN 12/04/2013 \n", | |
"3 NaN 12/04/2013 \n", | |
"4 NaN 12/11/2013 \n", | |
"\n", | |
" institution modified \\\n", | |
"0 Non partner institution 04/28/2015 \n", | |
"1 University of California, Office of the President 06/05/2014 \n", | |
"2 University of California, Office of the President 05/30/2014 \n", | |
"3 University of California, Office of the President 05/30/2014 \n", | |
"4 University of California, Office of the President 05/28/2014 \n", | |
"\n", | |
" name \\\n", | |
"0 USGS CDR/ECV DMP \n", | |
"1 A unified approach to preserving cultural soft... \n", | |
"2 Atmospheric CO2 Concentrations, Mauna Loa Obse... \n", | |
"3 Daymet Follow-On: Surface Weather Data with Un... \n", | |
"4 Multimedia Text Annotation for Students \n", | |
"\n", | |
" owner solicitation_identifier \\\n", | |
"0 {u'email': u'[email protected]', u'full_name'... NaN \n", | |
"1 {u'email': u'[email protected]', u'full_nam... NaN \n", | |
"2 {u'email': u'[email protected]', u'full_nam... NaN \n", | |
"3 {u'email': u'[email protected]', u'full_nam... NaN \n", | |
"4 {u'email': u'[email protected]', u'full_nam... NaN \n", | |
"\n", | |
" state template visibility \n", | |
"0 revised {u'active': True, u'review_type': u'no_review'... public \n", | |
"1 committed {u'active': True, u'review_type': u'no_review'... public \n", | |
"2 new {u'active': True, u'review_type': u'no_review'... public \n", | |
"3 new {u'active': True, u'review_type': u'no_review'... public \n", | |
"4 new {u'active': True, u'review_type': u'no_review'... public " | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"plans_df = DataFrame([r.get('plan') for r in r.json()])\n", | |
"plans_df.head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# thought I'd be able to get a list of my own DMPs -- but no\n", | |
"# only public dmps? https://dmptool.org/public_dmps?public%3Aall_scope=all&public%3Apage=6\n", | |
"\n", | |
"np.any(plans_df.owner.apply(lambda o: o.get('email')) == '[email protected]')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'You are not authorized to look at this content.'" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# let's try to get a plan\n", | |
"# curl -H \"Authorization: Token token=token_number\" https://dmptool.org/api/v1/plans/:id\n", | |
"\n", | |
"headers = {'Authorization': DMPTOOL_TOKEN}\n", | |
"r = requests.get(\"https://dmptool.org/api/v1/plans/{}\".format(MY_TEST_DMP_ID), headers=headers)\n", | |
"r.content" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Hi Raymond, I tried this again today when describing the problem to Scott Fisher our developer and I was no longer able recreate the issue. Are you still having this problem?
I'm thinking Stephanie gave you institutional admin rights, which is why it's working now.
Hi Raymond, we tried this again with another user who did not have inst admin privileges and it was working.
user (dmp2user123) who just had one plan that was private. I created an API key and was able to show the plan.
curl -H "Authorization: Token token=d93a2be06b6be6ddbb7cb432881200df" https://dmp2-dev.cdlib.org/api/v1/plans/1562
{"plan":{"id":1562,"name":"Copy of The Nine Lives of Kitty Cats","solicitation_identifier":"666","visibility":"private","created":"09/28/2015","modified":"09/28/2015","owner":{"full_name":"dmp2user123 dmp2user123","email":"[email protected]"},"template":{"name":"Cat Questions","active":true,"start_date":"03/05/2014","end_date":"03/18/2015","review_type":"no_review"},"state":"new","institution":"NonPartner Institution "}}
My mistake. The line in cell 7 above
headers = {'Authorization': DMPTOOL_TOKEN}
should be
headers = {'Authorization': 'Token token={}'.format(DMPTOOL_TOKEN)}
https://gist.github.com/rdhyee/a64c2c5380edc92efe07 shows this fix in operation.
Note: the settings module contains
DMPTOOL_TOKEN
, which is my DMPTool token.