-
Notifications
You must be signed in to change notification settings - Fork 2
/
licenses.py
157 lines (145 loc) · 4.38 KB
/
licenses.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
# This script load the licenses from Serial Solutions 360 ERM
# Usage:
#
# In the oriole-data-migration folder, run
# pipenv run python ./licenses.py
import settings
from zeep import Client
from zeep.wsse.username import UsernameToken
import json
import pickle
import requests
import uuid
from datetime import datetime
from random import choice
from string import ascii_lowercase, digits
import sys
if len(sys.argv) == 2 and sys.argv[1] == 'dump':
client = Client(settings.SS_WSDL)
req_data = {
'LibraryCode': settings.SS_LIBRARY_CODE,
'UserName': settings.SS_USERNAME,
'Password': settings.SS_PASSWORD
}
data = client.service.LicenseData(request=req_data)
pickle.dump(data, open('data/licenses.pickle', 'wb'))
sys.exit(0)
# {
# "id": "2c91808c6a7a80d7016a7a8cf0b80017",
# "dateCreated": "2019-05-02T21:56:58Z",
# "links": [],
# "customProperties": {},
# "tags": [],
# "lastUpdated": "2019-05-02T21:56:58Z",
# "endDate": "2019-05-31T00:00:00Z",
# "startDate": "2019-05-03T00:00:00Z",
# "docs": [],
# "name": "Test",
# "orgs": [],
# "type": {
# "id": "2c91808c6a7a80d7016a7a81fded0008",
# "value": "local",
# "label": "Local"
# },
# "status": {
# "id": "2c91808c6a7a80d7016a7a81fe2d000f",
# "value": "active",
# "label": "Active"
# },
# "supplementaryDocs": [],
# "description": "test",
# "_links": {
# "linkedResources": {
# "href": "/licenses/licenseLinks?filter=owner.id%3d2c91808c6a7a80d7016a7a8cf0b80017"
# }
# },
# "openEnded": false
# }
# post to /licenses
headers = settings.build_headers()
data = pickle.load(open('data/licenses.pickle', 'rb'))
types = {
'Consortial': {
"id": "2c91808c6a7a80d7016a7a81fdf50009",
"value": "consortial",
"label": "Consortial"
},
'Negotiated': {
"id": "2c91808c6a7a80d7016a7a81fe0d000b",
"value": "negotiated",
"label": "Negotiated"
},
'License not required': {
"id": "2c91808c6a7a80d7016a7a81fdfe000a",
"value": "license_not_required",
"label": "License not required"
},
'Click-Through': {
"id": "2c91808c6a7a80d7016a7a81fded0008",
"value": "click_through",
"label": "Click-Through"
},
None: {
"id": "2c91808c6a7a80d7016a7a81fdce0004",
"value": "none",
"label": "None"
}
}
statuses = {
'Active': {
"id": "2c91808c6a7a80d7016a7a81fe2d000f",
"value": "active",
"label": "Active"
},
'Pending': {
"id": "2c91808c6a7a80d7016a7a81fe26000e",
"value": "pending",
"label": "Pending"
},
'Retired': {
"id": "2c91808c6a7a80d7016a7a81fe3a0011",
"value": "retired",
"label": "Retired"
},
None: {
"id": "2c91808c6a7a80d7016a7a81fe1a000d",
"value": "none",
"label": "None"
}
}
# types: {'License not required', 'Negotiated', 'Click-Through', 'Consortial', None}
# statuses: {'Active', 'Retired', None, 'Pending'}
api_url = f'{settings.ORIOLE_API_ROOT}/licenses/licenses'
for license in data:
id = ''.join(choice(ascii_lowercase+digits) for i in range(32))
name = license['LicenseName']['Content']
ss_id = license['LicenseId']['Content']
type = license['Type']['Content']
status = license['Status']['Content']
terms = license['LicenseTerms']
customProperties = {}
authorizedUsers = terms['AuthorizedUsers']['Content']
if (authorizedUsers is not None):
customProperties['authorizedUsers'] = authorizedUsers['string']
customProperties['authorizedUsersNote'] = terms['AuthorizedUsersNote']['Content']
customProperties['iLLRecordKeepingNote'] = terms['ILLRecordKeepingNote']['Content']
payload = {
'id': id,
'name': license['LicenseName']['Content'],
'dateCreated': str(datetime.now()),
'lastUpdated': str(datetime.now()),
'type': types[type],
'status': statuses[status],
'description': '',
'openEnded': False,
'customProperties': customProperties,
'orgs': {},
'docs': [],
'supplementaryDocs': [],
"tags": [],
"description": license['LicenseNote']['Content']
}
response = requests.post(api_url, headers=headers, data=json.dumps(payload), verify=False)
if response.status_code != 201:
print(response.status_code, response.text)