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