s2wx加锁

This commit is contained in:
murmur 2023-03-23 15:56:02 +08:00
parent c7e679cbb1
commit 7cca86c86a
2 changed files with 11 additions and 3 deletions

3
s2f.py Normal file
View File

@ -0,0 +1,3 @@
def save2file(data):
pass

View File

@ -10,6 +10,7 @@ import requests
import socket import socket
# import json # import json
from threading import Timer from threading import Timer
import s2f
SERVER = "http://www.pushplus.plus/send" SERVER = "http://www.pushplus.plus/send"
TOKEN = "ff328cba923a4225bc4acd0086a9014c" TOKEN = "ff328cba923a4225bc4acd0086a9014c"
@ -32,7 +33,7 @@ def pp2wx(title,content,description):
requests.post(SERVER, json=ppmsg) requests.post(SERVER, json=ppmsg)
msgcache=[] msgcache=[]
pushisbusy=0
def s2wx(title="",description="", content=""): def s2wx(title="",description="", content=""):
"""通过自建msgpusher发送至微信 """通过自建msgpusher发送至微信
当前title值无效 当前title值无效
@ -40,6 +41,9 @@ def s2wx(title="",description="", content=""):
# return # return
# 受API限制频繁发送会失败 # 受API限制频繁发送会失败
# 拟合并发送满3条已发送超时时间10s # 拟合并发送满3条已发送超时时间10s
if pushisbusy:
return
pushisbusy=1
if len(content): if len(content):
t=f""" t=f"""
*时戳* *时戳*
@ -67,7 +71,7 @@ _{datetime.datetime.now()}_
send() send()
msgcache.clear() msgcache.clear()
t= Timer(10,s2wx).start() t= Timer(10,s2wx).start()
pushisbusy=0
# GET 方式 # GET 方式
# res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}" # res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}"
# f"&description={description}&content={content}&token={TOKEN}") # f"&description={description}&content={content}&token={TOKEN}")
@ -92,7 +96,7 @@ _{datetime.datetime.now()}_
# return None # return None
# else: # else:
# return res["message"] # return res["message"]
t=Timer(10,s2wx).start() # t=Timer(10,s2wx).start()
cache = defaultdict(list) cache = defaultdict(list)
offs = 0 # 偏移量 offs = 0 # 偏移量
@ -392,6 +396,7 @@ class MyServer(socketserver.BaseRequestHandler):
if not data: if not data:
break break
add_timestamp() add_timestamp()
s2f.save2file(data)
t = f"接收到新数据,长度{len(data)}字节。" t = f"接收到新数据,长度{len(data)}字节。"
print(t) print(t)
s2wx("","",t) s2wx("","",t)