-
Notifications
You must be signed in to change notification settings - Fork 0
/
getResourceIds.py
41 lines (35 loc) · 1.08 KB
/
getResourceIds.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
40
41
import json
import requests
import secrets
import csv
baseURL = secrets.baseURL
user = secrets.user
password = secrets.password
auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json()
session = auth["session"]
headers = {'X-ArchivesSpace-Session':session, 'Content_Type':'application/json'}
endpoint = '/repositories/4/resources?all_ids=true'
ids = requests.get(baseURL + endpoint, headers=headers).json()
f=csv.writer(open('output.csv', 'w', newline=''))
f.writerow(['id_0']+['ead_id']+['Published']+['Title']+['URL'])
for id in ids:
print(id)
endpoint = '/repositories/4/resources/'+str(id)
output = requests.get(baseURL + endpoint, headers=headers).json()
try:
id_0 = output['id_0']
except:
id_0 = ''
try:
ead_id = output['ead_id']
except:
ead_id = ''
try:
published = output['publish']
except:
published = ''
try:
title = output['finding_aid_title']
except:
title = ''
f.writerow([id_0]+[ead_id]+[published]+[title]+['https://aspace.lib.jmu.edu'+endpoint])