-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: add script to clear pending files
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |