-
Notifications
You must be signed in to change notification settings - Fork 0
/
singleItemGet.py
50 lines (44 loc) · 1.23 KB
/
singleItemGet.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
45
46
47
48
49
50
from asnake.client import ASnakeClient
import json
import re
import html
import re
import getopt
import sys
import os
from getpass import getpass
wwfile = os.getcwd() + "\\aspw.txt"
if os.path.exists(wwfile):
with open(wwfile, "r") as rfile:
for i, line in enumerate(rfile):
if i == 0:
authun = re.sub("\n", "", line)
if i == 1:
authww = re.sub("\n", "", line)
else:
authun = input("Username: ")
authww = getpass()
#Connect to ArchivesSpace API
client = ASnakeClient(baseurl="https://collectionguides.universiteitleiden.nl/staff/api",
username=authun,
password=authww)
client.authorize()
#If given --obj=XXX argument process that Archival Object. Else process ubl002.
try:
opts, args = getopt.getopt(sys.argv[1:], 'o', ['obj='])
for opt, arg in opts:
if opt in '--obj':
if not arg:
print("Error: No argument given.")
sys.exit(2)
else:
obj_num = arg
else:
print("Unregocnized argument: " + opt)
if not opts:
obj_num = "66508"
except getopt.GetoptError as err:
print(str(err))
sys.exit(2)
digital_object = client.get("/repositories/2/archival_objects/" + obj_num)
print(json.dumps(digital_object.json(), indent=4))