Skip to content

Commit

Permalink
scripts: add script to clear pending files
Browse files Browse the repository at this point in the history
  • Loading branch information
lnielsen committed Oct 15, 2023
1 parent b4ea829 commit b7877a3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions scripts/admin/clear_pending_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Usage:
export RDMTOK=....
python3 clear_pending_files.py <id>
"""

import requests
import os, argparse

parser = argparse.ArgumentParser(description="Clear stuck files from UI uploader")
parser.add_argument("ids", nargs="*", help="Record IDs to clear")

args = parser.parse_args()

# Get access token as environment variable
token = os.environ["RDMTOK"]

url = "https://zenodo.org/api/records"

headers = {
"Authorization": "Bearer %s" % token,
"Content-type": "application/json",
}

for idv in args.ids:
response = requests.get(f"{url}/{idv}/draft/files", headers=headers)
entries = response.json()["entries"]
for entry in entries:
if entry["status"] == "pending":
response = requests.delete(entry["links"]["self"], headers=headers)
if response.status_code != 204:
print(response.text)
exit()

0 comments on commit b7877a3

Please sign in to comment.