-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetSingleRecord.py
44 lines (37 loc) · 1.25 KB
/
getSingleRecord.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
42
43
44
import json
import requests
import argparse
secretsVersion = input('To edit production server, enter the name of the \
secrets file: ')
if secretsVersion != '':
try:
secrets = __import__(secretsVersion)
print('Editing Production')
except ImportError:
secrets = __import__('secrets')
print('Editing Development')
else:
secrets = __import__('secrets')
print('Editing Development')
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--uri', help='URI of the object to retreive. \
optional - if not provided, the script will ask for input')
args = parser.parse_args()
if args.uri:
uri = args.uri
else:
uri = input('Enter handle (\'/repositories/2/resources/564\'): ')
baseURL = secrets.baseURL
user = secrets.user
password = secrets.password
repository = secrets.repository
auth = requests.post(baseURL + '/users/' + user + '/login?password='
+ password).json()
session = auth['session']
headers = {'X-ArchivesSpace-Session': session,
'Content_Type': 'application/json'}
output = requests.get(baseURL + uri, headers=headers).json()
uri = uri.replace('/repositories/' + repository + '/', '').replace('/', '-')
f = open(uri + '.json', 'w')
results = json.dump(output, f)
f.close()