From bad0091f0df420813adeff93f001fc66af3b49dd Mon Sep 17 00:00:00 2001 From: yshtcn Date: Wed, 6 Sep 2023 23:49:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?-=20=E4=BF=AE=E7=90=86=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=A4=84=E7=90=86UTF-8=E5=AD=97=E7=AC=A6=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ServerChanPush2TelegramBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServerChanPush2TelegramBot.py b/ServerChanPush2TelegramBot.py index 4fb231d..142154a 100644 --- a/ServerChanPush2TelegramBot.py +++ b/ServerChanPush2TelegramBot.py @@ -11,7 +11,7 @@ from logging.handlers import TimedRotatingFileHandler current_date = datetime.now().strftime("%Y-%m-%d") # 创建一个处理器,该处理器每天午夜都会创建一个新的日志文件 -handler = TimedRotatingFileHandler(f"received_requests_{current_date}.log", when="midnight", interval=1, backupCount=10) +handler = TimedRotatingFileHandler(f"received_requests_{current_date}.log", when="midnight", interval=1, backupCount=10, encoding='utf-8') handler.suffix = "%Y-%m-%d" # 配置日志 From a48f0c8ff93c1fa698b2c82a83c3551e6895a1fb Mon Sep 17 00:00:00 2001 From: yshtcn Date: Fri, 8 Sep 2023 12:44:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?-=20=E4=BF=AE=E6=94=B9=E5=9B=9Ehtml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ServerChanPush2TelegramBot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ServerChanPush2TelegramBot.py b/ServerChanPush2TelegramBot.py index 7a81a93..88acce4 100644 --- a/ServerChanPush2TelegramBot.py +++ b/ServerChanPush2TelegramBot.py @@ -131,7 +131,7 @@ def send_telegram_message(bot_id, chat_id, title, desp=None, url=None): text = text.replace(affected_url, corrected_url) if url: # 如果有 url,添加到 text - text += f"\n\n[详情]({url})" + text += f"\n\n详情:" text += f"{url}" # 直接添加 URL,Telegram 会自动处理预览 text=unescape_url(text) @@ -140,17 +140,17 @@ def send_telegram_message(bot_id, chat_id, title, desp=None, url=None): payload = { 'chat_id': chat_id, 'text': text, - 'parse_mode': 'markdown', + 'parse_mode': 'HTML', 'disable_web_page_preview': False # 启用网页预览 } try: response = requests.post(api_url, data=payload, proxies=proxies, timeout=2) + logging.info(f"response: {response.text}") if response.status_code == 200 and response.json().get("ok"): # 保存发送的请求数据 converted_sent_data = convert_str_gbk_to_utf8(str(payload)) save_sent_data(api_url,converted_sent_data) return True, response.json() - else: return False, response.json() except requests.RequestException as e: From 69cba3a03b4aa41564cd203a7ceeecf53ec530ea Mon Sep 17 00:00:00 2001 From: yshtcn Date: Fri, 8 Sep 2023 12:56:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?-=20=E5=BE=AE=E8=B0=83=EF=BC=9A=E6=8A=8A?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=B0=BE=E9=83=A8=E5=A4=9A=E4=BD=99=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=E5=92=8C=E6=8D=A2=E8=A1=8C=E5=8E=BB=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ServerChanPush2TelegramBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServerChanPush2TelegramBot.py b/ServerChanPush2TelegramBot.py index 88acce4..5419823 100644 --- a/ServerChanPush2TelegramBot.py +++ b/ServerChanPush2TelegramBot.py @@ -119,7 +119,7 @@ def send_telegram_message(bot_id, chat_id, title, desp=None, url=None): text = title # 初始化 text 为 title text += f"\n\n{(desp.split(delimiter)[0] if delimiter and desp else desp) if desp else ''}" - + text =text.rstrip() # 使用正则表达式来识别受影响的链接