Skip to content

Commit 7bd705a

Browse files
author
ehanson8
committed
script updates
1 parent 8e27d67 commit 7bd705a

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

postItem.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
session = requests.post(baseURL+'/rest/login', headers=header, data=data).content
1616
headerAuth = {'content-type':'application/json','accept':'application/json', 'rest-dspace-token':session}
1717
headerAuthFileUpload = {'accept':'application/json', 'rest-dspace-token':session}
18+
status = requests.get(baseURL+'/rest/status', headers=headerAuth).json()
19+
userFullName = status['fullname']
1820
print 'authenticated'
1921

2022
#Post community
@@ -49,25 +51,38 @@
4951
files = {'file': open(bitstream, 'rb')}
5052
post = requests.post(baseURL+itemID+'/bitstreams?name='+fileName, headers=headerAuthFileUpload, data=data).json()
5153

52-
#Create provenance note
54+
#Create provenance notes
5355
provNote = {}
5456
provNote['key'] = 'dc.description.provenance'
5557
provNote['language'] = 'en_US'
56-
bitstreams = requests.get(baseURL+itemID+'/bitstreams', headers=headerAuth).json()
57-
bitstreamCount = len(bitstreams)
5858
utc= datetime.datetime.utcnow()
5959
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)
6163
for bitstream in bitstreams:
6264
fileName = bitstream['name']
6365
size = str(bitstream['sizeBytes'])
6466
checksum = bitstream['checkSum']['value']
6567
algorithm = bitstream ['checkSum']['checkSumAlgorithm']
6668
provNoteValue = provNoteValue+' '+fileName+': '+size+' bytes, checkSum: '+checksum+' ('+algorithm+')'
6769
provNote['value'] = provNoteValue
68-
provNote = json.dumps([provNote])
6970

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])
7186
post = requests.put(baseURL+itemID+'/metadata', headers=headerAuth, data=provNote)
7287
print post
7388

0 commit comments

Comments
 (0)