forked from gtfierro/point-label-sharing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
86 lines (72 loc) · 2.3 KB
/
client.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
import json
import requests
d1 = {
"name": "test1",
"contents": [
["col1","col2"],
["abcdefg.5678.re3", "val2"]
]
}
file_list = requests.get('http://localhost:5000/file').json()
print(f"file list: {file_list}")
resp = requests.post('http://localhost:5000/file', data=json.dumps(d1)).json()
fileid = resp['fileid']
print(f"file saved with id: {fileid}")
contents = requests.get(f'http://localhost:5000/file/{fileid}').json()
print(f'Got contents of file {fileid}: {contents}')
template_list = requests.get('http://localhost:5000/template').json()
print(f"template list: {template_list}")
rule_list = requests.get('http://localhost:5000/rule').json()
print(f"rule list: {rule_list}")
# #Replace
# # instantiate rule
# rule_stuff = {
# 'cols': [0],
# 'args': [False, 'abc','replaced']
# }
# resp = requests.post('http://localhost:5000/rule/replace', data=json.dumps(rule_stuff)).json()
# ruleid=resp['ruleid']
# print(f"ruleid: {ruleid}")
#Trim
# instantiate rule
rule_stuff = {
'cols': [0],
'args': [1, 5]
}
resp = requests.post('http://localhost:5000/rule/trim', data=json.dumps(rule_stuff)).json()
ruleid=resp['ruleid']
print(f"ruleid: {ruleid}")
# #Split
# # instantiate rule
# rule_stuff = {
# 'cols': [0],
# 'args': [".", 2]
# }
# resp = requests.post('http://localhost:5000/rule/split', data=json.dumps(rule_stuff)).json()
# ruleid=resp['ruleid']
# print(f"ruleid: {ruleid}")
# #Remove
# # instantiate rule
# rule_stuff = {
# 'cols': [0],
# 'args': ["."]
# }
# resp = requests.post('http://localhost:5000/rule/remove', data=json.dumps(rule_stuff)).json()
# ruleid=resp['ruleid']
# print(f"ruleid: {ruleid}")
# #Regex Match (Doesn't work yet)
# # instantiate rule
# rule_stuff = {
# 'cols': [0],
# 'args': ["\s"]
# }
# resp = requests.post('http://localhost:5000/rule/regex_match', data=json.dumps(rule_stuff)).json()
# ruleid=resp['ruleid']
# print(f"ruleid: {ruleid}")
ruledef = requests.get(f'http://localhost:5000/rule/{ruleid}').json()
print(f"got defined rule: {ruledef}")
resp = requests.post(f'http://localhost:5000/apply/{fileid}/{ruleid}').json()
newfileid = resp['fileid']
print(f"new file id: {newfileid}")
contents = requests.get(f'http://localhost:5000/file/{newfileid}').json()
print(f'Running rule on {fileid} gave us {newfileid} with content: {contents}')