-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontainer_update.py
32 lines (25 loc) · 1.4 KB
/
container_update.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
from archivesspace import archivesspace
import argparse
import logging
import csv
import pprint
#This script replaces the existing indicator of a top container with a provided indicator number. It takes as input a csv file with the columns 'container_uri' and 'indicator'
if __name__ == "__main__":
CONFIGFILE = "archivesspace.cfg"
argparser = argparse.ArgumentParser()
argparser.add_argument("SERVERCFG", default="DEFAULT", help="Name of the server configuration section e.g. 'production' or 'recording'. Edit archivesspace.cfg to add a server configuration section. If no configuration is specified, the default settings will be used host=localhost user=admin pass=admin.")
argparser.add_argument("CSVFILE", default="DEFAULT", help="Path to CSV file for parsing.")
cliArguments = argparser.parse_args()
aspace = archivesspace.ArchivesSpace()
aspace.setServerCfg(CONFIGFILE, section=cliArguments.SERVERCFG)
aspace.connect()
with open(cliArguments.CSVFILE, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
record = aspace.get(row['container_uri'])
record['indicator'] = row['indicator']
try:
post = aspace.post(record['uri'], record)
print('Successful update for {}'.format(post['uri']))
except:
print('Failed update for {}'.format(row['container_uri']))