-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpathway_client.py
44 lines (35 loc) · 1.01 KB
/
pathway_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
import requests
import re
import os
while True:
data_input = input(">> ")
data = {
"user": "user",
"query": data_input
+ ",the command should be the last word(s) of the single sentence and in double quotes",
}
post_response = requests.post("http://localhost:8080/", json=data)
post_response_json = post_response.json()
# print(post_response_json)
import re
text = post_response_json
pattern1 = '^(.*) "(.*)" command.'
pattern2 = '^(.*) "(.*)"'
pattern3 = '^(.*) "(.*)"\.'
m1 = re.search(pattern1, text)
m2 = re.search(pattern2, text)
m3 = re.search(pattern3, text)
if m1:
found = m1.group(2)
# print("Pattern 1 match: ", found)
os.system(found)
elif m2:
found = m2.group(2)
# print("Pattern 2 match: ", found)
os.system(found)
elif m3:
found = m3.group(2)
# print("Pattern 3 match: ", found)
os.system(found)
else:
print("No match found.")