Compare commits

..

No commits in common. "546ca9dfe2d8e13a233b2d36bcfc344ac7fce978" and "96e67e8b045e6fb40339d17119b613497448339b" have entirely different histories.

5 changed files with 36 additions and 103 deletions

View File

@ -2,6 +2,5 @@ CONFIG = {
"app_id": "cli_a8de57f7e95f100c",
"app_secret": "jm2nkFnnSNVS3n076VOPfh8k7q0hEKVp",
"open_id": "ou_bd33a5f75dd2ccb005a21e4dd01f930c",
"file_path": "C:\\Users\\22251\\OneDrive\\桌面\\picture\\",
"messages_reciever": "File Transfer"
"file_path": "C:\\Users\\22251\\OneDrive\\桌面\\picture\\"
}

View File

@ -3,36 +3,17 @@ import time
import subprocess
import sys
import os
from datetime import datetime
def run_sendmsg():
"""执行sendmsg.py脚本"""
script_path = os.path.join(os.path.dirname(__file__), 'sendmsg.py')
try:
print(f"[{datetime.now()}] 开始执行每日消息发送任务...")
result = subprocess.run([sys.executable, script_path],
capture_output=True, text=True, cwd=os.path.dirname(__file__))
if result.returncode == 0:
print(f"[{datetime.now()}] 任务执行成功")
else:
print(f"[{datetime.now()}] 任务执行失败: {result.stderr}")
except Exception as e:
print(f"[{datetime.now()}] 执行出错: {str(e)}")
subprocess.run([sys.executable, script_path])
def main():
"""主函数 - 设置定时任务"""
# 每天17:30执行任务
schedule.every().day.at("17:40").do(run_sendmsg)
# 设置每天12点运行
schedule.every().day.at("12:00").do(run_sendmsg)
print(f"[{datetime.now()}] 定时任务已启动将在每天17:30执行sendmsg.py")
print("按Ctrl+C停止程序")
print("定时任务已启动将在每天12:00运行sendmsg.py")
try:
# 保持程序运行
while True:
schedule.run_pending()
time.sleep(60) # 每分钟检查一次
except KeyboardInterrupt:
print(f"\n[{datetime.now()}] 定时任务已停止")
if __name__ == "__main__":
main()
time.sleep(1)

View File

@ -7,32 +7,30 @@ import json
from config import CONFIG
import time
def send_daily_message():
"""发送每日消息的主函数"""
today = date.today()
formatted_date = today.strftime('%Y-%m-%d')
file_name = formatted_date+".png"
file_path = CONFIG['file_path']+file_name
try:
wx = WeChat()
except:
#运行send_openmsg.py
subprocess.run([sys.executable, 'send_openmsg.py'])
return False
sys.exit(1)
msg = 'hello, wxauto!'
who = CONFIG['messages_reciever']
who = 'File Transfer'
if os.path.isfile(file_path):
error_msg = ""
else:
error_msg = "没找到指定文件"
#运行send_filemsg.py
subprocess.run([sys.executable, 'send_filemsg.py'])
sys.exit(1)
print("找到了指定文件!")
wx.SendFiles(filepath=file_path, who="File Transfer")
wx.SendMsg(msg=msg, who=who)
return True
else:
print("没找到指定文件")
subprocess.run([sys.executable, 'send_filemsg.py'])
return False
# 如果直接运行此脚本,执行发送消息功能
if __name__ == "__main__":
send_daily_message()

View File

@ -1,20 +0,0 @@
import subprocess
import sys
import os
from pathlib import Path
def run_in_background():
"""在后台运行定时任务"""
script_path = Path(__file__).parent / "scheduler.py"
# 使用pythonw.exe在后台运行无窗口
pythonw_path = sys.executable.replace('python.exe', 'pythonw.exe')
subprocess.Popen([pythonw_path, str(script_path)],
cwd=str(Path(__file__).parent),
creationflags=subprocess.CREATE_NO_WINDOW)
print("定时任务已在后台启动")
if __name__ == "__main__":
run_in_background()

View File

@ -1,25 +0,0 @@
import subprocess
import sys
import os
def stop_scheduler():
"""停止定时任务进程"""
try:
# 查找并结束scheduler.py进程
result = subprocess.run(['tasklist', '/FI', 'IMAGENAME eq pythonw.exe', '/FO', 'CSV'],
capture_output=True, text=True)
if 'scheduler.py' in result.stdout:
# 结束包含scheduler.py的pythonw进程
subprocess.run(['taskkill', '/F', '/IM', 'pythonw.exe'], check=True)
print("定时任务已停止")
else:
print("未找到运行中的定时任务")
except subprocess.CalledProcessError as e:
print(f"停止进程时出错: {e}")
except Exception as e:
print(f"发生错误: {e}")
if __name__ == "__main__":
stop_scheduler()