|
15 | 15 | session = requests.post(baseURL+'/rest/login', headers=header, data=data).content |
16 | 16 | headerAuth = {'content-type':'application/json','accept':'application/json', 'rest-dspace-token':session} |
17 | 17 | headerAuthFileUpload = {'accept':'application/json', 'rest-dspace-token':session} |
| 18 | +status = requests.get(baseURL+'/rest/status', headers=headerAuth).json() |
| 19 | +userFullName = status['fullname'] |
18 | 20 | print 'authenticated' |
19 | 21 |
|
20 | 22 | #Post community |
|
49 | 51 | files = {'file': open(bitstream, 'rb')} |
50 | 52 | post = requests.post(baseURL+itemID+'/bitstreams?name='+fileName, headers=headerAuthFileUpload, data=data).json() |
51 | 53 |
|
52 | | - #Create provenance note |
| 54 | + #Create provenance notes |
53 | 55 | provNote = {} |
54 | 56 | provNote['key'] = 'dc.description.provenance' |
55 | 57 | provNote['language'] = 'en_US' |
56 | | - bitstreams = requests.get(baseURL+itemID+'/bitstreams', headers=headerAuth).json() |
57 | | - bitstreamCount = len(bitstreams) |
58 | 58 | utc= datetime.datetime.utcnow() |
59 | 59 | utcTime = utc.strftime('%Y-%m-%dT%H:%M:%SZ') |
60 | | - provNoteValue = 'Made available in DSpace on '+utcTime+' (GMT). No. of bitstreams: '+str(bitstreamCount) |
| 60 | + bitstreams = requests.get(baseURL+itemID+'/bitstreams', headers=headerAuth).json() |
| 61 | + bitstreamCount = len(bitstreams) |
| 62 | + provNoteValue = 'Submitted by '+userFullName+' ('+email+') on '+utcTime+' (GMT). No. of bitstreams: '+str(bitstreamCount) |
61 | 63 | for bitstream in bitstreams: |
62 | 64 | fileName = bitstream['name'] |
63 | 65 | size = str(bitstream['sizeBytes']) |
64 | 66 | checksum = bitstream['checkSum']['value'] |
65 | 67 | algorithm = bitstream ['checkSum']['checkSumAlgorithm'] |
66 | 68 | provNoteValue = provNoteValue+' '+fileName+': '+size+' bytes, checkSum: '+checksum+' ('+algorithm+')' |
67 | 69 | provNote['value'] = provNoteValue |
68 | | - provNote = json.dumps([provNote]) |
69 | 70 |
|
70 | | - #Post provenance note |
| 71 | + provNote2 = {} |
| 72 | + provNote2['key'] = 'dc.description.provenance' |
| 73 | + provNote2['language'] = 'en_US' |
| 74 | + |
| 75 | + provNote2Value = 'Made available in DSpace on '+utcTime+' (GMT). No. of bitstreams: '+str(bitstreamCount) |
| 76 | + for bitstream in bitstreams: |
| 77 | + fileName = bitstream['name'] |
| 78 | + size = str(bitstream['sizeBytes']) |
| 79 | + checksum = bitstream['checkSum']['value'] |
| 80 | + algorithm = bitstream ['checkSum']['checkSumAlgorithm'] |
| 81 | + provNote2Value = provNote2Value+' '+fileName+': '+size+' bytes, checkSum: '+checksum+' ('+algorithm+')' |
| 82 | + provNote2['value'] = provNote2Value |
| 83 | + |
| 84 | + #Post provenance notes |
| 85 | + provNote = json.dumps([provNote, provNote2]) |
71 | 86 | post = requests.put(baseURL+itemID+'/metadata', headers=headerAuth, data=provNote) |
72 | 87 | print post |
73 | 88 |
|
|
0 commit comments