|
9 | 9 | filePath = secrets.filePath |
10 | 10 |
|
11 | 11 | 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: ') |
12 | 15 |
|
13 | 16 | data = json.dumps({'email':email,'password':password}) |
14 | 17 | header = {'content-type':'application/json','accept':'application/json'} |
|
20 | 23 | print 'authenticated' |
21 | 24 |
|
22 | 25 | #Post community |
23 | | -communityName = 'Test Community' |
24 | 26 | community = json.dumps({'name': communityName}) |
25 | 27 | post = requests.post(baseURL+'/rest/communities', headers=headerAuth, data=community).json() |
26 | 28 | print json.dumps(post) |
27 | 29 | communityID = post['link'] |
28 | 30 |
|
29 | 31 | #Post collection |
30 | | -collectionName = 'Test Collection' |
31 | 32 | collection = json.dumps({'name': collectionName}) |
32 | 33 | post = requests.post(baseURL+communityID+'/collections', headers=headerAuth, data=collection).json() |
33 | 34 | print json.dumps(post) |
34 | 35 | collectionID = post['link'] |
35 | 36 |
|
36 | 37 | #Post items |
37 | | -collectionMetadata = json.load(open(filePath+'sampleCollectionMetadata.json')) |
| 38 | +collectionMetadata = json.load(open(directory+'/'+'collectionMetadata.json')) |
38 | 39 | for itemMetadata in collectionMetadata: |
39 | 40 | for element in itemMetadata['metadata']: |
40 | 41 | if element['key'] == 'dc.identifier.other': |
41 | | - imageIdentifier = element['value'] |
| 42 | + fileIdentifier = element['value'] |
42 | 43 | itemMetadata = json.dumps(itemMetadata) |
43 | 44 | post = requests.post(baseURL+collectionID+'/items', headers=headerAuth, data=itemMetadata).json() |
44 | 45 | print json.dumps(post) |
45 | 46 | itemID = post['link'] |
46 | 47 |
|
47 | 48 | #Post bitstream |
48 | | - bitstream = directory+'/'+imageIdentifier+'.jpg' |
| 49 | + bitstream = directory+'/'+fileIdentifier+fileExtension |
49 | 50 | fileName = bitstream[bitstream.rfind('/')+1:] |
50 | 51 | data = open(bitstream, 'rb') |
51 | 52 | files = {'file': open(bitstream, 'rb')} |
|
0 commit comments