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.
@@ -42,7 +42,8 @@ class MarkdownGenerator:
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def generate_markdown(self, announcements: List[Announcement],
|
||||
title: str = "广西政府采购网公告监控") -> str:
|
||||
title: str = "广西政府采购网公告监控",
|
||||
time_period: str = None) -> str:
|
||||
"""
|
||||
生成Markdown内容
|
||||
|
||||
@@ -54,22 +55,31 @@ class MarkdownGenerator:
|
||||
str: Markdown格式的文本
|
||||
"""
|
||||
if not announcements:
|
||||
return self._generate_empty_markdown(title)
|
||||
return self._generate_empty_markdown(title, time_period)
|
||||
|
||||
# 按来源分组
|
||||
grouped_announcements = self._group_announcements_by_source(announcements)
|
||||
|
||||
# 生成Markdown
|
||||
lines = []
|
||||
lines.append(f"# {title}")
|
||||
lines.append("")
|
||||
lines.append(f"**更新时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
lines.append(f"**总公告数**: {len(announcements)}")
|
||||
lines.append("# 搜索完成")
|
||||
lines.append("")
|
||||
|
||||
# 生成目录
|
||||
lines.extend(self._generate_toc(grouped_announcements))
|
||||
lines.append("---")
|
||||
# 解析标题中的关键词
|
||||
keyword = "未知"
|
||||
if "关键词:" in title:
|
||||
keyword_part = title.split("关键词:")[-1].strip()
|
||||
keyword = keyword_part.split()[0] if keyword_part else "未知"
|
||||
|
||||
lines.append(f"📋 关键词搜索: `{keyword}` - 总公告数: `{len(announcements)}`")
|
||||
lines.append("")
|
||||
|
||||
# 使用传入的时间段或默认的更新时间
|
||||
if time_period:
|
||||
lines.append(f"**时间段: {time_period}**")
|
||||
else:
|
||||
lines.append(f"**更新时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}**")
|
||||
lines.append("")
|
||||
lines.append("")
|
||||
|
||||
# 生成各来源的公告
|
||||
@@ -107,11 +117,8 @@ class MarkdownGenerator:
|
||||
def _generate_source_section(self, source_name: str, announcements: List[Announcement]) -> List[str]:
|
||||
"""生成来源章节"""
|
||||
lines = []
|
||||
anchor = self._create_anchor(source_name)
|
||||
|
||||
lines.append(f"## {source_name}")
|
||||
lines.append("")
|
||||
lines.append(f"**共 {len(announcements)} 条公告**")
|
||||
lines.append(f"## {source_name} - **共 {len(announcements)} 条**")
|
||||
lines.append("")
|
||||
|
||||
# 生成公告列表
|
||||
@@ -124,59 +131,49 @@ class MarkdownGenerator:
|
||||
"""生成单个公告项"""
|
||||
lines = []
|
||||
|
||||
# 公告标题
|
||||
title_prefix = ""
|
||||
if self.include_today_highlight and announcement.is_today:
|
||||
title_prefix = "🆕 **【今日】**"
|
||||
|
||||
title_line = f"### {index}. {title_prefix}[{announcement.title}]({announcement.content_url})"
|
||||
# 公告标题(包含超链接)
|
||||
title_line = f"### {index}. [{announcement.title}]({announcement.content_url})"
|
||||
lines.append(title_line)
|
||||
lines.append("")
|
||||
|
||||
# 公告信息
|
||||
info_items = []
|
||||
# 公告信息 - 简洁格式
|
||||
info_parts = []
|
||||
|
||||
if announcement.publish_date:
|
||||
publish_date = announcement.publish_date.strftime("%Y-%m-%d")
|
||||
info_items.append(f"📅 发布时间: {publish_date}")
|
||||
info_parts.append(publish_date)
|
||||
|
||||
if announcement.purchase_name:
|
||||
info_items.append(f"🏢 发布单位: {announcement.purchase_name}")
|
||||
info_parts.append(announcement.purchase_name)
|
||||
|
||||
info_items.append(f"📄 来源: {announcement.source_name}")
|
||||
info_parts.append(announcement.source_name)
|
||||
|
||||
if announcement.crawled_at:
|
||||
crawled_time = announcement.crawled_at.strftime("%m-%d %H:%M")
|
||||
info_items.append(f"🤖 爬取时间: {crawled_time}")
|
||||
|
||||
if info_items:
|
||||
lines.append(" | ".join(info_items))
|
||||
if info_parts:
|
||||
info_line = " | ".join(info_parts)
|
||||
lines.append(info_line)
|
||||
lines.append("")
|
||||
|
||||
# 如果是新公告,添加标记
|
||||
if announcement.is_new:
|
||||
lines.append("*🚀 新公告*")
|
||||
lines.append("")
|
||||
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
|
||||
return lines
|
||||
|
||||
def _generate_empty_markdown(self, title: str) -> str:
|
||||
def _generate_empty_markdown(self, title: str, time_period: str = None) -> str:
|
||||
"""生成空内容的Markdown"""
|
||||
# 解析标题中的关键词
|
||||
keyword = "未知"
|
||||
if "关键词:" in title:
|
||||
keyword_part = title.split("关键词:")[-1].strip()
|
||||
keyword = keyword_part.split()[0] if keyword_part else "未知"
|
||||
|
||||
lines = [
|
||||
f"# {title}",
|
||||
f"📋 关键词搜索: `{keyword}` - 总公告数: `0`",
|
||||
"",
|
||||
f"**更新时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
|
||||
f"**时间段: {time_period}**" if time_period else f"**更新时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}**",
|
||||
"",
|
||||
"## 无新公告",
|
||||
"",
|
||||
"当前时间范围内没有找到符合条件的公告。",
|
||||
"## 无匹配公告",
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
f"*由广西政府采购网公告监控系统生成*"
|
||||
"在指定时间范围内没有找到符合条件的公告。",
|
||||
""
|
||||
]
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
Reference in New Issue
Block a user