Skip to content

Commit 0647444

Browse files
committed
new script
1 parent 12efe30 commit 0647444

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Retrieves a count of archival objects associated with a particular resource. Upo
3434
#### [getArchivalObjectsByResource.py](/getArchivalObjectsByResource.py)
3535
Extracts 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).
3636

37+
#### [getArchivalObjectRefIdsForResource.py](/getArchivalObjectRefIdsForResource.py)
38+
Extracts the title, URI, ref_id, and date expression for all 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).
39+
3740
#### [getArrayPropertiesFromAgentsPeopleCSV.py](/getArrayPropertiesFromAgentsPeopleCSV.py)
3841
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.
3942

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

0 commit comments

Comments
 (0)