-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.py
37 lines (23 loc) · 889 Bytes
/
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
import cmd
import requests
import json
def color_string(text, color_code):
return f"\x1b[{color_code}m{text}\x1b[0m"
class MyShell(cmd.Cmd):
intro = 'Welcome to GraphoPlex the distributed graph database. Type help or ? to list commands.\n'
prompt = color_string('GraphoPlex > ', 91)
def default(self, line):
url = 'http://127.0.0.1:8080/query'
# set header for content type
headers = {'Content-Type': 'application/json'}
# send post request with body query : line
json_data = {"query": line}
body = json.dumps(json_data)
# print response
response = requests.post(url, body, headers = headers)
print(response.text+"\n")
def do_quit(self, arg):
'Exit the shell.'
return True
if __name__ == '__main__':
MyShell().cmdloop()