From 699bac8008aecdef6ecb8d9d7ceb55a5aee19752 Mon Sep 17 00:00:00 2001 From: teddy Date: Tue, 24 Jun 2025 14:50:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=B6=E9=97=B4=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=A4=84=E7=90=86=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将定时任务时间从12:00改为14:39 - 新增start_scheduler.bat脚本用于管理进程 - 在config.py中添加messages_reciever配置项 - 优化sendmsg.py代码结构,使用配置项代替硬编码 --- config.py | 3 ++- scheduler.py | 2 +- sendmsg.py | 5 ++--- start_scheduler.bat | 9 +++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 start_scheduler.bat diff --git a/config.py b/config.py index 9e7357e..d375548 100644 --- a/config.py +++ b/config.py @@ -2,5 +2,6 @@ CONFIG = { "app_id": "cli_a8de57f7e95f100c", "app_secret": "jm2nkFnnSNVS3n076VOPfh8k7q0hEKVp", "open_id": "ou_bd33a5f75dd2ccb005a21e4dd01f930c", - "file_path": "C:\\Users\\22251\\OneDrive\\桌面\\picture\\" + "file_path": "C:\\Users\\22251\\OneDrive\\桌面\\picture\\", + "messages_reciever": "File Transfer" } \ No newline at end of file diff --git a/scheduler.py b/scheduler.py index 19e66cb..c9c2c1f 100644 --- a/scheduler.py +++ b/scheduler.py @@ -9,7 +9,7 @@ def run_sendmsg(): subprocess.run([sys.executable, script_path]) # 设置每天12点运行 -schedule.every().day.at("12:00").do(run_sendmsg) +schedule.every().day.at("14:39").do(run_sendmsg) print("定时任务已启动,将在每天12:00运行sendmsg.py") diff --git a/sendmsg.py b/sendmsg.py index 50b7ece..97f7841 100644 --- a/sendmsg.py +++ b/sendmsg.py @@ -6,6 +6,7 @@ import subprocess import json from config import CONFIG import time +from config import CONFIG today = date.today() @@ -15,19 +16,17 @@ file_path = CONFIG['file_path']+file_name try: wx = WeChat() except: - #运行send_openmsg.py subprocess.run([sys.executable, 'send_openmsg.py']) sys.exit(1) msg = 'hello, wxauto!' -who = 'File Transfer' +who = CONFIG['messages_reciever'] if os.path.isfile(file_path): error_msg = "" else: error_msg = "没找到指定文件" - #运行send_filemsg.py subprocess.run([sys.executable, 'send_filemsg.py']) sys.exit(1) diff --git a/start_scheduler.bat b/start_scheduler.bat new file mode 100644 index 0000000..c42c738 --- /dev/null +++ b/start_scheduler.bat @@ -0,0 +1,9 @@ +@echo off +:: 查找并停止所有运行 scheduler.py 的 pythonw 进程 +for /f "tokens=2" %%a in ('tasklist /fi "imagename eq pythonw.exe" /v ^| findstr "scheduler.py"') do taskkill /F /PID %%a + +:: 等待1秒确保进程完全停止 +timeout /t 1 /nobreak > nul + +:: 启动新的进程 +start /min pythonw "%~dp0scheduler.py" \ No newline at end of file