-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresources_wout_creators.py
43 lines (37 loc) · 1.8 KB
/
resources_wout_creators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# This script checks all resources in an ArchivesSpace instance and makes an excel spreadsheet with those without
# creators
import re
from secrets import *
from asnake.client import ASnakeClient
id_field_regex = re.compile(r"(^id_+\d)")
id_combined_regex = re.compile(r'[\W_]+', re.UNICODE)
def check_creators(client):
repos = client.get("repositories").json()
for repo in repos:
print(repo["name"] + "\n")
repo_id = repo["uri"].split("/")[2]
resources = client.get("repositories/{}/resources".format(repo_id), params={"all_ids": True}).json()
for resource_id in resources:
has_creator = False
resource = client.get("repositories/{}/resources/{}".format(repo_id, resource_id))
combined_id = ""
for field, value in resource.json().items():
id_match = id_field_regex.match(field)
if id_match:
combined_id += value + "-"
combined_id = combined_id[:-1]
if resource.json()["publish"] is True:
if resource.status_code == 200:
if "linked_agents" in resource.json():
linked_agents = resource.json()["linked_agents"]
for linked_agent in linked_agents:
if linked_agent["role"] == "creator":
has_creator = True
if has_creator is False:
print(f'{repo["name"]},{combined_id},Publish: {resource.json()["publish"]}')
else:
print(f'{repo["name"]},{combined_id},Publish: {resource.json()["publish"]}')
print("-" * 100)
asp_client = ASnakeClient(baseurl=as_api, username=as_un, password=as_pw)
asp_client.authorize()
check_creators(asp_client)