forked from CheckiO/checkio-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_webplugin.py
26 lines (19 loc) · 974 Bytes
/
test_webplugin.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
import subprocess
import json
import struct
pipe = subprocess.Popen(['checkio', 'webplugin'],
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
def send_message(data):
message = json.dumps(data).encode('utf-8')
pipe.stdin.write(struct.pack('I', len(message)))
pipe.stdin.write(message)
pipe.stdin.flush()
text_length_bytes = pipe.stdout.read(4)
#print(text_length_bytes)
text_length = struct.unpack('i', text_length_bytes)[0]
print(pipe.stdout.read(text_length).decode('utf-8'))
#send_message({'do': 'mission_file', 'domain': 'py', 'mission': 'best-stock'})
#send_message({'do': 'read_file', 'filename': '/Users/oleksandrliabakh/www/checkio/mission-design/solutions_alfi/Elementary/best_stock.py'})
#send_message({'do': 'write_file', 'filename': '/Users/oleksandrliabakh/www/checkio/mission-design/solutions_alfi/test.py', 'text': 'WOW'})
send_message({"event": "plugin:test", "a": "1", "b": "2"})