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