- 删除start_scheduler.bat脚本,改为直接运行scheduler.py - 重构scheduler.py,添加日志记录和主函数封装 - 重构sendmsg.py,将逻辑封装到函数中并添加返回值 - 调整定时任务执行时间为每天17:30
39 lines
1011 B
Python
39 lines
1011 B
Python
from wxauto import WeChat
|
|
from datetime import date
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
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:
|
|
subprocess.run([sys.executable, 'send_openmsg.py'])
|
|
return False
|
|
|
|
msg = 'hello, wxauto!'
|
|
who = CONFIG['messages_reciever']
|
|
|
|
if os.path.isfile(file_path):
|
|
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()
|