|
@@ -0,0 +1,52 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
+'''
|
|
|
+@File : kuaishou_socket.py
|
|
|
+@Time : 2019/05/28 03:00:17
|
|
|
+@Author : Liuyuqi
|
|
|
+@Version : 1.0
|
|
|
+@Contact : liuyuqi.gov@msn.cn
|
|
|
+@License : (C)Copyright 2019
|
|
|
+@Desc : None
|
|
|
+
|
|
|
+Request URL: wss://live-ws-pg-group2.kuaishou.com/websocket
|
|
|
+Request Method: GET
|
|
|
+Status Code: 101 Switching Protocols
|
|
|
+
|
|
|
+Accept-Encoding: gzip, deflate, br
|
|
|
+Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
|
|
|
+Cache-Control: no-cache
|
|
|
+Connection: Upgrade
|
|
|
+Host: live-ws-pg-group2.kuaishou.com
|
|
|
+Origin: https://live.kuaishou.com
|
|
|
+Pragma: no-cache
|
|
|
+Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
|
|
|
+Sec-WebSocket-Key: opUwBCN/VZdDkpQSokZJIQ==
|
|
|
+Sec-WebSocket-Version: 13
|
|
|
+Upgrade: websocket
|
|
|
+User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
|
|
|
+
|
|
|
+'''
|
|
|
+import asyncio
|
|
|
+import logging
|
|
|
+from datetime import datetime
|
|
|
+from aiowebsocket.converses import AioWebSocket
|
|
|
+
|
|
|
+# url = 'wss://api.bbxapp.vip/v1/ifcontract/realTime'
|
|
|
+url = 'wss://live-ws-pg-group2.kuaishou.com/websocket'
|
|
|
+
|
|
|
+async def startup(uri):
|
|
|
+ async with AioWebSocket(uri) as aws:
|
|
|
+ converse = aws.manipulator
|
|
|
+ # 客户端给服务端发送消息
|
|
|
+ await converse.send('{"action":"subscribe","args":["QuoteBin5m:14"]}')
|
|
|
+ while True:
|
|
|
+ mes = await converse.receive()
|
|
|
+ print('{time}-Client receive: {rec}'.format(
|
|
|
+ time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ try:
|
|
|
+ asyncio.get_event_loop().run_until_complete(startup(url))
|
|
|
+ except KeyboardInterrupt as exc:
|
|
|
+ logging.info('Quit.')
|