增加push消息合并功能,默认3条一发,超时10s
This commit is contained in:
parent
f2ab3012df
commit
c7e679cbb1
79
server.py
79
server.py
@ -9,7 +9,7 @@ import time
|
||||
import requests
|
||||
import socket
|
||||
# import json
|
||||
|
||||
from threading import Timer
|
||||
|
||||
SERVER = "http://www.pushplus.plus/send"
|
||||
TOKEN = "ff328cba923a4225bc4acd0086a9014c"
|
||||
@ -31,36 +31,68 @@ def pp2wx(title,content,description):
|
||||
# ppmsg["description"]= content
|
||||
requests.post(SERVER, json=ppmsg)
|
||||
|
||||
def s2wx(title,description, content):
|
||||
msgcache=[]
|
||||
|
||||
def s2wx(title="",description="", content=""):
|
||||
"""通过自建msgpusher发送至微信
|
||||
当前title值无效
|
||||
"""
|
||||
# return
|
||||
# 受API限制,频繁发送会失败
|
||||
# 拟合并发送,满3条已发送,超时时间10s
|
||||
if len(content):
|
||||
t=f"""
|
||||
*时戳:*
|
||||
_{datetime.datetime.now()}_
|
||||
*信息:*
|
||||
{content}"""
|
||||
msgcache.append(t)
|
||||
|
||||
def send():
|
||||
c= " \n".join(msgcache[:3])
|
||||
requests.post("http://push.nmhd.eu.org:12722/push/murmur", json={
|
||||
"title": title,
|
||||
"description": description,
|
||||
"content": c,
|
||||
"token": "tt"})
|
||||
|
||||
if len(msgcache) >3:
|
||||
send()
|
||||
msgcache.pop(0)
|
||||
msgcache.pop(0)
|
||||
msgcache.pop(0)
|
||||
t= Timer(10,s2wx).start()
|
||||
elif (not len(content)) and len(msgcache):
|
||||
# 等效超时
|
||||
send()
|
||||
msgcache.clear()
|
||||
t= Timer(10,s2wx).start()
|
||||
|
||||
# GET 方式
|
||||
# res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}"
|
||||
# f"&description={description}&content={content}&token={TOKEN}")
|
||||
|
||||
# POST 方式
|
||||
res = requests.post("http://push.nmhd.eu.org:12722/push/murmur", json={
|
||||
"title": title,
|
||||
"description": description,
|
||||
"content": f"""
|
||||
*时戳:*
|
||||
_{datetime.datetime.now()}_
|
||||
*信息:*
|
||||
{content}""",
|
||||
"token": "tt"
|
||||
})
|
||||
try:
|
||||
res = res.json()
|
||||
except:
|
||||
return
|
||||
else:
|
||||
if res["success"]:
|
||||
return None
|
||||
else:
|
||||
return res["message"]
|
||||
|
||||
# res = requests.post("http://push.nmhd.eu.org:12722/push/murmur", json={
|
||||
# "title": title,
|
||||
# "description": description,
|
||||
# "content": f"""
|
||||
# *时戳:*
|
||||
# _{datetime.datetime.now()}_
|
||||
# *信息:*
|
||||
# {content}""",
|
||||
# "token": "tt"
|
||||
# })
|
||||
# try:
|
||||
# res = res.json()
|
||||
# except:
|
||||
# return
|
||||
# else:
|
||||
# if res["success"]:
|
||||
# return None
|
||||
# else:
|
||||
# return res["message"]
|
||||
t=Timer(10,s2wx).start()
|
||||
|
||||
cache = defaultdict(list)
|
||||
offs = 0 # 偏移量
|
||||
@ -113,8 +145,7 @@ def update_pairs(addr, ccid, clear=0):
|
||||
t = f"""*信息:*
|
||||
天通终端上线。
|
||||
CCID:{ccid.decode()}
|
||||
地址:{str(addr.getpeername())}
|
||||
"""
|
||||
地址:{str(addr.getpeername())}"""
|
||||
print(t)
|
||||
s2wx("","天通终端上线",t)
|
||||
# p[ccid] = addr
|
||||
|
Loading…
Reference in New Issue
Block a user