Skip to content

Commit 6dbe4aa

Browse files
committed
Authors add files script
1 parent 49aa0b6 commit 6dbe4aa

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

add_files_authors.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import requests, os
2+
from caltechdata_api import write_files_rdm
3+
4+
idv = "tv53y-rqh37"
5+
files = ["1-s2.0-S2590162125000620-main.pdf"]
6+
token = os.environ["RDMTOK"]
7+
url = "https://authors.library.caltech.edu"
8+
9+
headers = {
10+
"Authorization": "Bearer %s" % token,
11+
"Content-type": "application/json",
12+
}
13+
f_headers = {
14+
"Authorization": "Bearer %s" % token,
15+
"Content-type": "application/octet-stream",
16+
}
17+
18+
existing = requests.get(
19+
url + "/api/records/" + idv + "/draft",
20+
headers=headers,
21+
)
22+
if existing.status_code != 200:
23+
raise Exception(f"Record {idv} does not exist, cannot edit")
24+
data = existing.json()
25+
data["files"] = {"enabled": True}
26+
# Update metadata
27+
result = requests.put(
28+
url + "/api/records/" + idv + "/draft",
29+
headers=headers,
30+
json=data,
31+
)
32+
if result.status_code != 200:
33+
raise Exception(result.text)
34+
file_link = result.json()["links"]["files"]
35+
write_files_rdm(files, file_link, headers, f_headers)

0 commit comments

Comments
 (0)