|
| 1 | +import requests |
| 2 | +import os, json |
| 3 | + |
| 4 | +token = os.environ["RDMTOK"] |
| 5 | + |
| 6 | +url = "https://newdata.caltechlibrary.dev/" |
| 7 | + |
| 8 | +headers = { |
| 9 | + "Authorization": "Bearer %s" % token, |
| 10 | + "Content-type": "application/json", |
| 11 | +} |
| 12 | + |
| 13 | +response = requests.get( |
| 14 | + "https://newdata.caltechlibrary.dev/api/records/4ky4q-r3b49", headers=headers |
| 15 | +) |
| 16 | + |
| 17 | +data = response.json() |
| 18 | +data.pop("pids") |
| 19 | +data["metadata"]["rights"][0].pop("icon") |
| 20 | +data["metadata"]["rights"][0].pop("description") |
| 21 | +data["metadata"]["rights"][0].pop("title") |
| 22 | +data["metadata"]["rights"][0].pop("props") |
| 23 | + |
| 24 | +result = requests.post(url + "/api/records", headers=headers, json=data) |
| 25 | + |
| 26 | +idv = result.json()["id"] |
| 27 | +publish_link = result.json()["links"]["publish"] |
| 28 | + |
| 29 | +file_data = [ |
| 30 | + { |
| 31 | + "key": "C5710A-00001Z-01_2018_08_01_00_44_16_VNIRcalib.tar", |
| 32 | + "size": 11408920576, |
| 33 | + "checksum": "md5:076029ee247300fb94a9c8a103f71003-2177", |
| 34 | + "transfer": { |
| 35 | + "type": "R", |
| 36 | + "url": "https://caltech2.osn.mghpcc.org/10.22002/h790j-6ar55/BA4A/VNIR/C5710A-00001Z-01_2018_08_01_00_44_16_VNIRcalib.tar", |
| 37 | + }, |
| 38 | + }, |
| 39 | +] |
| 40 | + |
| 41 | +result = requests.post( |
| 42 | + url + "/api/records/%s/draft/files" % idv, headers=headers, json=file_data |
| 43 | +) |
| 44 | + |
| 45 | +print(result.text) |
| 46 | + |
| 47 | +result = requests.post(publish_link, json=data, headers=headers) |
| 48 | +if result.status_code != 202: |
| 49 | + raise Exception(result.text) |
0 commit comments