Last active
October 5, 2017 12:56
-
-
Save blokhin/23f6a6c856d76bb656f2 to your computer and use it in GitHub Desktop.
Datacite API test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
import httplib2 | |
import base64 | |
endpoint_meta = 'https://test.datacite.org/mds/metadata?testMode=0' | |
endpoint_mint = 'https://test.datacite.org/mds/doi?testMode=0' | |
login = '<login here>' | |
password = '<pass here>' | |
doi = '10.5072/NOMAD/W4UV5CN78NC347934J9483CD3453' | |
meta_req = '''<?xml version="1.0" encoding="UTF-8"?> | |
<resource xsi:schemaLocation="http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3.1/metadata.xsd" xmlns="http://datacite.org/schema/kernel-3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<identifier identifierType="DOI">''' + doi + '''</identifier> | |
<creators> | |
<creator> | |
<creatorName>Lastname, Name</creatorName> | |
</creator> | |
</creators> | |
<titles> | |
<title>DOI Simple Test</title> | |
</titles> | |
<publisher>Yet Another Repository</publisher> | |
<publicationYear>2015</publicationYear> | |
</resource> | |
''' | |
url = 'http://nomad.physik.hu-berlin.de/gui#W4UV5CN78NC347934J9483CD3453' # NOT EXISTS, ONLY FOR TEST | |
doi_req = "doi="+doi+"\nurl="+url | |
h = httplib2.Http() | |
auth_string = base64.encodestring(login + ':' + password) | |
# First, save meta | |
response, content = h.request(endpoint_meta, | |
'POST', | |
body = meta_req.encode('utf-8'), | |
headers={'Content-Type':'application/xml;charset=UTF-8', | |
'Authorization':'Basic ' + auth_string}) | |
if response.status != 201: print str(response.status) | |
print content.decode('utf-8') | |
# Then, save its new ID | |
response, content = h.request(endpoint_mint, | |
'POST', | |
body = doi_req.encode('utf-8'), | |
headers={'Content-Type':'text/plain;charset=UTF-8', | |
'Authorization':'Basic ' + auth_string}) | |
if response.status != 201: print str(response.status) | |
print content.decode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment