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.
275 lines
8.5 KiB
275 lines
8.5 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)
|
|
|
|
import check_sz_housing
|
|
|
|
def format_housing_content(results, target_date):
|
|
"""格式化住建局内容为HTML"""
|
|
|
|
# 按类型分组
|
|
notice_results = [r for r in results if r['type'] == '通知公告']
|
|
policy_results = [r for r in results if r['type'] == '政策法规']
|
|
|
|
content = f"""
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>深圳市住房和建设局每日信息 - {target_date}</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 #9b59b6;
|
|
padding-bottom: 10px;
|
|
margin-top: 0;
|
|
}}
|
|
h2 {{
|
|
color: #34495e;
|
|
border-left: 4px solid #9b59b6;
|
|
padding-left: 15px;
|
|
margin-top: 30px;
|
|
}}
|
|
.section {{
|
|
margin-bottom: 25px;
|
|
}}
|
|
.item {{
|
|
background: #f8f9fa;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
margin-bottom: 15px;
|
|
border-left: 4px solid #3498db;
|
|
}}
|
|
.item-title {{
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
color: #2c3e50;
|
|
margin-bottom: 10px;
|
|
}}
|
|
.item-meta {{
|
|
color: #7f8c8d;
|
|
font-size: 14px;
|
|
margin-bottom: 10px;
|
|
}}
|
|
.item-link {{
|
|
background: #3498db;
|
|
color: white;
|
|
padding: 8px 15px;
|
|
border-radius: 4px;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
margin-top: 10px;
|
|
}}
|
|
.no-data {{
|
|
background: #fff3cd;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
border-left: 4px solid #ffc107;
|
|
text-align: center;
|
|
color: #856404;
|
|
}}
|
|
.footer {{
|
|
margin-top: 40px;
|
|
padding-top: 20px;
|
|
border-top: 1px solid #eee;
|
|
color: #7f8c8d;
|
|
font-size: 14px;
|
|
}}
|
|
.badge {{
|
|
display: inline-block;
|
|
padding: 4px 10px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
font-weight: bold;
|
|
margin-right: 10px;
|
|
}}
|
|
.badge-notice {{
|
|
background: #3498db;
|
|
color: white;
|
|
}}
|
|
.badge-policy {{
|
|
background: #e67e22;
|
|
color: white;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🏠 深圳市住房和建设局每日信息 - {target_date}</h1>
|
|
"""
|
|
|
|
if not results:
|
|
content += f"""
|
|
<div class="no-data">
|
|
<h3>未找到相关信息</h3>
|
|
<p>{target_date} 没有发布包含关键词(人才房、公租房、保障房、租赁)的通知公告或政策法规</p>
|
|
</div>
|
|
"""
|
|
else:
|
|
if notice_results:
|
|
content += f"""
|
|
<div class="section">
|
|
<h2>📋 通知公告 ({len(notice_results)}条)</h2>
|
|
"""
|
|
for i, item in enumerate(notice_results, 1):
|
|
content += f"""
|
|
<div class="item">
|
|
<div class="item-title">
|
|
<span class="badge badge-notice">通知公告</span>
|
|
{i}. {item['title']}
|
|
</div>
|
|
<div class="item-meta">
|
|
<strong>日期:</strong> {item['date']}
|
|
</div>
|
|
<a href="{item['link']}" target="_blank" class="item-link">🔗 查看原文</a>
|
|
</div>
|
|
"""
|
|
|
|
if policy_results:
|
|
content += f"""
|
|
<div class="section">
|
|
<h2>📜 政策法规 ({len(policy_results)}条)</h2>
|
|
"""
|
|
for i, item in enumerate(policy_results, 1):
|
|
content += f"""
|
|
<div class="item">
|
|
<div class="item-title">
|
|
<span class="badge badge-policy">政策法规</span>
|
|
{i}. {item['title']}
|
|
</div>
|
|
<div class="item-meta">
|
|
<strong>日期:</strong> {item['date']}
|
|
</div>
|
|
<a href="{item['link']}" target="_blank" class="item-link">🔗 查看原文</a>
|
|
</div>
|
|
"""
|
|
|
|
content += f"""
|
|
<div class="footer">
|
|
<p><strong>检查时间:</strong> {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
|
|
<p><strong>通知公告关键词:</strong> 人才房、公租房、保障房、租赁</p>
|
|
<p><strong>政策法规:</strong> 不过滤,有就整理</p>
|
|
<p><strong>检查页面:</strong></p>
|
|
<ul>
|
|
<li>通知公告: <a href="https://zjj.sz.gov.cn/ztfw/zfbz/tzgg2017/index.html" target="_blank">https://zjj.sz.gov.cn/ztfw/zfbz/tzgg2017/index.html</a></li>
|
|
<li>政策法规: <a href="https://zjj.sz.gov.cn/ztfw/zfbz/zcfg2017/index.html" target="_blank">https://zjj.sz.gov.cn/ztfw/zfbz/zcfg2017/index.html</a></li>
|
|
</ul>
|
|
<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"sz_housing_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)
|
|
|
|
# 获取昨天的日期
|
|
target_date = check_sz_housing.get_yesterday()
|
|
|
|
# 运行检查
|
|
results = check_sz_housing.main()
|
|
|
|
# 格式化邮件内容
|
|
email_body = format_housing_content(results, target_date)
|
|
|
|
# 保存结果到文件
|
|
result_file = os.path.join(SCRIPT_DIR, f"深圳住建局信息_{target_date}.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"深圳市住房和建设局每日信息 - {target_date}"
|
|
|
|
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())
|
|
|