修改了分发方式,不再使用压缩包。正文中渲染了文章
This commit is contained in:
parent
abc7c8fd2b
commit
90397ee4db
@ -404,7 +404,6 @@ def send_emails(distribution_csv, output_dir, email_from, email_password,
|
||||
try:
|
||||
# 确保输出目录存在
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
os.makedirs(os.path.join(output_dir, "temp_zips"), exist_ok=True)
|
||||
|
||||
# 读取分发CSV
|
||||
df = pd.read_csv(distribution_csv)
|
||||
@ -432,9 +431,6 @@ def send_emails(distribution_csv, output_dir, email_from, email_password,
|
||||
"details": []
|
||||
}
|
||||
|
||||
# 临时ZIP文件列表
|
||||
temp_zips = []
|
||||
|
||||
# 发送邮件
|
||||
for email, rows in email_groups.items():
|
||||
try:
|
||||
@ -442,12 +438,24 @@ def send_emails(distribution_csv, output_dir, email_from, email_password,
|
||||
|
||||
# 收集所有文件路径
|
||||
files = []
|
||||
article_contents = []
|
||||
|
||||
for row in rows:
|
||||
# 收集文本文件
|
||||
# 收集文本文件并读取内容
|
||||
file_path = row.get('file_path')
|
||||
if file_path and not pd.isna(file_path) and os.path.exists(file_path):
|
||||
files.append(file_path)
|
||||
|
||||
# 读取文章内容
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
article_content = f.read()
|
||||
product_name = row.get('product', '')
|
||||
object_name = row.get('object', '')
|
||||
article_contents.append(f"【{product_name} - {object_name}】\n\n{article_content}\n\n{'='*50}\n\n")
|
||||
except Exception as e:
|
||||
logger.warning(f"读取文章内容失败: {file_path}, 错误: {e}")
|
||||
|
||||
# 收集海报图片
|
||||
poster_path = row.get('poster_path')
|
||||
if poster_path and not pd.isna(poster_path) and os.path.exists(poster_path):
|
||||
@ -472,40 +480,26 @@ def send_emails(distribution_csv, output_dir, email_from, email_password,
|
||||
results["failed"] += 1
|
||||
continue
|
||||
|
||||
# 创建ZIP文件
|
||||
if zip_filename:
|
||||
# 使用指定的文件名
|
||||
zip_filename_with_ext = f"{zip_filename}.zip"
|
||||
else:
|
||||
# 使用默认的时间戳文件名
|
||||
zip_filename_with_ext = f"content_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{hash(email) % 10000}.zip"
|
||||
|
||||
zip_path = os.path.join(output_dir, "temp_zips", zip_filename_with_ext)
|
||||
|
||||
zip_file = create_zip_file(files, zip_path)
|
||||
if zip_file:
|
||||
temp_zips.append(zip_file)
|
||||
else:
|
||||
logger.error(f"为邮箱 {email} 创建ZIP文件失败,跳过")
|
||||
results["details"].append({
|
||||
"user_id": rows[0]['user_id'],
|
||||
"email": email,
|
||||
"status": "failed",
|
||||
"reason": "创建ZIP文件失败",
|
||||
"files": files
|
||||
})
|
||||
results["failed"] += 1
|
||||
continue
|
||||
|
||||
# 构建邮件内容
|
||||
files_count = len(files)
|
||||
entries_count = len(rows)
|
||||
|
||||
email_content = f"""您好!请查收今日带货笔记(文案+配图),内容在文件压缩包内。具体挂载商品等操作流程请查看对应达人微信群内信息。
|
||||
# 基本邮件内容
|
||||
base_email_content = f"""
|
||||
您好!请查收今日带货笔记(文案+配图),内容在邮件正文和附件中。具体挂载商品等操作流程请查看对应达人微信群内信息。
|
||||
|
||||
优化建议:
|
||||
①所有提供的材料仅为参考,支持自行修改
|
||||
②标题优化和格式的规整更有利于带来小眼睛
|
||||
③本测试提供的商品均为近期高佣金筛选后的优质商单,质量保证
|
||||
|
||||
===== 文章内容 =====
|
||||
|
||||
共包含{entries_count}篇文章内容,请按照要求发布。
|
||||
"""
|
||||
|
||||
# 添加文章内容
|
||||
full_email_content = base_email_content + '\n'.join(article_contents)
|
||||
|
||||
# 发送邮件
|
||||
if test_mode:
|
||||
logger.info(f"测试模式: 模拟发送邮件到 {email}")
|
||||
@ -528,8 +522,8 @@ def send_emails(distribution_csv, output_dir, email_from, email_password,
|
||||
email_password,
|
||||
target_email,
|
||||
subject,
|
||||
email_content,
|
||||
[zip_file],
|
||||
full_email_content,
|
||||
files, # 直接传递所有文件作为附件
|
||||
smtp_server,
|
||||
smtp_port,
|
||||
use_ssl
|
||||
@ -574,17 +568,6 @@ def send_emails(distribution_csv, output_dir, email_from, email_password,
|
||||
logger.info(f"成功: {results['success']} 个邮箱")
|
||||
logger.info(f"失败: {results['failed']} 个邮箱")
|
||||
|
||||
# 清理临时文件
|
||||
if not test_mode:
|
||||
logger.info("清理临时ZIP文件...")
|
||||
for temp_zip in temp_zips:
|
||||
try:
|
||||
if os.path.exists(temp_zip):
|
||||
os.remove(temp_zip)
|
||||
logger.info(f"已删除临时文件: {temp_zip}")
|
||||
except Exception as e:
|
||||
logger.warning(f"删除临时文件失败: {temp_zip}, 错误: {e}")
|
||||
|
||||
# 将结果写入CSV文件
|
||||
try:
|
||||
result_df = pd.DataFrame(results["details"])
|
||||
@ -861,10 +844,13 @@ def main():
|
||||
)
|
||||
|
||||
# 记录分发结果到数据库
|
||||
if not args.test_mode:
|
||||
if not args.test_mode and not args.test_email:
|
||||
record_distribution_to_database(conn, distribution_csv, send_result_csv)
|
||||
else:
|
||||
if args.test_mode:
|
||||
logger.info("测试模式,不记录分发结果到数据库")
|
||||
if args.test_email:
|
||||
logger.info("测试邮箱模式,不记录分发结果到数据库")
|
||||
|
||||
# 生成分发报告
|
||||
generate_distribution_report(conn, distribution_csv, send_result_csv, args.output_dir)
|
||||
|
||||
@ -14,8 +14,8 @@ DB_PATH="$BASE_DIR/distribution.db"
|
||||
# 设置邮件相关变量
|
||||
EMAIL_FROM="zwysendemail@163.com"
|
||||
EMAIL_PASSWORD="NMhVGFmCJkGEy3B5"
|
||||
SUBJECT="文旅小红书带货笔记内容0513"
|
||||
ZIP_FILENAME="文旅小红书带货笔记内容0513"
|
||||
SUBJECT="文旅小红书带货笔记内容0515"
|
||||
ZIP_FILENAME="文旅小红书带货笔记内容0515"
|
||||
|
||||
# 设置分发配置
|
||||
ARTICLE_PER_USER=1
|
||||
@ -23,15 +23,15 @@ MAX_USERS=-1 # 最多发送给多少用户,不限制则设置为-1
|
||||
TEST_MODE=false # 测试模式,不实际发送邮件
|
||||
|
||||
# 测试邮箱配置(新增)
|
||||
TEST_EMAIL_MODE=false # 是否启用测试邮箱模式
|
||||
TEST_EMAIL_MODE=true # 是否启用测试邮箱模式
|
||||
TEST_EMAIL="jinye_huang@foxmail.com" # 测试邮箱地址,所有邮件都会发送到这里
|
||||
|
||||
JUDGE_ONLY=true # 只分发审核通过的内容
|
||||
UNDISTRIBUTED_ONLY=true # 只分发未分发的内容
|
||||
|
||||
# 内容筛选配置
|
||||
TARGET_PRODUCT="【奇妙萌可卡牌套票】四季梦幻亲子乐园单人票" # 为空则不筛选特定产品
|
||||
TARGET_OBJECT="" # 为空则不筛选特定景点
|
||||
TARGET_PRODUCT="" # 为空则不筛选特定产品
|
||||
TARGET_OBJECT="极爽冲浪馆" # 为空则不筛选特定景点
|
||||
|
||||
# 用户筛选配置
|
||||
TARGET_USER_ID="" # 为空则不筛选特定用户ID
|
||||
@ -50,6 +50,8 @@ echo "内容分发系统启动 (数据库全依赖版) - $(date)"
|
||||
echo "==================================================="
|
||||
echo "日志保存在: $LOG_FILE"
|
||||
echo "结果保存在: $RESULT_DIR"
|
||||
echo "注意: 本次更新不再创建ZIP压缩包,所有文件将直接作为邮件附件发送"
|
||||
echo " 同时,文章内容将添加到邮件正文中"
|
||||
|
||||
# 检查数据库是否存在
|
||||
if [ ! -f "$DB_PATH" ]; then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user