forked from ehanson8/dspace-editing
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostMultipleItemsForTesting.py
51 lines (43 loc) · 1.55 KB
/
postMultipleItemsForTesting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
import secrets
import time
import urllib3
secretsVersion = input('To edit production, enter secrets filename: ')
if secretsVersion != '':
try:
secrets = __import__(secretsVersion)
print('Editing Production')
except ImportError:
print('Editing Stage')
else:
print('Editing Stage')
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
baseURL = secrets.baseURL
email = secrets.email
password = secrets.password
filePath = secrets.filePath
skippedCollections = secrets.skippedCollections
startTime = time.time()
data = {'email': email, 'password': password}
header = {'content-type': 'application/json', 'accept': 'application/json'}
session = requests.post(baseURL+'/rest/login', headers=header,
params=data).cookies['JSESSIONID']
cookies = {'JSESSIONID': session}
headerFileUpload = {'accept': 'application/json'}
cookiesFileUpload = cookies
status = requests.get(baseURL+'/rest/status', headers=header, cookies=cookies).json()
userFullName = status['fullname']
print('authenticated')
itemIds = ['/rest/items/226e5fcb-0652-4aba-8f13-674533f1bcf3']
directory = ''
filename = 'file_example.jpg'
count = 250
while count < 300:
count = count + 1
for item in itemIds:
bitstream = directory+str(count).zfill(2)+filename
data = open(bitstream, 'rb')
link = baseURL+item+'/bitstreams?name='+str(count).zfill(2)+filename
post = requests.post(link, headers=headerFileUpload, cookies=cookies,
data=data).json()
print(post)