This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
77-ArchivesSpace-API-Workshop.html
64 lines (55 loc) · 2.36 KB
/
77-ArchivesSpace-API-Workshop.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<link href="css/slides.css" rel="stylesheet" />
</head>
<body>
<nav>
<a id="start-slide" rel="nav" href="00-ArchivesSpace-API-Workshop.html" title="Return to start of presentation">Start</a>
<a id="prev-slide" rel="nav" href="76-ArchivesSpace-API-Workshop.html" title="Previous slide">Prev</a>
<a id="next-slide" rel="nav" href="78-ArchivesSpace-API-Workshop.html" title="Next slide">Next</a>
</nav>
<section><h1>6. Accessions</h1>
<h2>update_accession implementation</h2>
<p>We need three pieces of information</p>
<ol>
<li>our repo_id</li>
<li>our accession_id (the numeric one from the <em>uri</em>, not <em>id_0</em>, <em>id_1</em>, etc.)</li>
<li>our updated accession model</li>
</ol>
<p>Notice the similarity to <em>update_agent</em>.</p>
<pre><code class="language-python"> def update_accession(api_url, auth_token, repo_id, accession_id, accession_model):
'''update an accession record and return a results message'''
data = json.JSONEncoder().encode(accession_model).encode('utf-8')
url = api_url+'/repositories/'+str(repo_id)+'/accessions/'+str(accession_id)
req = urllib.request.Request(
url = url,
data = None,
headers = {'X-ArchivesSpace-Session': auth_token},
method = 'POST')
try:
response = urllib.request.urlopen(req, data)
except urllib.error.URLError as e:
print(e.reason)
return None
except urllib.error.HTTPError as e:
print(e.code)
print(e.read())
return None
src = response.read().decode('utf-8')
return json.JSONDecoder().decode(src)
</code></pre>
<p>And our test in the <em>if</em> block</p>
<pre><code class="language-python"> # Test update_accession
print('Test update_accession()')
accession_id = int(input('Enter accession id to uppdate: '))
accession_model = list_accession(api_url, auth_token, repo_id, accession_id)
accession_model['title'] = input('Enter new title: ')
result = update_accession(api_url, auth_token, repo_id, accession_id, accession_model)
print('update result', json.dumps(result, indent=4))
</code></pre>
<p>Full listing <a href="accession.py">accession.py</a></p>
</section>
<script type="text/javascript" src="js/keyboard-nav.js"></script>
</body>
</html>