Files
auv/scripts/README_HOTSPOT.md

153 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 热点股追踪数据导出/导入工具
## 功能说明
本工具用于导出和导入热点股追踪的历史数据,包括:
- 每日题材涨幅前20
- 每日核心股票(覆盖多个题材的股票)
- 每日核心股票与题材的关联关系
## 快速使用(Docker环境)
### 1. 导出8月20日的数据
```bash
./scripts/docker_hotspot.sh export 2026-08-20
```
### 2. 导入数据
```bash
# 导入数据到容器
./scripts/docker_hotspot.sh import hotspot_2026-08-20.json
```
### 3. 查看数据库中的日期
```bash
./scripts/docker_hotspot.sh list
```
### 4. 备份整个数据库
```bash
./scripts/docker_hotspot.sh backup
```
### 5. 进入Python shell
```bash
./scripts/docker_hotspot.sh shell
```
## 本地开发环境
如果在本地开发环境中,可以使用以下命令:
```bash
# 导出数据
python3 scripts/export_hotspot_data.py export --date 2026-08-20
# 导入数据
python3 scripts/export_hotspot_data.py import --file hotspot_2026-08-20.json
# 列出日期
python3 scripts/export_hotspot_data.py list
```
## 文件说明
### Docker脚本 (`docker_hotspot.sh`)
- `export [日期]`: 从容器导出数据(默认8月20日)
- `import <文件>`: 导入数据文件到容器
- `list`: 列出所有日期
- `backup`: 备份整个数据库
- `shell`: 进入容器的Python shell
### Python脚本 (`export_hotspot_data.py`)
- `export --date YYYY-MM-DD`: 导出指定日期的数据
- `import --file <文件路径>`: 导入数据文件
- `list`: 列出数据库中所有有数据的日期
### Shell脚本 (`hotspot_backup.sh`)
- `export [日期]`: 导出数据(默认8月20日)
- `import <文件>`: 导入数据文件
- `list`: 列出所有日期
- `backup`: 备份整个数据库
## 数据格式
导出的JSON文件包含以下字段:
```json
{
"version": "1.0",
"trade_date": "2026-08-11",
"themes": [...], // 题材数据
"core_stocks": [...], // 核心股票数据
"stock_themes": [...], // 股票-题材关联
"stats": {
"theme_count": 20,
"core_stock_count": 193,
"stock_theme_count": 1205
}
}
```
## 注意事项
1. **容器运行**:使用Docker脚本前,请确保容器正在运行
2. **幂等性**:导入时使用 `INSERT OR IGNORE`,重复导入不会产生重复数据
3. **数据完整性**:导入前会检查目标日期是否已有数据
4. **备份建议**:导入前建议先备份数据库
5. **日期格式**:日期格式必须为 `YYYY-MM-DD`(如 `2026-08-20`)
## 常见问题
### Q: 容器未运行怎么办?
A: 启动容器:
```bash
docker-compose up -d
```
### Q: 如何查看容器是否运行?
A: 运行以下命令:
```bash
docker ps | grep auv
```
### Q: 如何手动采集8月20日的数据?
A: 在容器内运行:
```bash
docker exec -it auv python3 -c "
import asyncio
from services.daily_collector import collect_daily
asyncio.run(collect_daily('2026-08-20'))
"
```
### Q: 如何查看数据库中的日期?
A: 运行 `./scripts/docker_hotspot.sh list`
### Q: 如何备份数据库?
A: 运行 `./scripts/docker_hotspot.sh backup`
### Q: 导入时出现错误怎么办?
A: 检查JSON文件格式是否正确,确保包含必要的字段。可以使用以下命令验证JSON:
```bash
python3 -m json.tool hotspot_2026-08-20.json
```