Implement manual crawling feature in GXGPMonitorApp, allowing users to filter announcements by date and keywords. Update Markdown generation to include time period and keyword details. Remove outdated onu.md file. Enhance WeChat message handling to support manual crawl results and improve logging for better traceability.
This commit is contained in:
Binary file not shown.
@@ -276,31 +276,118 @@ class WeChatMessageHandler:
|
||||
if not app:
|
||||
return self._create_text_response("系统初始化失败,请稍后重试", from_user)
|
||||
|
||||
# 执行爬取
|
||||
result = app.run_crawl(keywords=keywords)
|
||||
# 执行爬取(手动爬取,只筛选今天的公告)
|
||||
result = app.run_crawl(keywords=keywords, manual_crawl=True)
|
||||
|
||||
if result.get("success"):
|
||||
total = result.get("total_crawled", 0)
|
||||
filtered = result.get("filtered", 0)
|
||||
filtered_announcements = result.get("filtered_announcements", [])
|
||||
|
||||
# 获取今天的日期范围
|
||||
from datetime import datetime, date
|
||||
today = date.today()
|
||||
time_period = f"{today.strftime('%Y-%m-%d')} 00:00 至 {datetime.now().strftime('%Y-%m-%d %H:%M')}"
|
||||
|
||||
if filtered > 0:
|
||||
response = f"""✅ 爬取完成!
|
||||
# 生成markdown汇总消息并发送
|
||||
try:
|
||||
from ..storage.md_generator import MarkdownGenerator
|
||||
from ..notification.wechat import send_system_notification
|
||||
|
||||
关键词: {' '.join(keywords)}
|
||||
📊 统计信息:
|
||||
# 生成markdown内容
|
||||
md_generator = MarkdownGenerator()
|
||||
title = f"手动爬取结果 - 关键词: {' '.join(keywords)}"
|
||||
markdown_content = md_generator.generate_markdown(filtered_announcements, title, time_period)
|
||||
|
||||
# 发送markdown消息
|
||||
notify_success = send_system_notification(
|
||||
title="🔍 搜索完成",
|
||||
content=markdown_content
|
||||
)
|
||||
|
||||
if notify_success:
|
||||
# 成功发送markdown消息,返回空响应(不发送额外文本消息)
|
||||
response = ""
|
||||
else:
|
||||
response = f"""✅ 爬取完成!
|
||||
|
||||
🔍 搜索条件:
|
||||
• 关键词: {' '.join(keywords)}
|
||||
• 时间段: {time_period}
|
||||
|
||||
📊 统计结果:
|
||||
• 总共发现: {total} 条公告
|
||||
• 匹配筛选: {filtered} 条
|
||||
|
||||
相关公告已推送,请查收。"""
|
||||
else:
|
||||
response = f"""✅ 爬取完成!
|
||||
⚠️ 公告汇总推送失败,但数据已生成。"""
|
||||
except Exception as notify_error:
|
||||
logger.error(f"生成或发送公告汇总失败: {notify_error}")
|
||||
# 降级处理:手动构建简单的文本响应
|
||||
announcement_list = []
|
||||
for i, ann in enumerate(filtered_announcements[:10], 1): # 最多显示10条
|
||||
announcement_list.append(f"{i}. {ann.title[:50]}...")
|
||||
|
||||
关键词: {' '.join(keywords)}
|
||||
📊 统计信息:
|
||||
remaining = len(filtered_announcements) - 10
|
||||
if remaining > 0:
|
||||
announcement_list.append(f"... 还有 {remaining} 条公告")
|
||||
|
||||
response = f"""✅ 爬取完成!
|
||||
|
||||
🔍 搜索条件:
|
||||
• 关键词: {' '.join(keywords)}
|
||||
• 时间段: {time_period}
|
||||
|
||||
📊 统计结果:
|
||||
• 总共发现: {total} 条公告
|
||||
• 匹配筛选: {filtered} 条
|
||||
|
||||
📋 匹配公告:
|
||||
{chr(10).join(announcement_list)}
|
||||
|
||||
💡 公告详情已保存,可通过其他方式查看。"""
|
||||
else:
|
||||
# 没有找到匹配的公告,发送markdown格式的空结果
|
||||
try:
|
||||
from ..storage.md_generator import MarkdownGenerator
|
||||
from ..notification.wechat import send_system_notification
|
||||
|
||||
md_generator = MarkdownGenerator()
|
||||
title = f"手动爬取结果 - 关键词: {' '.join(keywords)}"
|
||||
markdown_content = md_generator.generate_markdown([], title, time_period)
|
||||
|
||||
notify_success = send_system_notification(
|
||||
title="🔍 搜索完成",
|
||||
content=markdown_content
|
||||
)
|
||||
|
||||
if notify_success:
|
||||
response = ""
|
||||
else:
|
||||
response = f"""✅ 爬取完成!
|
||||
|
||||
🔍 搜索条件:
|
||||
• 关键词: {' '.join(keywords)}
|
||||
• 时间段: {time_period}
|
||||
|
||||
📊 统计结果:
|
||||
• 总共发现: {total} 条公告
|
||||
• 匹配筛选: 0 条
|
||||
|
||||
没有找到匹配的公告。"""
|
||||
❌ 在指定时间段内没有找到匹配的公告。"""
|
||||
except Exception as notify_error:
|
||||
logger.error(f"生成或发送公告汇总失败: {notify_error}")
|
||||
response = f"""✅ 爬取完成!
|
||||
|
||||
🔍 搜索条件:
|
||||
• 关键词: {' '.join(keywords)}
|
||||
• 时间段: {time_period}
|
||||
|
||||
📊 统计结果:
|
||||
• 总共发现: {total} 条公告
|
||||
• 匹配筛选: 0 条
|
||||
|
||||
❌ 在指定时间段内没有找到匹配的公告。"""
|
||||
else:
|
||||
error = result.get("error", "未知错误")
|
||||
response = f"❌ 爬取失败: {error}"
|
||||
|
||||
Reference in New Issue
Block a user