forked from MITLibraries/archivesspace-api-python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getUnassociatedContainers.py
39 lines (30 loc) · 1.03 KB
/
getUnassociatedContainers.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
import requests
import secret
import time
import csv
secretVersion = input('To edit production server, enter secret filename: ')
if secretVersion != '':
try:
secret = __import__(secretVersion)
print('Editing Production')
except ImportError:
print('Editing Development')
else:
print('Editing Development')
startTime = time.time()
baseURL = secret.baseURL
user = secret.user
password = secret.password
repository = secret.repository
auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json()
session = auth["session"]
headers = {'X-ArchivesSpace-Session': session, 'Content_Type': 'application/json'}
endpoint = '/search?page=1&page_size=2000&entity_type[]=top_container&filter_term[]={"empty_u_sbool":true}&q="/repositories/3"'
results = requests.get(baseURL + endpoint, headers=headers).json()
results = results['results']
f = csv.writer(open('unassociatedTopContainer.csv', 'w'))
f.writerow(['uri'])
for result in results:
uri = result['uri']
f.writerow([uri])
print(len(results))