caltechdata-api 1.10.2__tar.gz → 1.10.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/PKG-INFO +1 -1
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/caltechdata_edit.py +9 -1
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/caltechdata_write.py +38 -17
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/cli.py +7 -3
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/customize_schema.py +3 -1
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/get_metadata.py +34 -4
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/PKG-INFO +1 -1
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/setup.cfg +1 -1
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/LICENSE +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/README.md +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/__init__.py +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/download_file.py +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/get_files.py +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/md_to_json.py +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api/utils.py +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/SOURCES.txt +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/dependency_links.txt +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/entry_points.txt +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/requires.txt +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/top_level.txt +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/pyproject.toml +0 -0
- {caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: caltechdata_api
|
|
3
|
-
Version: 1.10.
|
|
3
|
+
Version: 1.10.4
|
|
4
4
|
Summary: Python wrapper for CaltechDATA API.
|
|
5
5
|
Home-page: https://github.com/caltechlibrary/caltechdata_api
|
|
6
6
|
Author: Thomas E Morrell, Rohan Bhattarai, Elizabeth Won, Alexander A Abakah, Kshemaahna Nagi
|
|
@@ -124,14 +124,22 @@ def caltechdata_edit(
|
|
|
124
124
|
# Check if file links were provided in the metadata
|
|
125
125
|
descriptions = []
|
|
126
126
|
ex_file_links = []
|
|
127
|
+
ex_file_descriptions = []
|
|
127
128
|
if "descriptions" in metadata:
|
|
128
129
|
for d in metadata["descriptions"]:
|
|
129
130
|
if d["description"].startswith("Files available via S3"):
|
|
130
131
|
file_text = d["description"]
|
|
131
132
|
file_list = file_text.split('href="')
|
|
133
|
+
# Check if we have file_descriptions
|
|
134
|
+
split_comma = file_list[0].split(", ")
|
|
135
|
+
if len(split_comma) == 3:
|
|
136
|
+
ex_file_descriptions.append(split_comma[1])
|
|
132
137
|
# Loop over links in description, skip header text
|
|
133
138
|
for file in file_list[1:]:
|
|
134
139
|
ex_file_links.append(file.split('"\n')[0])
|
|
140
|
+
split_comma = file.split(", ")
|
|
141
|
+
if len(split_comma) == 3:
|
|
142
|
+
ex_file_descriptions.append(split_comma[1])
|
|
135
143
|
else:
|
|
136
144
|
descriptions.append(d)
|
|
137
145
|
# We remove file link descriptions, and re-add below
|
|
@@ -145,7 +153,7 @@ def caltechdata_edit(
|
|
|
145
153
|
# Otherwise we add file links found in the mtadata file
|
|
146
154
|
elif ex_file_links:
|
|
147
155
|
metadata = add_file_links(
|
|
148
|
-
metadata, ex_file_links,
|
|
156
|
+
metadata, ex_file_links, ex_file_descriptions, s3_link=s3_link
|
|
149
157
|
)
|
|
150
158
|
|
|
151
159
|
if authors == False:
|
|
@@ -9,7 +9,9 @@ from caltechdata_api import customize_schema
|
|
|
9
9
|
from caltechdata_api.utils import humanbytes
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def write_files_rdm(
|
|
12
|
+
def write_files_rdm(
|
|
13
|
+
files, file_link, headers, f_headers, s3=None, keepfiles=False, verify=True
|
|
14
|
+
):
|
|
13
15
|
f_json = []
|
|
14
16
|
f_list = {}
|
|
15
17
|
fnames = []
|
|
@@ -24,16 +26,18 @@ def write_files_rdm(files, file_link, headers, f_headers, s3=None, keepfiles=Fal
|
|
|
24
26
|
f_json.append({"key": filename})
|
|
25
27
|
f_list[filename] = f
|
|
26
28
|
# Now we see if any existing draft files need to be replaced
|
|
27
|
-
result = requests.get(file_link, headers=f_headers)
|
|
29
|
+
result = requests.get(file_link, headers=f_headers, verify=verify)
|
|
28
30
|
if result.status_code == 200:
|
|
29
31
|
ex_files = result.json()["entries"]
|
|
30
32
|
for ex in ex_files:
|
|
31
33
|
if ex["key"] in f_list:
|
|
32
|
-
result = requests.delete(
|
|
34
|
+
result = requests.delete(
|
|
35
|
+
ex["links"]["self"], headers=f_headers, verify=verify
|
|
36
|
+
)
|
|
33
37
|
if result.status_code != 204:
|
|
34
38
|
raise Exception(result.text)
|
|
35
39
|
# Create new file upload links
|
|
36
|
-
result = requests.post(file_link, headers=headers, json=f_json)
|
|
40
|
+
result = requests.post(file_link, headers=headers, json=f_json, verify=verify)
|
|
37
41
|
if result.status_code != 201:
|
|
38
42
|
raise Exception(result.text)
|
|
39
43
|
# Now we have the upload links
|
|
@@ -49,16 +53,16 @@ def write_files_rdm(files, file_link, headers, f_headers, s3=None, keepfiles=Fal
|
|
|
49
53
|
infile = open(name, "rb")
|
|
50
54
|
else:
|
|
51
55
|
infile = open(f_list[name], "rb")
|
|
52
|
-
result = requests.put(link, headers=f_headers, data=infile)
|
|
56
|
+
result = requests.put(link, headers=f_headers, data=infile, verify=verify)
|
|
53
57
|
if result.status_code != 200:
|
|
54
58
|
raise Exception(result.text)
|
|
55
|
-
result = requests.post(commit, headers=headers)
|
|
59
|
+
result = requests.post(commit, headers=headers, verify=verify)
|
|
56
60
|
if result.status_code != 200:
|
|
57
61
|
raise Exception(result.text)
|
|
58
62
|
else:
|
|
59
63
|
# Delete any files not included in this write command
|
|
60
64
|
if keepfiles == False:
|
|
61
|
-
result = requests.delete(self, headers=f_headers)
|
|
65
|
+
result = requests.delete(self, headers=f_headers, verify=verify)
|
|
62
66
|
if result.status_code != 204:
|
|
63
67
|
raise Exception(result.text)
|
|
64
68
|
|
|
@@ -77,7 +81,11 @@ def add_file_links(
|
|
|
77
81
|
size = s3.info(path)["size"]
|
|
78
82
|
size = humanbytes(size)
|
|
79
83
|
try:
|
|
80
|
-
|
|
84
|
+
description = file_descriptions[index]
|
|
85
|
+
if description != " ":
|
|
86
|
+
desc = description + ","
|
|
87
|
+
else:
|
|
88
|
+
desc = ""
|
|
81
89
|
except IndexError:
|
|
82
90
|
desc = ""
|
|
83
91
|
if link_string == "":
|
|
@@ -100,7 +108,9 @@ def add_file_links(
|
|
|
100
108
|
return metadata
|
|
101
109
|
|
|
102
110
|
|
|
103
|
-
def send_to_community(
|
|
111
|
+
def send_to_community(
|
|
112
|
+
review_link, data, headers, publish, community, message=None, verify=True
|
|
113
|
+
):
|
|
104
114
|
if not message:
|
|
105
115
|
message = "This record is submitted automatically with the CaltechDATA API"
|
|
106
116
|
|
|
@@ -108,7 +118,7 @@ def send_to_community(review_link, data, headers, publish, community, message=No
|
|
|
108
118
|
"receiver": {"community": community},
|
|
109
119
|
"type": "community-submission",
|
|
110
120
|
}
|
|
111
|
-
result = requests.put(review_link, json=data, headers=headers)
|
|
121
|
+
result = requests.put(review_link, json=data, headers=headers, verify=verify)
|
|
112
122
|
if result.status_code != 200:
|
|
113
123
|
raise Exception(result.text)
|
|
114
124
|
submit_link = review_link.replace("/review", "/actions/submit-review")
|
|
@@ -118,7 +128,7 @@ def send_to_community(review_link, data, headers, publish, community, message=No
|
|
|
118
128
|
"format": "html",
|
|
119
129
|
}
|
|
120
130
|
}
|
|
121
|
-
result = requests.post(submit_link, json=data, headers=headers)
|
|
131
|
+
result = requests.post(submit_link, json=data, headers=headers, verify=verify)
|
|
122
132
|
if result.status_code != 202:
|
|
123
133
|
raise Exception(result.text)
|
|
124
134
|
if publish:
|
|
@@ -129,7 +139,7 @@ def send_to_community(review_link, data, headers, publish, community, message=No
|
|
|
129
139
|
"format": "html",
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
|
-
result = requests.post(accept_link, json=data, headers=headers)
|
|
142
|
+
result = requests.post(accept_link, json=data, headers=headers, verify=verify)
|
|
133
143
|
if result.status_code != 200:
|
|
134
144
|
raise Exception(result.text)
|
|
135
145
|
return result
|
|
@@ -150,6 +160,7 @@ def caltechdata_write(
|
|
|
150
160
|
s3_link=None,
|
|
151
161
|
default_preview=None,
|
|
152
162
|
review_message=None,
|
|
163
|
+
verify=True,
|
|
153
164
|
):
|
|
154
165
|
"""
|
|
155
166
|
File links are links to files existing in external systems that will
|
|
@@ -229,7 +240,7 @@ def caltechdata_write(
|
|
|
229
240
|
if production == True:
|
|
230
241
|
url = "https://authors.library.caltech.edu/"
|
|
231
242
|
else:
|
|
232
|
-
url = "https://
|
|
243
|
+
url = "https://127.0.0.1:5000/"
|
|
233
244
|
|
|
234
245
|
headers = {
|
|
235
246
|
"Authorization": "Bearer %s" % token,
|
|
@@ -246,7 +257,9 @@ def caltechdata_write(
|
|
|
246
257
|
data["files"] = {"enabled": True, "default_preview": default_preview}
|
|
247
258
|
|
|
248
259
|
# Make draft and publish
|
|
249
|
-
result = requests.post(
|
|
260
|
+
result = requests.post(
|
|
261
|
+
url + "/api/records", headers=headers, json=data, verify=verify
|
|
262
|
+
)
|
|
250
263
|
if result.status_code != 201:
|
|
251
264
|
if result.status_code == 400 and "Referer checking failed" in result.text:
|
|
252
265
|
raise Exception("Token is incorrect or missing referer.")
|
|
@@ -257,17 +270,25 @@ def caltechdata_write(
|
|
|
257
270
|
|
|
258
271
|
if files:
|
|
259
272
|
file_link = result.json()["links"]["files"]
|
|
260
|
-
write_files_rdm(files, file_link, headers, f_headers, s3)
|
|
273
|
+
write_files_rdm(files, file_link, headers, f_headers, s3, verify=verify)
|
|
261
274
|
|
|
262
275
|
if community:
|
|
263
276
|
review_link = result.json()["links"]["review"]
|
|
264
277
|
send_to_community(
|
|
265
|
-
review_link,
|
|
278
|
+
review_link,
|
|
279
|
+
data,
|
|
280
|
+
headers,
|
|
281
|
+
publish,
|
|
282
|
+
community,
|
|
283
|
+
review_message,
|
|
284
|
+
verify=verify,
|
|
266
285
|
)
|
|
267
286
|
|
|
268
287
|
else:
|
|
269
288
|
if publish:
|
|
270
|
-
result = requests.post(
|
|
289
|
+
result = requests.post(
|
|
290
|
+
publish_link, json=data, headers=headers, verify=verify
|
|
291
|
+
)
|
|
271
292
|
if result.status_code != 202:
|
|
272
293
|
raise Exception(result.text)
|
|
273
294
|
return idv
|
|
@@ -159,10 +159,14 @@ def get_funding_entries():
|
|
|
159
159
|
|
|
160
160
|
def validate_funder_identifier(funder_identifier):
|
|
161
161
|
response = requests.get(f"https://api.ror.org/organizations/{funder_identifier}")
|
|
162
|
+
returnv = False
|
|
162
163
|
if response.status_code == 200:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
names = response.json().get("names", [])
|
|
165
|
+
for name in names:
|
|
166
|
+
types = name.get("types", [])
|
|
167
|
+
if "ror_display" in types:
|
|
168
|
+
returnv = name.get("value")
|
|
169
|
+
return returnv
|
|
166
170
|
|
|
167
171
|
|
|
168
172
|
def get_funding_details():
|
|
@@ -17,7 +17,9 @@ def grid_to_ror(grid):
|
|
|
17
17
|
elif grid == "grid.465477.3":
|
|
18
18
|
ror = "00em52312"
|
|
19
19
|
else:
|
|
20
|
-
url =
|
|
20
|
+
url = (
|
|
21
|
+
f"https://api.ror.org/organizations?query.advanced=external_ids.all:{grid}"
|
|
22
|
+
)
|
|
21
23
|
results = requests.get(url).json()
|
|
22
24
|
if len(results["items"]) == 0:
|
|
23
25
|
print(url + "doesn't have a valid ROR")
|
|
@@ -31,10 +31,12 @@ def get_metadata(
|
|
|
31
31
|
url = "https://data.caltechlibrary.dev/api/records/"
|
|
32
32
|
verify = True
|
|
33
33
|
|
|
34
|
+
base_headers = {
|
|
35
|
+
"accept": "application/json",
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
if authors:
|
|
35
|
-
headers =
|
|
36
|
-
"accept": "application/json",
|
|
37
|
-
}
|
|
39
|
+
headers = base_headers
|
|
38
40
|
validate = False
|
|
39
41
|
else:
|
|
40
42
|
headers = {
|
|
@@ -42,6 +44,7 @@ def get_metadata(
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
if token:
|
|
47
|
+
base_headers["Authorization"] = "Bearer %s" % token
|
|
45
48
|
headers["Authorization"] = "Bearer %s" % token
|
|
46
49
|
|
|
47
50
|
response = requests.get(url + idv, headers=headers, verify=verify)
|
|
@@ -49,7 +52,34 @@ def get_metadata(
|
|
|
49
52
|
raise Exception(response.text)
|
|
50
53
|
else:
|
|
51
54
|
metadata = response.json()
|
|
52
|
-
|
|
55
|
+
if not authors:
|
|
56
|
+
response = requests.get(url + idv, headers=base_headers, verify=verify)
|
|
57
|
+
if response.status_code != 200:
|
|
58
|
+
raise Exception(response.text)
|
|
59
|
+
else:
|
|
60
|
+
instance = response.json()
|
|
61
|
+
base_metadata = instance["metadata"]
|
|
62
|
+
if "descriptions" in metadata:
|
|
63
|
+
metadata["descriptions"][0]["description"] = base_metadata.get(
|
|
64
|
+
"description"
|
|
65
|
+
)
|
|
66
|
+
additional_descriptions = base_metadata.get(
|
|
67
|
+
"additional_descriptions", []
|
|
68
|
+
)
|
|
69
|
+
count = 1
|
|
70
|
+
if (
|
|
71
|
+
len(metadata["descriptions"])
|
|
72
|
+
== len(additional_descriptions) + 1
|
|
73
|
+
):
|
|
74
|
+
for desc in additional_descriptions:
|
|
75
|
+
metadata["descriptions"][count]["description"] = desc[
|
|
76
|
+
"description"
|
|
77
|
+
]
|
|
78
|
+
count += 1
|
|
79
|
+
else:
|
|
80
|
+
print(f"Record {idv} does not have a description.")
|
|
81
|
+
if "formats" in metadata:
|
|
82
|
+
metadata["formats"] = list(set(metadata["formats"]))
|
|
53
83
|
if validate:
|
|
54
84
|
if schema == "43":
|
|
55
85
|
try:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: caltechdata-api
|
|
3
|
-
Version: 1.10.
|
|
3
|
+
Version: 1.10.4
|
|
4
4
|
Summary: Python wrapper for CaltechDATA API.
|
|
5
5
|
Home-page: https://github.com/caltechlibrary/caltechdata_api
|
|
6
6
|
Author: Thomas E Morrell, Rohan Bhattarai, Elizabeth Won, Alexander A Abakah, Kshemaahna Nagi
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[metadata]
|
|
6
6
|
name = caltechdata_api
|
|
7
|
-
version = 1.10.
|
|
7
|
+
version = 1.10.4
|
|
8
8
|
author = Thomas E Morrell, Rohan Bhattarai, Elizabeth Won, Alexander A Abakah, Kshemaahna Nagi
|
|
9
9
|
author_email = tmorrell@caltech.edu, aabakah@caltech.edu, knagi@caltech.edu
|
|
10
10
|
description = Python wrapper for CaltechDATA API.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{caltechdata_api-1.10.2 → caltechdata_api-1.10.4}/caltechdata_api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|