Skip to content

Commit 0ebc82f

Browse files
authored
Merge pull request #3 from ehanson8/master
update
2 parents 77b4dee + 3c3933f commit 0ebc82f

File tree

3 files changed

+51
-40
lines changed

3 files changed

+51
-40
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ All of these scripts require a secrets.py file in the same directory that must c
1010

1111
## Scripts
1212

13+
#### [getArchivalObjectsByResource.py](/getArchivalObjectsByResource.py)
14+
A GET script to extract all of the archival objects associated with a particular resource. Upon running the script, you will be prompted enter the resource ID (just the number, not the full URI).
15+
1316
#### [getArrayPropertiesFromAgentsPeopleCSV.py](/getArrayPropertiesFromAgentsPeopleCSV.py)
1417
This GET script retrieves specific properties, including proprerties that have arrays as values, from the JSON of ArchivesSpace agent_people records. In this example, the 'dates_of existence' property contains an array that must be iterated over. This requires a second level of iteration with 'for j in range (...)' on line 20, which is in addition to the iteration function 'for i in range (...)' on line 19, which was also found in the getPropertiesFromAgentsPeopleCSV.py script. As with the previous script, it also writes the properties' values into a CSV file which is specified in variable 'f' on line 17.
1518

@@ -29,6 +32,3 @@ This POST script will post new records to a generic API endpoint based the recor
2932

3033
#### [postOverwrite.py](/postOverwrite.py)
3134
This POST script will overwrite existing ArchivesSpace records based the 'uri' and can be used with any ArchivesSpace record type (e.g. resource, accession, subject, agent_people, agent_corporate_entity, archival_object, etc.). It requires a properly formatted JSON file (specified where [JSON File] appears in the 'records' variable on line 13) for the particular ArchivesSpace record type you are trying to post.
32-
33-
#### [searchArchivalObjectsByResource.py](/searchArchivalObjectsByResource.py)
34-
A GET script to extract all of the archival objects associated with a particular resource. To set the resource you want to search for, adjust the 'resourceNumber' variable on line 13

getArchivalObjectsByResource.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import requests
3+
import secrets
4+
import time
5+
6+
startTime = time.time()
7+
8+
def findKey(d, key):
9+
if key in d:
10+
yield d[key]
11+
for k in d:
12+
if isinstance(d[k], list):
13+
for i in d[k]:
14+
for j in findKey(i, key):
15+
yield j
16+
17+
baseURL = secrets.baseURL
18+
user = secrets.user
19+
password = secrets.password
20+
21+
resourceID= raw_input('Enter resource ID: ')
22+
23+
auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json()
24+
session = auth["session"]
25+
headers = {'X-ArchivesSpace-Session':session, 'Content_Type':'application/json'}
26+
27+
endpoint = '/repositories/3/resources/'+resourceID+'/tree'
28+
29+
output = requests.get(baseURL + endpoint, headers=headers).json()
30+
31+
archivalObjects = []
32+
for value in findKey(output, 'record_uri'):
33+
if 'archival_objects' in value:
34+
archivalObjects.append(value)
35+
36+
records = []
37+
for archivalObject in archivalObjects:
38+
output = requests.get(baseURL + archivalObject, headers=headers).json()
39+
records.append(output)
40+
41+
f=open('archivalObjects.json', 'w')
42+
json.dump(records, f)
43+
f.close()
44+
45+
elapsedTime = time.time() - startTime
46+
m, s = divmod(elapsedTime, 60)
47+
h, m = divmod(m, 60)
48+
print 'Total script run time: ', '%d:%02d:%02d' % (h, m, s)

searchArchivalObjectsByResource.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)