You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
249 lines
7.8 KiB
249 lines
7.8 KiB
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
每日跨境物流行业动态整理并发送邮件(HTML格式)
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
from datetime import datetime
|
|
|
|
# 添加脚本目录到路径
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, SCRIPT_DIR)
|
|
|
|
def format_news_content(news_data, date_str):
|
|
"""格式化新闻内容为HTML"""
|
|
|
|
content = f"""
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>跨境物流行业动态 - {date_str}</title>
|
|
<style>
|
|
body {{
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
line-height: 1.6;
|
|
color: #333;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}}
|
|
.container {{
|
|
background-color: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
padding: 30px;
|
|
}}
|
|
h1 {{
|
|
color: #2c3e50;
|
|
border-bottom: 3px solid #e74c3c;
|
|
padding-bottom: 10px;
|
|
margin-top: 0;
|
|
}}
|
|
h2 {{
|
|
color: #34495e;
|
|
border-left: 4px solid #e74c3c;
|
|
padding-left: 15px;
|
|
margin-top: 30px;
|
|
}}
|
|
.section {{
|
|
margin-bottom: 25px;
|
|
}}
|
|
.footer {{
|
|
margin-top: 40px;
|
|
padding-top: 20px;
|
|
border-top: 1px solid #eee;
|
|
color: #7f8c8d;
|
|
font-size: 14px;
|
|
}}
|
|
.warning {{
|
|
background-color: #f8d7da;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
border-left: 4px solid #dc3545;
|
|
margin: 15px 0;
|
|
}}
|
|
.highlight {{
|
|
background-color: #d1ecf1;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
border-left: 4px solid #17a2b8;
|
|
margin: 15px 0;
|
|
}}
|
|
pre {{
|
|
background: #f8f9fa;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
white-space: pre-wrap;
|
|
margin: 0;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🌐 跨境物流行业动态 - {date_str}</h1>
|
|
|
|
<div class="section">
|
|
<h2>📋 一、政策导向</h2>
|
|
<pre>{news_data.get('policy', '暂无政策相关信息')}</pre>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>🏢 二、企业动态</h2>
|
|
<pre>{news_data.get('company', '暂无企业相关信息')}</pre>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>📈 三、市场趋势</h2>
|
|
<pre>{news_data.get('market', '暂无市场相关信息')}</pre>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>🌍 四、国际合作</h2>
|
|
<pre>{news_data.get('international', '暂无国际合作相关信息')}</pre>
|
|
</div>
|
|
|
|
<div class="section warning">
|
|
<h2>⚠️ 风险提示</h2>
|
|
<pre>{news_data.get('risk', '暂无风险提示')}</pre>
|
|
</div>
|
|
|
|
<div class="section highlight">
|
|
<h2>💡 今日看点</h2>
|
|
<pre>{news_data.get('highlight', '暂无看点')}</pre>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p><strong>整理时间:</strong> {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
|
|
<p><strong>信息来源:</strong> 行业公开资料、新闻媒体</p>
|
|
<p><strong>关键词:</strong> 跨境物流、政策、企业、市场、国际合作</p>
|
|
<hr style="margin: 20px 0; border: none; border-top: 1px solid #eee;">
|
|
<p style="text-align: center; color: #95a5a6;">此邮件由系统自动发送</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
return content
|
|
|
|
def send_email(to_email, subject, body_content, attachment_path=None):
|
|
"""发送邮件 - HTML格式"""
|
|
|
|
# 保存HTML正文到临时文件
|
|
body_file = os.path.join(SCRIPT_DIR, f"cross_border_email_body_{datetime.now().strftime('%Y%m%d_%H%M%S')}.html")
|
|
with open(body_file, 'w', encoding='utf-8') as f:
|
|
f.write(body_content)
|
|
|
|
# 构建发送命令 - 使用HTML格式
|
|
email_skill_dir = "/root/.openclaw/workspace/skills/imap-smtp-email"
|
|
cmd = [
|
|
"node", "scripts/smtp.js", "send",
|
|
"--to", to_email,
|
|
"--subject", subject,
|
|
"--html",
|
|
"--html-file", body_file
|
|
]
|
|
|
|
if attachment_path and os.path.exists(attachment_path):
|
|
cmd.extend(["--attach", attachment_path])
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
cmd,
|
|
cwd=email_skill_dir,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=60
|
|
)
|
|
print("邮件发送命令输出:", result.stdout)
|
|
if result.stderr:
|
|
print("邮件发送命令错误:", result.stderr)
|
|
|
|
# 清理临时文件
|
|
if os.path.exists(body_file):
|
|
os.remove(body_file)
|
|
|
|
return result.returncode == 0
|
|
except Exception as e:
|
|
print(f"发送邮件时出错: {e}")
|
|
# 清理临时文件
|
|
if os.path.exists(body_file):
|
|
os.remove(body_file)
|
|
return False
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("=" * 60)
|
|
print("🌐 跨境物流行业每日动态")
|
|
print("=" * 60)
|
|
|
|
today = datetime.now().strftime('%Y-%m-%d')
|
|
|
|
# 暂时用示例数据
|
|
news_data = {
|
|
'policy': """
|
|
- **美国关税政策**:最高法院裁定特朗普关税违宪后,FedEx起诉政府要求退还关税
|
|
- **临时关税**:白宫实施临时关税,影响全球贸易格局
|
|
- **一带一路**:中国与UNDP合作完成马尔代夫气象服务项目
|
|
- **广东战略**:强调制造业与服务业协同发展
|
|
""",
|
|
'company': """
|
|
- **DHL**:推出布鲁塞尔-辛辛那提冷链航线,扩大医疗物流网络
|
|
- 投资20亿美元于DHL Health Logistics业务
|
|
- **WiseTech**:为迎接AI时代,裁员近30%
|
|
- **巴拿马港口**:取消和记黄埔协议,码头交由马士基/MSC管理
|
|
""",
|
|
'market': """
|
|
- **技术创新**:AI和量子技术增强供应链韧性
|
|
- **成本变化**:美国柴油价格连续8周上涨,至3.809美元/加仑
|
|
- **电商影响**:电子商务持续重塑全球货运网络
|
|
- **行业主题**:"不确定性"仍是2026年物流行业关键词
|
|
""",
|
|
'international': """
|
|
- **中印巴贸易**:印度和巴西承诺将双边贸易提高至200亿美元
|
|
- **柬埔寨出口**:服装鞋类2025年出口达155亿美元
|
|
""",
|
|
'risk': """
|
|
- ⚠️ 贸易政策不确定性
|
|
- ⚠️ 地缘政治风险(巴拿马运河变动)
|
|
- ⚠️ 燃油成本压力
|
|
- ⚠️ 供应链中断风险
|
|
""",
|
|
'highlight': """
|
|
1. 技术变革(AI、量子技术)正在重塑物流行业
|
|
2. 冷链物流和医疗物流成为重要增长点
|
|
3. 成本上升和政策不确定性需要密切关注
|
|
"""
|
|
}
|
|
|
|
# 格式化内容
|
|
email_body = format_news_content(news_data, today)
|
|
|
|
# 保存结果到文件
|
|
result_file = os.path.join(SCRIPT_DIR, f"跨境物流行业动态_{today}.html")
|
|
with open(result_file, 'w', encoding='utf-8') as f:
|
|
f.write(email_body)
|
|
|
|
print(f"\n结果已保存到: {result_file}")
|
|
|
|
# 发送邮件
|
|
to_email = "eanliu@xswec.cn"
|
|
subject = f"跨境物流行业动态 - {today}"
|
|
|
|
print(f"\n正在发送邮件到: {to_email}")
|
|
success = send_email(to_email, subject, email_body, result_file)
|
|
|
|
if success:
|
|
print("✅ 邮件发送成功!")
|
|
return 0
|
|
else:
|
|
print("❌ 邮件发送失败!")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|
|
|