first commit
This commit is contained in:
235
SKILL.md
Normal file
235
SKILL.md
Normal file
@@ -0,0 +1,235 @@
|
||||
---
|
||||
name: "policy-regulations-retrieval"
|
||||
description: "Automates Chinese tax policy retrieval with scheduled tasks, web scraping, content filtering, file downloading, and data deduplication. Invoke when user needs to build a policy/regulation collection system or wants automated policy monitoring."
|
||||
---
|
||||
|
||||
# 政策法规检索与整理系统
|
||||
|
||||
这是一个自动化政策法规检索与整理系统,可用于从中国税务相关部门网站自动抓取、筛选、下载和整理政策法规文件。
|
||||
|
||||
## 功能特性
|
||||
|
||||
1. **定时任务功能** - 支持配置每日自动执行检索任务
|
||||
2. **网站内容爬取** - 自动访问税务相关部门网站获取最新政策
|
||||
3. **内容筛选** - 智能识别包含关键词(最新、通知、公告、政策、法规)的内容
|
||||
4. **资料下载** - 支持下载PDF、Word、TXT等多种格式文件
|
||||
5. **数据处理** - 去重、分类整理、自动生成汇总报告
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 基本命令
|
||||
|
||||
```bash
|
||||
# 初始化系统配置
|
||||
python policy_retrieval.py init
|
||||
|
||||
# 立即执行一次检索(默认发送邮件报告)
|
||||
python policy_retrieval.py run
|
||||
|
||||
# 立即执行一次检索,不发送邮件
|
||||
python policy_retrieval.py run --no-email
|
||||
|
||||
# 指定收件人执行检索
|
||||
python policy_retrieval.py run -e user@example.com -e another@example.com
|
||||
|
||||
# 启动定时任务服务
|
||||
python policy_retrieval.py schedule --time "09:00"
|
||||
|
||||
# 查看检索结果
|
||||
python policy_retrieval.py report
|
||||
|
||||
# 查看帮助
|
||||
python policy_retrieval.py --help
|
||||
```
|
||||
|
||||
### 配置文件 (config.yaml)
|
||||
|
||||
```yaml
|
||||
# 定时任务配置
|
||||
scheduler:
|
||||
enabled: true
|
||||
time: "09:00" # 每日执行时间
|
||||
days: ["mon", "tue", "wed", "thu", "fri"] # 执行日期
|
||||
|
||||
# 目标网站配置
|
||||
targets:
|
||||
- name: "国家税务总局"
|
||||
url: "https://www.chinatax.gov.cn/"
|
||||
keywords: ["最新", "通知", "公告", "政策", "法规"]
|
||||
- name: "财政部"
|
||||
url: "https://www.mof.gov.cn/"
|
||||
keywords: ["最新", "通知", "公告", "政策", "法规"]
|
||||
- name: "科技部"
|
||||
url: "https://www.most.gov.cn/"
|
||||
keywords: ["科技", "创新", "项目", "申报", "通知", "公告", "政策"]
|
||||
|
||||
# 下载配置
|
||||
download:
|
||||
path: "./downloads"
|
||||
formats: ["pdf", "doc", "docx", "txt"]
|
||||
max_size: 50MB
|
||||
check_disk_space: true # 下载前检查磁盘空间
|
||||
min_disk_space: 100MB # 最小剩余空间要求
|
||||
verify_download: true # 验证下载文件完整性
|
||||
|
||||
# 反爬策略配置
|
||||
anti_crawler:
|
||||
enabled: true
|
||||
user_agents:
|
||||
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0"
|
||||
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15"
|
||||
request_interval: 3 # 请求间隔(秒)
|
||||
timeout: 30 # 请求超时(秒)
|
||||
retry_times: 3 # 重试次数
|
||||
retry_delay: 5 # 重试间隔(秒)
|
||||
|
||||
# 代理池配置
|
||||
proxy:
|
||||
enabled: false
|
||||
pool: [] # 代理列表,格式: ["http://user:pass@host:port", ...]
|
||||
rotate: true # 是否轮换代理
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
enabled: true
|
||||
level: "INFO" # DEBUG, INFO, WARNING, ERROR
|
||||
path: "./logs"
|
||||
max_size: 10MB # 单个日志文件最大大小
|
||||
backup_count: 5 # 保留日志文件数量
|
||||
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
|
||||
# 告警通知配置
|
||||
notification:
|
||||
enabled: true # 启用通知功能
|
||||
on_failure: true # 任务失败时通知
|
||||
on_success: true # 任务成功时通知(发送检索报告)
|
||||
email:
|
||||
enabled: true
|
||||
smtp_host: "smtp.qq.com" # QQ邮箱示例
|
||||
smtp_port: 587
|
||||
smtp_user: "your_email@qq.com"
|
||||
smtp_password: "your_auth_code" # QQ邮箱需要使用授权码
|
||||
from_addr: "your_email@qq.com"
|
||||
to_addrs:
|
||||
- "user@example.com"
|
||||
- "admin@example.com"
|
||||
dingtalk:
|
||||
enabled: false
|
||||
webhook: "https://oapi.dingtalk.com/robot/send?access_token=xxx"
|
||||
webhook:
|
||||
enabled: false
|
||||
url: "https://your-webhook-url.com/notify"
|
||||
|
||||
# 去重配置
|
||||
deduplication:
|
||||
title_similarity: 0.8
|
||||
content_similarity: 0.9
|
||||
|
||||
# 分类配置
|
||||
categories:
|
||||
- name: "税收政策"
|
||||
keywords: ["税收", "税务", "纳税"]
|
||||
- name: "通知公告"
|
||||
keywords: ["通知", "公告"]
|
||||
- name: "法规文件"
|
||||
keywords: ["法规", "条例", "规章"]
|
||||
```
|
||||
|
||||
## 核心模块说明
|
||||
|
||||
### 1. 定时任务模块 (scheduler.py)
|
||||
- 使用APScheduler实现定时任务
|
||||
- 支持自定义执行时间和频率
|
||||
- 可配置工作日/休息日
|
||||
- **持久化存储**:使用SQLite数据库存储任务状态,程序重启后任务不丢失
|
||||
- **支持cron表达式**:高级用户可使用cron格式自定义执行规则
|
||||
|
||||
### 2. 网页爬取模块 (scraper.py)
|
||||
- 支持多网站并发爬取
|
||||
- 智能解析HTML/XML内容
|
||||
- **反爬策略**:
|
||||
- User-Agent轮换(随机选取)
|
||||
- 请求间隔控制(默认3秒,可配置)
|
||||
- 请求超时设置(默认30秒)
|
||||
- 自动重试机制(默认3次)
|
||||
- **代理池支持**:可配置代理列表,自动轮换
|
||||
- **错误处理**:
|
||||
- 网络异常自动重试
|
||||
- 解析失败记录日志并跳过
|
||||
- 请求超时处理
|
||||
|
||||
### 3. 内容筛选模块 (filter.py)
|
||||
- 关键词匹配算法
|
||||
- 相关度评分系统
|
||||
- 可配置筛选规则
|
||||
|
||||
### 4. 文件下载模块 (downloader.py)
|
||||
- 支持多种文件格式
|
||||
- 断点续传功能
|
||||
- 自动重命名和分类
|
||||
- **文件完整性校验**:下载完成后校验文件大小和完整性
|
||||
- **磁盘空间检查**:下载前检查剩余空间
|
||||
|
||||
### 5. 数据处理模块 (processor.py)
|
||||
- 基于SimHash的去重算法
|
||||
- 多维度分类(时间、类型、部门)
|
||||
- Excel/CSV报告生成
|
||||
- **数据库存储**:使用SQLite存储结构化数据,支持查询和统计
|
||||
|
||||
### 6. 日志模块 (logger.py)
|
||||
- **结构化日志**:JSON格式日志,便于分析
|
||||
- **日志轮转**:按大小和时间自动轮转,防止日志文件过大
|
||||
- **执行记录**:记录每次任务执行的开始时间、结束时间、结果统计
|
||||
- **错误追踪**:详细的错误堆栈信息,便于问题排查
|
||||
|
||||
### 7. 通知模块 (notifier.py)
|
||||
- **多通道通知**:支持邮件、钉钉、Webhook
|
||||
- **失败告警**:任务执行失败时自动发送通知
|
||||
- **可配置开关**:可单独控制成功/失败通知
|
||||
|
||||
## 输出结果
|
||||
|
||||
系统会在以下目录生成文件:
|
||||
|
||||
### output 目录
|
||||
- `summary_YYYYMMDD.xlsx` - 每日汇总表格
|
||||
- `deduplicated_data.json` - 去重后的数据
|
||||
- `category_*/` - 按类别分类的文件
|
||||
- `policies.db` - SQLite数据库(结构化存储)
|
||||
|
||||
### logs 目录
|
||||
- `app_YYYYMMDD.log` - 应用日志
|
||||
- `execution_YYYYMMDD.json` - 执行记录(JSON格式)
|
||||
|
||||
### downloads 目录
|
||||
- 按类别分类的政策文件
|
||||
- 文件名格式:`{日期}_{来源}_{标题}`
|
||||
|
||||
## 示例输出表格
|
||||
|
||||
| 标题 | 发布时间 | 来源 | 类别 | 摘要 | 下载链接 |
|
||||
|------|----------|------|------|------|----------|
|
||||
| 关于实施新的组合式税费支持政策的通知 | 2024-01-01 | 国家税务总局 | 税收政策 | ... | /downloads/xxx.pdf |
|
||||
|
||||
## 依赖安装
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
主要依赖:
|
||||
- requests - HTTP请求
|
||||
- beautifulsoup4 - HTML解析
|
||||
- apscheduler - 定时任务
|
||||
- pandas - 数据处理
|
||||
- openpyxl - Excel导出
|
||||
- sqlalchemy - 数据库ORM
|
||||
- python-dotenv - 环境变量管理
|
||||
- pytz - 时区处理
|
||||
- selenium/playwright - 动态页面爬取(可选)
|
||||
|
||||
可选依赖(通知功能):
|
||||
- smtplib - 邮件发送(标准库)
|
||||
- requests - 钉钉/Webhook通知
|
||||
Reference in New Issue
Block a user