kwebsocket 1.2__tar.gz → 1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kwebsocket-1.2 → kwebsocket-1.3}/PKG-INFO +2 -2
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket/__init__.py +1 -1
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket/rfdszbfnbxrdfgvxrhbdtxrhtbs.py +49 -8
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket.egg-info/PKG-INFO +2 -2
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket.egg-info/SOURCES.txt +0 -0
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket.egg-info/dependency_links.txt +0 -0
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket.egg-info/requires.txt +0 -0
- {kwebsocket-1.2 → kwebsocket-1.3}/kwebsocket.egg-info/top_level.txt +0 -0
- {kwebsocket-1.2 → kwebsocket-1.3}/setup.cfg +0 -0
- {kwebsocket-1.2 → kwebsocket-1.3}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.2
|
|
2
2
|
Name: kwebsocket
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3
|
|
4
4
|
Summary: kwebsocket
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: 百里
|
|
@@ -9,5 +9,5 @@ Maintainer: 坤坤
|
|
|
9
9
|
Maintainer-email: fk1402936534@qq.com
|
|
10
10
|
License: MIT License
|
|
11
11
|
Description: UNKNOWN
|
|
12
|
-
Keywords: kwebsocket1.
|
|
12
|
+
Keywords: kwebsocket1.3
|
|
13
13
|
Platform: UNKNOWN
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
import time,threading
|
|
3
3
|
def kwebsocket_print_log(*strs):
|
|
4
4
|
print(time.strftime("%Y-%m-%d %H:%M:%S"),*strs)
|
|
5
|
+
def kwebsocket_json_encode(strs):
|
|
6
|
+
"""python列表或字典转成字符串"""
|
|
7
|
+
import json
|
|
8
|
+
try:
|
|
9
|
+
return json.dumps(strs,ensure_ascii=False)
|
|
10
|
+
except Exception:
|
|
11
|
+
return ""
|
|
5
12
|
class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
6
13
|
wsobj=None
|
|
7
14
|
__config={
|
|
@@ -22,17 +29,12 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
22
29
|
try:
|
|
23
30
|
self.wsobj.connect(self.__config['url'])
|
|
24
31
|
except websocket._exceptions.WebSocketBadStatusException:
|
|
25
|
-
|
|
26
|
-
except:pass
|
|
27
|
-
self.wsobj=None
|
|
32
|
+
self.close()
|
|
28
33
|
if i>=self.__config['break']:
|
|
29
34
|
self.__close_th_lock()
|
|
30
35
|
raise Exception('连接已中止,请重新连接')
|
|
31
|
-
time.sleep(0.1)
|
|
32
36
|
except:
|
|
33
|
-
|
|
34
|
-
except:pass
|
|
35
|
-
self.wsobj=None
|
|
37
|
+
self.close()
|
|
36
38
|
self.__close_th_lock()
|
|
37
39
|
raise
|
|
38
40
|
else:
|
|
@@ -57,11 +59,13 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
57
59
|
try:self.wsobj.close()
|
|
58
60
|
except:pass
|
|
59
61
|
self.wsobj=None
|
|
60
|
-
def connect(self,url,th_lock=False):
|
|
62
|
+
def connect(self,url,breaks=5,th_lock=False):
|
|
61
63
|
"""设置连接
|
|
62
64
|
|
|
63
65
|
url 连接地址 如 wss://websocket.kwebapp.cn/?unionid=1&token=1232
|
|
64
66
|
|
|
67
|
+
breaks #断线重连次数,0表示不重连
|
|
68
|
+
|
|
65
69
|
th_lock 是否开启线程锁 多线程中建议开启 注意 这个python多线程锁 而不是redis库事务锁 也可以在配置信息中全局开启
|
|
66
70
|
|
|
67
71
|
"""
|
|
@@ -70,9 +74,15 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
70
74
|
if self.__config['th_lock']:
|
|
71
75
|
self.__start_th_lock()
|
|
72
76
|
self.__config['url']=url
|
|
77
|
+
self.__config['break']=breaks
|
|
73
78
|
return self
|
|
74
79
|
|
|
75
80
|
def send(self,text):
|
|
81
|
+
"""发送信息
|
|
82
|
+
|
|
83
|
+
text 要推送的数据 字符串格式
|
|
84
|
+
|
|
85
|
+
"""
|
|
76
86
|
for i in range(100):
|
|
77
87
|
self.__connect()
|
|
78
88
|
try:
|
|
@@ -96,6 +106,37 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
96
106
|
else:
|
|
97
107
|
self.__close_th_lock()
|
|
98
108
|
break
|
|
109
|
+
def send_arr(self,data,types,admintoken,GroupName='',client_id='',unionid=''):
|
|
110
|
+
"""发送信息
|
|
111
|
+
|
|
112
|
+
data 要推送的数据 支持字典
|
|
113
|
+
|
|
114
|
+
types 类型 sendToAll(给所有在线发送信息) sendToGroup(给指定组发送信息) sendToClient(给指定客户端发送信息) sendToUid(给指定客户端发送信息)
|
|
115
|
+
|
|
116
|
+
admintoken 管理员连接token
|
|
117
|
+
|
|
118
|
+
GroupName 组名 types=sendToGroup时必填
|
|
119
|
+
|
|
120
|
+
client_id 客户端id types=sendToClient时必填
|
|
121
|
+
|
|
122
|
+
unionid 用户id types=sendToUid时必填
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
con={'type':types,'admintoken':admintoken}
|
|
126
|
+
if types=='sendToGroup':
|
|
127
|
+
if not GroupName:
|
|
128
|
+
raise Exception('GroupName not null')
|
|
129
|
+
con['GroupName']=GroupName
|
|
130
|
+
elif types=='sendToClient':
|
|
131
|
+
if not client_id:
|
|
132
|
+
raise Exception('client_id not null')
|
|
133
|
+
con['client_id']=client_id
|
|
134
|
+
elif types=='sendToUid':
|
|
135
|
+
if not unionid:
|
|
136
|
+
raise Exception('unionid not null')
|
|
137
|
+
con['unionid']=unionid
|
|
138
|
+
con['data']=data
|
|
139
|
+
self.send(kwebsocket_json_encode(con))
|
|
99
140
|
def recv(self):
|
|
100
141
|
"""接收数据"""
|
|
101
142
|
for i in range(100):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.2
|
|
2
2
|
Name: kwebsocket
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3
|
|
4
4
|
Summary: kwebsocket
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: 百里
|
|
@@ -9,5 +9,5 @@ Maintainer: 坤坤
|
|
|
9
9
|
Maintainer-email: fk1402936534@qq.com
|
|
10
10
|
License: MIT License
|
|
11
11
|
Description: UNKNOWN
|
|
12
|
-
Keywords: kwebsocket1.
|
|
12
|
+
Keywords: kwebsocket1.3
|
|
13
13
|
Platform: UNKNOWN
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|