Initial commit: Report automation script using Playwright
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# DESIGN - 报表自动化架构设计
|
||||
|
||||
## 1. 整体架构
|
||||
```mermaid
|
||||
graph TD
|
||||
A[Main Script] --> B[Browser Manager]
|
||||
A --> C[Secsion Service]
|
||||
A --> D[Upload Service]
|
||||
B --> E[Playwright Context]
|
||||
C --> E
|
||||
D --> E
|
||||
```
|
||||
|
||||
## 2. 核心组件说明
|
||||
- **Browser Manager**: 初始化 Playwright,配置 `ignore_https_errors`,管理浏览器生命周期。
|
||||
- **Secsion Service**:
|
||||
- `login()`: 处理角色选择、账号密码输入、登录按钮点击。
|
||||
- `export_report(date)`: 处理日期填写、点击导出、捕获下载流。
|
||||
- **Upload Service**:
|
||||
- `upload_file(file_path)`: 处理 94kan.cn 的文件上传。
|
||||
|
||||
## 3. 数据流向
|
||||
1. 启动浏览器 -> 建立 Context。
|
||||
2. `Secsion Service` 登录 -> 获取报表下载对象。
|
||||
3. 保存文件至 `temp_downloads/` 目录。
|
||||
4. `Upload Service` 读取该文件并上传。
|
||||
5. 关闭浏览器。
|
||||
|
||||
## 4. 异常处理策略
|
||||
- **超时处理**: 设置全局等待超时(30s)。
|
||||
- **重试机制**: 对关键点击动作进行简单重试。
|
||||
- **日志记录**: 使用 Python `logging` 模块记录每一步状态。
|
||||
|
||||
## 5. 接口契约 (伪代码)
|
||||
```python
|
||||
class SecsionService:
|
||||
def login(page, username, password): ...
|
||||
def export_report(page, date_str) -> str: ... # returns file path
|
||||
|
||||
class UploadService:
|
||||
def upload(page, file_path): ...
|
||||
```
|
||||
Reference in New Issue
Block a user