Skip to content

Instantly share code, notes, and snippets.

@helrond
Last active August 29, 2015 14:08
Show Gist options
  • Save helrond/1ef5b5bd47b47bd52f02 to your computer and use it in GitHub Desktop.
Save helrond/1ef5b5bd47b47bd52f02 to your computer and use it in GitHub Desktop.
A simple Python script to export EAD files using ArchivesSpace's API
#!/usr/bin/env python
import requests
import json
# the base URL of your ArchivesSpace installation
baseURL = 'Your URL here'
# the id of your repository
repository = 'Your repository id here'
# the username to authenticate with
user = 'username goes here'
# the password for the username above
password = 'password goes here'
# authenticates the session
auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json()
session = auth["session"]
if auth.status_code == 200:
print "Authenticated!"
headers = {'X-ArchivesSpace-Session':session}
# Gets the IDs of all resources in the repository
resourceIds = requests.get(baseURL + '/repositories/'+repository+'/resources?all_ids=true', headers=headers)
# Exports EAD for all resources whose IDs contain 'FA'
for id in resourceIds.json():
resource = (requests.get(baseURL + '/repositories/'+repository+'/resources/' + str(id), headers=headers)).json()
resourceID = resource["id_0"]
if "FA" in resourceID:
ead = requests.get(baseURL + '/repositories/'+repository+'/resource_descriptions/'+str(id)+'.xml', headers=headers).text
# Sets the location where the files should be saved
destination = 'location goes here'
f = open(destination+resourceID+'.xml', 'w')
f.write(ead.encode('utf-8'))
f.close
print resourceID + ' exported to ' + destination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment