Skip to content

Commit e139e74

Browse files
author
ehanson8
committed
updates
1 parent f8d20df commit e139e74

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

addBibNumbersAndPost.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import json
2+
import requests
3+
import secrets
4+
import time
5+
import csv
6+
7+
startTime = time.time()
8+
9+
baseURL = secrets.baseURL
10+
user = secrets.user
11+
password = secrets.password
12+
13+
auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json()
14+
session = auth["session"]
15+
headers = {'X-ArchivesSpace-Session':session, 'Content_Type':'application/json'}
16+
17+
urisBibs = csv.DictReader(open(''))
18+
19+
f=csv.writer(open('bibNumberPush.csv', 'wb'))
20+
f.writerow(['uri']+['existingValue']+['bibNum'])
21+
22+
for row in urisBibs:
23+
uri = row['asURI']
24+
bibNum = row['bibNum']
25+
print uri
26+
record = requests.get(baseURL + uri, headers=headers).json()
27+
try:
28+
print record['user_defined']
29+
record['user_defined']['real_1'] = bibNum
30+
existingValue = 'Y'
31+
except:
32+
value = {}
33+
value['real_1'] = row['bibNum']
34+
record['user_defined'] = value
35+
print value
36+
existingValue = 'N'
37+
record = json.dumps(record)
38+
post = requests.post(baseURL + uri, headers=headers, data=record)#.json()
39+
print post
40+
f.writerow([uri]+[existingValue]+[bibNum]+[post])
41+
42+
elapsedTime = time.time() - startTime
43+
m, s = divmod(elapsedTime, 60)
44+
h, m = divmod(m, 60)
45+
print 'Total script run time: ', '%d:%02d:%02d' % (h, m, s)

0 commit comments

Comments
 (0)