From 0f8e0dd8fa14b5e28e86424ed7290d1df477d92c Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Tue, 23 Jan 2024 18:33:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E5=A4=84=E7=90=86=E7=B2=98=E5=8C=85=20debug?= =?UTF-8?q?=E5=8F=8Atrlog=E9=87=87=E7=94=A8=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=BD=92=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- s2f.py | 17 +++++++++--- server.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/s2f.py b/s2f.py index 66181d0..bcf8552 100644 --- a/s2f.py +++ b/s2f.py @@ -1,8 +1,19 @@ import datetime +import os +def gettm(): + t= datetime.datetime.now() + d = str(t) + return d,d[:10] + def save2file(data,isR=1): # pass - t= datetime.datetime.now() - l=f"{'[R]' if isR else '[T]'} - {str(t)} --- {data.hex(' ')}\n" - f=open('./rxlog.txt','a') + t,d = gettm() + + p = '/'.join(['trlog',d]) + if not os.path.exists(p): + os.makedirs(p) + + l=f"{'[R]' if isR else '[T]'} - {t} --- {data.hex(' ')}\n" + f=open('/'.join(['trlog',d,'trlog.txt']),'a') f.write(l) f.close \ No newline at end of file diff --git a/server.py b/server.py index b1b0ec9..c33c140 100755 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ import socket from threading import Timer import s2f from loguru import logger +import os SERVER = "http://www.pushplus.plus/send" TOKEN = "ff328cba923a4225bc4acd0086a9014c" @@ -284,6 +285,7 @@ def tt_hh(addr, data): msg[-1] = crc add_timestamp() addr.send(msg) + s2f.save2file(msg,0) logger.debug("服务器回复心跳包。") # 从缓存中匹配到数据才重发 @@ -298,6 +300,7 @@ def tt_hh(addr, data): add_timestamp() # 按缓存先后顺序发送 addr.send(msgs[i]) + s2f.save2file(msg) time.sleep(1) # 成功则清空已发送成功的缓存数据 cache[ccid].pop(0) @@ -392,16 +395,61 @@ def tt_trans(addr, data): s2wx("","",f"发送失败,终端{taddr}可能已掉线。 \n数据已缓存,待目标终端上线后重发。") return 0 +def isInlst(tar,lst): + """ + 在列表中查找目标子列表 -def data_split(data): + 返回匹配的列表 + """ + index = [] + for x in range(len(lst)): + if lst[x:x+len(tar)] == tar : + index.append(x) + + rst = [] + for x in range(len(index)): + if x