-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreqs.py
191 lines (126 loc) · 4.83 KB
/
reqs.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import requests
import os
import json
import ast
import subprocess
import time
path = "C:/Program Files/IMSI/Amnesia"
os.chdir(path)
command = ["java", "-Xms1024m", "-Xmx4096m", "-Dorg.eclipse.jetty.server.Request.maxFormKeys=1000000", "-Dorg.eclipse.jetty.server.Request.maxFormContentSize=1000000", "-jar", "amnesiaBackEnd-1.0-SNAPSHOT.jar", "--server.port=8181"]
subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
response=requests.post('http://localhost:8181/getSession')
json_response = json.loads(response.text)
session_id = json_response['Session_Id']
print(session_id)
#START FIRST CALL, LOAD DATA SET
cookies = {
'JSESSIONID': f"{session_id}",
}
headers = {
'Cookie': f"{session_id}",
}
#COLUMNS TAKEN FROM PRESIDIO###################################################
#
#
#
presidio_dict = '{"Lastname":"string","Firstname":"string","Country":"string"}'
#
#
#
################################################################################
files = {
'file': open('C:/Users/sothr/Desktop/venetia/estonia-passenger-list.csv','rb'),
'del': (None, ';'),
'datasetType': (None, 'tabular'),
'columnsType': (None, presidio_dict),
}
response = requests.post('http://localhost:8181/loadData', cookies=cookies, files=files,allow_redirects=True)
print(response.text)
#2ND CALL GENERATE HIERARCHY
files = {
'hierType': (None,'distinct'),
'varType': (None,'string'),
'attribute': (None,'Lastname'),
'hierName': (None,'codes_hier'),
'sorting': (None,'alphabetical'),
'fanout': (None,'3'),
}
response = requests.post('http://localhost:8181/generateHierarchy', cookies=cookies, files=files,allow_redirects=True)
with open('C:/Users/sothr/Desktop/venetia/pos_p_codes.txt', 'wb') as f:
f.write(response.content)
print(response.text)
files = {
'hierType': (None,'distinct'),
'varType': (None,'string'),
'attribute': (None,'Firstname'),
'hierName': (None,'fcodes_hier'),
'sorting': (None,'alphabetical'),
'fanout': (None,'3'),
}
response = requests.post('http://localhost:8181/generateHierarchy', cookies=cookies, files=files,allow_redirects=True)
with open('C:/Users/sothr/Desktop/venetia/pos1_p_codes.txt', 'wb') as f:
f.write(response.content)
print(response.text)
#masking attribs --form hierType=mask
#--form varType=string
#--form attribute="Procedure Codes"
#--form hierName=codes_hier
#--form length=3
files = {
'hierType': (None,'mask'),
'varType': (None,'string'),
'attribute': (None,'Country'),
'hierName': (None,'ccodes_hier'),
'length': (None,'4'),
}
response = requests.post('http://localhost:8181/generateHierarchy', cookies=cookies, files=files,allow_redirects=True)
with open('C:/Users/sothr/Desktop/venetia/posc_p_codes.txt', 'wb') as f:
f.write(response.content)
print(response.text)
time.sleep(3)
#3RD CALL GENERATE THE HIERARCHY
files = {
'hierarchies': open('C:/Users/sothr/Desktop/venetia/pos_p_codes.txt', 'rb'),
}
response = requests.post('http://localhost:8181/loadHierarchies', cookies=cookies, files=files)
print(response.text)
files = {
'hierarchies': open('C:/Users/sothr/Desktop/venetia/pos1_p_codes.txt', 'rb'),
}
response = requests.post('http://localhost:8181/loadHierarchies', cookies=cookies, files=files)
print(response.text)
files = {
'hierarchies': open('C:/Users/sothr/Desktop/venetia/posc_p_codes.txt', 'rb'),
}
response = requests.post('http://localhost:8181/loadHierarchies', cookies=cookies, files=files)
print(response.text)
time.sleep(3)
#4TH CALL ANONYMIZE
files = {
'bind': (None, '{"Lastname":"codes_hier","Firstname":"fcodes_hier","Country":"ccodes_hier"}'),
'k': (None, '3'),
}
response = requests.post('http://localhost:8181/anonymization', cookies=cookies, files=files)
with open('C:/Users/sothr/Desktop/venetia/anonymized_mixedData2.csv', 'wb') as f:
f.write(response.content)
print(response.text)
#5TH CALL SAVE ANONYMIZED DATA
time.sleep(4)
with open('C:/Users/sothr/Desktop/venetia/anonymized_mixedData2.csv', 'r') as f:
dict_str = f.read().replace('{"Solutions":', '').strip()[:-1]
my_dict = ast.literal_eval(dict_str)
last_safe = None
for key, value in my_dict.items():
if isinstance(value, dict):
if "result" in value and value["result"] == "safe":
if "levels" in value:
last_safe = value["levels"]
if last_safe is not None:
print(last_safe)
last=last_safe.replace(" ","")
files = {
'sol': (None, last),
}
response = requests.post('http://localhost:8181/getSolution', cookies=cookies, files=files)
with open('C:/Users/sothr/Desktop/venetia/anonymized_simple_table_data2.txt', 'wb') as f:
f.write(response.content)