Skip to content

Commit a0ea8cc

Browse files
authored
Update postItem.py
1 parent 0ed976b commit a0ea8cc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

postItem.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
filePath = secrets.filePath
1010

1111
directory = filePath+raw_input('Enter directory name: ')
12+
fileExtension = '.'+raw_input('Enter file extension: ')
13+
communityName = raw_input('Enter community name: ')
14+
collectionName = raw_input('Enter collectionn name: ')
1215

1316
data = json.dumps({'email':email,'password':password})
1417
header = {'content-type':'application/json','accept':'application/json'}
@@ -20,32 +23,30 @@
2023
print 'authenticated'
2124

2225
#Post community
23-
communityName = 'Test Community'
2426
community = json.dumps({'name': communityName})
2527
post = requests.post(baseURL+'/rest/communities', headers=headerAuth, data=community).json()
2628
print json.dumps(post)
2729
communityID = post['link']
2830

2931
#Post collection
30-
collectionName = 'Test Collection'
3132
collection = json.dumps({'name': collectionName})
3233
post = requests.post(baseURL+communityID+'/collections', headers=headerAuth, data=collection).json()
3334
print json.dumps(post)
3435
collectionID = post['link']
3536

3637
#Post items
37-
collectionMetadata = json.load(open(filePath+'sampleCollectionMetadata.json'))
38+
collectionMetadata = json.load(open(directory+'/'+'collectionMetadata.json'))
3839
for itemMetadata in collectionMetadata:
3940
for element in itemMetadata['metadata']:
4041
if element['key'] == 'dc.identifier.other':
41-
imageIdentifier = element['value']
42+
fileIdentifier = element['value']
4243
itemMetadata = json.dumps(itemMetadata)
4344
post = requests.post(baseURL+collectionID+'/items', headers=headerAuth, data=itemMetadata).json()
4445
print json.dumps(post)
4546
itemID = post['link']
4647

4748
#Post bitstream
48-
bitstream = directory+'/'+imageIdentifier+'.jpg'
49+
bitstream = directory+'/'+fileIdentifier+fileExtension
4950
fileName = bitstream[bitstream.rfind('/')+1:]
5051
data = open(bitstream, 'rb')
5152
files = {'file': open(bitstream, 'rb')}

0 commit comments

Comments
 (0)