-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoi_function.py
executable file
·85 lines (64 loc) · 3.3 KB
/
doi_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 20 10:50:11 2020
@author: maahutch
"""
import requests
from requests.auth import HTTPBasicAuth
import json
from datetime import date
with open('pwd.json') as f:
data = json.load(f)
#Create draft DOI
def create_draft_doi(creator, title, contentUrl, cred):
headers = {'content-type': 'application/vnd.api+json'}
create_date = date.today()
metadata = {"data": {"type": "dois",
"attributes": {"prefix": "10.26313",
"publisher": "Cadre",
"publicationYear": str(create_date.year),
"contenturl": contentUrl,
"creators": [{
"name": creator
}],
"titles": [{
"title": title
}],
"created": str(create_date),
"types":{
"resourceTypeGeneral":"Software"
}
}}}
payload = json.dumps(metadata, indent = 4)
url = 'https://api.datacite.org/dois'
response = requests.request("POST", url, data = payload, headers=headers, auth = HTTPBasicAuth(cred['Username'], cred['Password']))
return(response.text)
#Call function
#create_draft_doi(creator= creator, title=title, contentUrl=contentUrl, cred=data)
#Converts draft DOI to findable DOI, requires that DOI already exists
#Not tested since I didn't want to create a permenant DOI
def create_findable_doi(doi, creator, title, contentUrl, cred):
headers = {'content-type': 'application/vnd.api+json'}
create_date = date.today()
metadata = {"data": {"type": "dois",
"attributes": {"doi": doi,
"publisher": "Cadre",
"publicationYear": str(create_date.year),
"contenturl": contentUrl,
"creators": [{
"name": creator
}],
"titles": [{
"title": title
}],
"created": str(create_date),
"types":{
"resourceTypeGeneral":"Software"
},
"event": "publish"
}}}
payload = json.dumps(metadata, indent = 4)
url = 'https://api.datacite.org/dois'
response = requests.request("POST", url, data = payload, headers=headers, auth = HTTPBasicAuth(cred['Username'], cred['Password']))
return(response.text)