-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd.py
36 lines (29 loc) · 825 Bytes
/
cmd.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
import requests
import json
import readline
APP_URL = "http://localhost:5000"
SECRET_TOKEN = "azerty"
class PythonStreamer:
def __init__(self):
self.start_streaming = False
def cmd_stream(self):
if not self.start_streaming:
self.start_streaming = True
return
hl = readline.get_current_history_length()
last_cmd = readline.get_history_item(hl)
headers = {
"token": SECRET_TOKEN,
"Content-Type": "application/json",
}
data = {
"command": last_cmd,
"type": "python",
}
requests.post(
f"{APP_URL}/command",
headers=headers,
data=json.dumps(data),
)
streamer = PythonStreamer()
readline.set_pre_input_hook(streamer.cmd_stream)