feat: 更新配置并优化消息发送逻辑

- 修改配置中的接收者名称和发送时间
- 在scheduler.py中添加周末不执行任务的逻辑
- 在sendmsg.py中支持多种图片格式并延长重试间隔
This commit is contained in:
Your Name 2025-08-18 16:58:14 +08:00
parent aaf5f59b59
commit 33aca60f56
3 changed files with 33 additions and 13 deletions

View File

@ -3,8 +3,8 @@ CONFIG = {
"app_secret": "mcK8aTiq0CLtkzGs2aTZpcnom5J4o6yB",
"open_id": ["ou_c6466a45623096cf7a34d94fe30c6c73", "ou_3b94d0caf83dbced8b0e26af4852a281"],
"file_path": "F:\\",
"messages_reciever": "文件传输助手",
"checking_time": "15:24",
"sending_time": "15:26",
"messages_reciever": "宝库学堂AI全能增长官特训营 2期",
"checking_time": "16:55",
"sending_time": "16:56",
"message": "新的一天从华智长盈每日AI新闻开始让我们一起看看今天AI圈有啥新鲜事"
}

View File

@ -4,10 +4,19 @@ import subprocess
import sys
import os
from datetime import datetime
import calendar
from config import CONFIG
def run_sendmsg():
"""执行sendmsg.py脚本"""
"""执行sendmsg.py脚本周末不执行"""
# 获取当前日期是星期几0是星期一6是星期日
current_weekday = datetime.now().weekday()
# 如果是周末(周六或周日),不执行任务
if current_weekday >= 5: # 5是周六6是周日
print(f"[{datetime.now()}] 今天是周末,不执行任务")
return
script_path = os.path.join(os.path.dirname(__file__), 'sendmsg.py')
try:
print(f"[{datetime.now()}] 开始执行每日消息发送任务...")
@ -22,7 +31,6 @@ def run_sendmsg():
def main():
"""主函数 - 设置定时任务"""
# 每天07:55执行任务
schedule.every().day.at(CONFIG['checking_time']).do(run_sendmsg)
print(f"[{datetime.now()}] 定时任务已启动将在每天07:55执行sendmsg.py")

View File

@ -32,8 +32,13 @@ def send_daily_message(count):
"""发送每日消息的主函数"""
today = date.today()
formatted_date = today.strftime('%Y-%m-%d')
file_name = formatted_date + ".jpg"
file_path = CONFIG['file_path'] + file_name
# 支持多种图片格式jpg, jpeg, png
file_formats = [".jpg", ".jpeg", ".png"]
# 初始化文件路径变量
file_path = None
num = count
if num >= 4:
print("已尝试4次程序将退出")
@ -44,7 +49,7 @@ def send_daily_message(count):
except:
subprocess.run([sys.executable, 'send_openmsg.py'])
if num<4:
time.sleep(60)
time.sleep(1800)
num += 1
send_daily_message(num)
else:
@ -54,9 +59,16 @@ def send_daily_message(count):
msg = CONFIG['message']
who = CONFIG['messages_reciever']
if os.path.isfile(file_path):
print("找到了指定文件!")
# 依次检查各种格式的文件是否存在
for format in file_formats:
temp_file_name = formatted_date + format
temp_file_path = CONFIG['file_path'] + temp_file_name
if os.path.isfile(temp_file_path):
file_path = temp_file_path
print(f"找到了{format}格式的图片文件!")
break
if file_path:
# 等待到配置的时间再执行发送操作
wait_until_time()
@ -66,10 +78,10 @@ def send_daily_message(count):
print("发送完成!")
return True
else:
print("没找到指定文件")
print("没找到任何支持格式的图片文件(.jpg, .jpeg, .png)")
subprocess.run([sys.executable, 'send_filemsg.py'])
if num<4:
time.sleep(60)
time.sleep(1800)
num += 1
send_daily_message(num)
else: