[Archivesspace_Users_Group] Generating a list of collections URLs
Corey Schmidt
Corey.Schmidt at uga.edu
Tue Mar 22 17:54:06 EDT 2022
Hi Daniel,
I can't speak with direct experience for the custom reports module of 3.2 (but I believe it should be able to get you that info), but for 3.1.1, you could absolutely run a python script against your ArchivesSpace API to get that. For example,
import csv
import re
from asnake.client import ASnakeClient
id_field_regex = re.compile(r"(^id_+\d)")
id_combined_regex = re.compile(r'[\W_]+', re.UNICODE)
def write_csv(mode, coll_title, coll_id, coll_url):
with open("res_urls.csv", mode=mode, newline='', encoding='utf-8') as res_urls:
file_write = csv.writer(res_urls, delimiter=",")
file_write.writerow([coll_title, coll_id, coll_url])
res_urls.close()
def grab_res_urls(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:
resource = client.get("repositories/{}/resources/{}".format(repo_id, resource_id))
if resource.status_code == 200:
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:
write_csv("a", resource.json()["title"], combined_id, resource.json()["uri"])
else:
print("Error with getting repositories/{}/resources/{}".format(repo_id, resource_id))
print("-" * 100)
def run():
asp_client = ASnakeClient(baseurl=as_api, username=as_un, password=as_pw)
asp_client.authorize()
write_csv("w", "Collection_Title", "Collection_ID", "Collection_URL")
grab_res_urls(asp_client)
run()
Running the above would get you a CSV file with all published collections and their info, You would have to tweak the above code to add the "https://alaska.libraryhost.com" part to the URL's returned. Also, under def run():, replace as_api, as_un, and as_pw with your archivesspace API URL, username, and password.
Example output:
Florene Young papers UA04-025 /repositories/5/resources/4714
I'm more than happy to walk you through the steps of running and/or tweaking the above if you would like, so feel free to email me (Corey.Schmidt at uga.edu).
Hope this helps,
Corey
________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> on behalf of Cornwall, Daniel D (EED) <daniel.cornwall at alaska.gov>
Sent: Tuesday, March 22, 2022 4:44 PM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org>
Subject: [Archivesspace_Users_Group] Generating a list of collections URLs
[EXTERNAL SENDER - PROCEED CAUTIOUSLY]
Hi All,
My institution has cataloged our finding aids into our regular library catalog. With our recent-ish migration to ArchivesSpace, there is interest to ensure that all of our catalog finding aid records actually have ArchivesSpace URLs.
I know there is a resource list report in AS, but it doesn’t provide the URL. Ideally, I’d like a report that lists:
Collection Name
Collection Identifier
Collection URL
For example,
George L. Harrington Photograph Collection, ca. 1909-1917
Identifier: PCA 6
https://alaska.libraryhost.com/repositories/2/resources/458
We’re currently on v. 3.1.1 – Could such a report be run on this version, and if not, could something like this be run in the custom reports module in 3.2? I’m not sure we’d immediately upgrade if we couldn’t get such a report anyway.
Thanks for any thoughts, insight or experience. - Daniel
[cid:image001.png at 01D83DEA.286A0CF0]
====================================================
Daniel Cornwall
Pronouns: he/him/his
Continuing Resources Libarian
Information Services Staff, Alaska State Library
Andrew P. Kashevaroff Building
Phone: 907.465.2988
Mail: PO Box 110571, Juneau, AK 99811
Visit: 395 Whittier St., Juneau, AK 99801
email<mailto:daniel.cornwall at alaska.gov> | web<http://library.alaska.gov/> | sign up for event notifications<http://list.state.ak.us/mailman/listinfo/at-apk-and-sjm>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20220322/2aaf97ec/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 16846 bytes
Desc: image001.png
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20220322/2aaf97ec/attachment-0001.png>
More information about the Archivesspace_Users_Group
mailing list