-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadjson.py
More file actions
executable file
·37 lines (30 loc) · 941 Bytes
/
loadjson.py
File metadata and controls
executable file
·37 lines (30 loc) · 941 Bytes
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
#!/usr/bin/env python
import asyncio
import websockets
import json
import sys
async def test_client():
try:
with open(image_file, 'r') as file:
data = json.load(file)
print(json.dumps(data, indent=4))
except FileNotFoundError:
print(f"Error: The file '{image_file}' was not found.")
quit()
except json.JSONDecodeError:
print(f"Error: Could not decode JSON from '{image_file}'. Check file format.")
quit()
try:
uri = "ws://ledarray1:8765"
async with websockets.connect(uri) as websocket:
await websocket.send(json.dumps(data))
print(f"Sent: {data}")
except:
print(f"Error connecting to websocket server on {uri}")
# Run the client
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.exit("Require a json file argument")
else:
image_file = sys.argv[1]
asyncio.run(test_client())