This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
@@ -0,0 +1,236 @@
#!/usr/bin/env python3
"""
测试修复效果
1. 测试ZIP包是否包含图片
2. 测试小红书内容是否去掉原文链接
"""
import os
import sys
import zipfile
import tempfile
import json
def test_zip_with_images():
"""测试ZIP包是否包含图片"""
print("📦 测试ZIP包图片修复...")
try:
sys.path.append("/home/ubuntu/nanocode/it_automation_enhanced/scripts")
from email_with_attachments import EmailWithAttachments
# 测试数据
test_article = {
'id': 99,
'title': '测试修复效果',
'source': 'Test',
'word_count': 500,
'publish_date': '2026-03-19',
'url': 'https://example.com/test'
}
test_markdown = "# 测试文章\n\n测试ZIP包图片修复效果。"
# 创建ZIP包
sender = EmailWithAttachments()
zip_path = sender.create_zip_package(test_article, test_markdown)
if not zip_path:
print("❌ ZIP包创建失败")
return False
print(f"✅ ZIP包创建成功: {zip_path}")
# 检查ZIP内容
with zipfile.ZipFile(zip_path, 'r') as zipf:
file_list = zipf.namelist()
print(f"ZIP包内容 ({len(file_list)} 个文件):")
has_images = False
for file in file_list:
print(f" - {file}")
if file.startswith('images/'):
has_images = True
if has_images:
print("✅ ZIP包包含图片文件")
else:
print("❌ ZIP包不包含图片文件")
# 检查图片文件大小
for file in file_list:
if file.startswith('images/'):
info = zipf.getinfo(file)
print(f" 图片文件: {file} ({info.file_size:,} 字节)")
# 清理测试文件
if os.path.exists(zip_path):
os.remove(zip_path)
print(f"清理测试文件: {zip_path}")
return True
except Exception as e:
print(f"❌ 测试失败: {e}")
return False
def test_xiaohongshu_content():
"""测试小红书内容是否去掉原文链接"""
print("\n📱 测试小红书内容修复...")
try:
sys.path.append("/home/ubuntu/nanocode/it_automation_enhanced/scripts")
from xiaohongshu_multi_image import XiaohongshuMultiImagePublisher
# 测试数据
test_title = "测试文章标题"
test_content = "这是一篇测试文章的内容。原文链接: https://example.com/article"
test_tags = ["测试", "技术"]
# 创建发布器
publisher = XiaohongshuMultiImagePublisher()
# 测试文本分页
pages = publisher.split_text_to_pages(test_content)
print(f"文本分页结果: {len(pages)} 页")
# 检查内容是否包含原文链接
content_has_url = "原文链接:" in test_content or "https://" in test_content
print(f"原始内容包含原文链接: {content_has_url}")
# 测试过滤逻辑
import re
test_preview = test_content[:200] + "..." if len(test_content) > 200 else test_content
filtered_preview = re.sub(r'原文链接:.*?(?=\n|$)', '', test_preview)
filtered_preview = re.sub(r'https?://\S+', '', filtered_preview)
filtered_preview = re.sub(r'\n\s*\n', '\n\n', filtered_preview).strip()
filtered_has_url = "原文链接:" in filtered_preview or "https://" in filtered_preview
print(f"过滤后内容包含原文链接: {filtered_has_url}")
if filtered_has_url:
print("❌ 过滤逻辑可能有问题")
print(f"原始预览: {test_preview[:50]}...")
print(f"过滤后预览: {filtered_preview[:50]}...")
return False
else:
print("✅ 过滤逻辑正常工作")
print(f"过滤后预览: {filtered_preview[:50]}...")
return True
except Exception as e:
print(f"❌ 测试失败: {e}")
return False
def test_manual_script():
"""测试手动脚本的内容"""
print("\n📝 测试手动脚本修复...")
try:
# 读取手动测试脚本
script_path = "/home/ubuntu/nanocode/it_automation_enhanced/scripts/manual_full_test.py"
with open(script_path, 'r', encoding='utf-8') as f:
content = f.read()
# 检查是否包含"原文链接:"
if "原文链接:" in content:
# 找到相关内容
lines = content.split('\n')
for i, line in enumerate(lines):
if "原文链接:" in line:
print(f"第 {i+1} 行: {line.strip()}")
# 检查上下文
for j in range(max(0, i-2), min(len(lines), i+3)):
print(f" {j+1}: {lines[j].strip()}")
print("❌ 手动脚本可能仍然包含原文链接")
return False
else:
print("✅ 手动脚本已去掉原文链接")
return True
except Exception as e:
print(f"❌ 测试失败: {e}")
return False
def test_main_scheduler():
"""测试主调度脚本的内容"""
print("\n⏰ 测试主调度脚本修复...")
try:
# 读取主调度脚本
script_path = "/home/ubuntu/nanocode/it_automation_enhanced/scripts/main_scheduler_complete.sh"
with open(script_path, 'r', encoding='utf-8') as f:
content = f.read()
# 检查是否包含"原文链接:"
if "原文链接:" in content:
# 找到相关内容
lines = content.split('\n')
for i, line in enumerate(lines):
if "原文链接:" in line:
print(f"第 {i+1} 行: {line.strip()}")
print("❌ 主调度脚本可能仍然包含原文链接")
return False
else:
print("✅ 主调度脚本已去掉原文链接")
return True
except Exception as e:
print(f"❌ 测试失败: {e}")
return False
def main():
"""主函数"""
print("=" * 60)
print("🔧 测试修复效果")
print("=" * 60)
results = []
# 测试1: ZIP包图片
print("\n1️⃣ 测试ZIP包图片修复...")
zip_result = test_zip_with_images()
results.append(("ZIP包图片", zip_result))
# 测试2: 小红书内容
print("\n2️⃣ 测试小红书内容修复...")
xhs_result = test_xiaohongshu_content()
results.append(("小红书内容", xhs_result))
# 测试3: 手动脚本
print("\n3️⃣ 测试手动脚本修复...")
manual_result = test_manual_script()
results.append(("手动脚本", manual_result))
# 测试4: 主调度脚本
print("\n4️⃣ 测试主调度脚本修复...")
scheduler_result = test_main_scheduler()
results.append(("主调度脚本", scheduler_result))
# 结果总结
print("\n" + "=" * 60)
print("📋 修复测试结果")
print("=" * 60)
all_passed = True
for test_name, result in results:
status = "✅ 通过" if result else "❌ 失败"
print(f"{test_name}: {status}")
if not result:
all_passed = False
print("\n" + "=" * 60)
if all_passed:
print("🎉 所有修复测试通过!")
print("问题已成功修复:")
print("1. ✅ ZIP包现在包含图片(占位图片)")
print("2. ✅ 小红书内容已去掉原文链接")
return 0
else:
print("⚠️ 部分修复测试失败,请检查")
return 1
if __name__ == "__main__":
sys.exit(main())