Merge branch 'master' of https://git.internal.intelligrow.cn/intelligrow/Send_picture_automatically
This commit is contained in:
commit
462fed6336
@ -2,9 +2,9 @@ CONFIG = {
|
||||
"app_id": "cli_a8d64a7be63a500e",
|
||||
"app_secret": "mcK8aTiq0CLtkzGs2aTZpcnom5J4o6yB",
|
||||
"open_id": ["ou_c6466a45623096cf7a34d94fe30c6c73", "ou_3b94d0caf83dbced8b0e26af4852a281"],
|
||||
"file_path": "Z:\\",
|
||||
"messages_reciever": "文件传输助手",
|
||||
"checking_time": "15:19",
|
||||
"sending_time": "15:20",
|
||||
"file_path": "F:\\",
|
||||
"messages_reciever": "宝库学堂:AI全能增长官特训营 1期",
|
||||
"checking_time": "07:55",
|
||||
"sending_time": "10:00",
|
||||
"message": "新的一天,从华智长盈每日AI新闻开始!让我们一起看看今天AI圈有啥新鲜事!"
|
||||
}
|
||||
11
scheduler.py
11
scheduler.py
@ -4,6 +4,7 @@ import subprocess
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime
|
||||
import calendar
|
||||
from config import CONFIG
|
||||
from logger_config import setup_logger
|
||||
|
||||
@ -11,7 +12,15 @@ from logger_config import setup_logger
|
||||
logger = setup_logger('scheduler')
|
||||
|
||||
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')
|
||||
logger.info("=" * 50)
|
||||
logger.info("开始执行每日消息发送任务...")
|
||||
|
||||
19
sendmsg.py
19
sendmsg.py
@ -39,6 +39,13 @@ def send_daily_message(count):
|
||||
|
||||
today = date.today()
|
||||
formatted_date = today.strftime('%Y-%m-%d')
|
||||
|
||||
# 支持多种图片格式:jpg, jpeg, png
|
||||
file_formats = [".jpg", ".jpeg", ".png"]
|
||||
|
||||
# 初始化文件路径变量
|
||||
file_path = None
|
||||
|
||||
file_name = formatted_date + ".jpg"
|
||||
file_path = CONFIG['file_path'] + file_name
|
||||
|
||||
@ -74,6 +81,16 @@ def send_daily_message(count):
|
||||
logger.info(f"消息内容: {msg}")
|
||||
logger.info(f"接收者: {who}")
|
||||
|
||||
# 依次检查各种格式的文件是否存在
|
||||
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:
|
||||
if os.path.isfile(file_path):
|
||||
logger.info("找到了指定文件!")
|
||||
logger.info(f"文件大小: {os.path.getsize(file_path)} 字节")
|
||||
@ -110,10 +127,12 @@ def send_daily_message(count):
|
||||
logger.error("已尝试4次,程序将退出")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("没找到任何支持格式的图片文件(.jpg, .jpeg, .png)")
|
||||
logger.warning(f"没找到指定文件: {file_path}")
|
||||
logger.info("尝试发送飞书提醒消息...")
|
||||
subprocess.run([sys.executable, 'send_filemsg.py'])
|
||||
if num<4:
|
||||
time.sleep(1800)
|
||||
logger.info(f"等待60秒后重试,当前尝试次数: {num+1}")
|
||||
time.sleep(60)
|
||||
num += 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user