From c7e679cbb12f871879e15335fe54f4c6a26dca83 Mon Sep 17 00:00:00 2001 From: murmur Date: Thu, 23 Mar 2023 14:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0push=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?3=E6=9D=A1=E4=B8=80=E5=8F=91=EF=BC=8C=E8=B6=85=E6=97=B610s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 79 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/server.py b/server.py index 0f5c321..4c99263 100755 --- a/server.py +++ b/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