Refactor the cron job functionality to transition from a crawling to a searching model. Update related documentation and scripts to reflect the new terminology and functionality, including changes in the README and script comments. Enhance WeChat menu and message handling to support the new search features, ensuring clarity in user interactions and logging.

This commit is contained in:
2026-01-09 08:19:09 +08:00
parent 4000438f49
commit 72dc40186d
20 changed files with 5935 additions and 595 deletions
+11 -11
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""
定时爬取脚本
执行爬取、筛选关键词、保存到数据库并发送企业微信卡片通知
定时搜索脚本
执行搜索、筛选关键词、保存到数据库并发送企业微信卡片通知
"""
import sys
@@ -23,7 +23,7 @@ try:
logger = get_logger(__name__)
def main():
"""主函数:执行定时爬取任务"""
"""主函数:执行定时搜索任务"""
try:
# 加载配置
config = load_config()
@@ -34,13 +34,13 @@ try:
# 初始化日志
init_logger(config=config)
logger.info("=== 开始定时爬取任务 ===")
logger.info("=== 开始定时搜索任务 ===")
# 初始化存储
init_storage()
# 执行爬取
logger.info("开始执行爬取...")
# 执行搜索
logger.info("开始执行搜索...")
crawl_results = crawl_announcements()
if not crawl_results:
@@ -54,7 +54,7 @@ try:
all_announcements.extend(result.announcements)
total_crawled = len(all_announcements)
logger.info(f"爬取{total_crawled} 条原始公告")
logger.info(f"搜索{total_crawled} 条原始公告")
# 保存所有公告(按来源分组,每源保留最新100条)
all_saved_stats = save_all_announcements_by_source_to_storage(all_announcements, max_per_source=100)
@@ -103,18 +103,18 @@ try:
print(f"保存到数据库: {saved_count}")
print(f"企业微信通知: {'成功' if notify_success else '失败' if config.wechat_app.enabled else '未启用'}")
logger.info("=== 定时爬取任务完成 ===")
logger.info("=== 定时搜索任务完成 ===")
return True
except Exception as e:
logger.error(f"定时爬取任务执行失败: {str(e)}")
print(f"❌ 定时爬取任务失败: {str(e)}", file=sys.stderr)
logger.error(f"定时搜索任务执行失败: {str(e)}")
print(f"❌ 定时搜索任务失败: {str(e)}", file=sys.stderr)
# 尝试发送错误通知
try:
if config and config.wechat_app.enabled:
send_system_notification(
"定时爬取任务失败",
"定时搜索任务失败",
f"错误信息: {str(e)}"
)
except Exception as notify_error: