From e11e378081cac1dd733f3f6ef3cb406e00923433 Mon Sep 17 00:00:00 2001 From: "qichi.liang" Date: Mon, 29 Dec 2025 01:15:57 +0800 Subject: [PATCH] Add .env configuration for Confluence settings --- .env.example | 4 ++++ .gitignore | 4 ++++ AGENTS.md | 44 +++++++++++++++++++++++++++++++++----------- README.md | 15 +++++++++------ main.py | 18 +++++++++++++----- 5 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e75b221 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# Confluence 配置 +CONFLUENCE_BASE_URL=https://confluence.westwell-lab.com/rest/api +CONFLUENCE_TOKEN=your-token-here +CONFLUENCE_CONTENT_ID=155764524 diff --git a/.gitignore b/.gitignore index bce5504..3440a13 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,10 @@ data/daily_logs.db debug/ layout_output.txt +# Environment +.env +.env.local + # OS .DS_Store Thumbs.db diff --git a/AGENTS.md b/AGENTS.md index bb88d24..e2891ce 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,17 +9,23 @@ Python 工具,用于从 Confluence API 获取 HTML 并提取保留布局的文 ``` OrbitIn/ -├── src/ # 代码模块目录 -│ ├── __init__.py # 包初始化 -│ ├── confluence.py # Confluence API 客户端 -│ ├── extractor.py # HTML 文本提取器 -│ ├── parser.py # 日志解析器 -│ └── database.py # SQLite3 数据库操作 -├── data/ # 数据目录 -│ └── daily_logs.db # SQLite3 数据库文件 -├── fetch_and_process.py # CLI 入口 -├── AGENTS.md # AI助手文档 -└── layout_output.txt # 缓存的布局文本 +├── main.py # CLI 入口 +├── .env # 环境配置(敏感信息) +├── .env.example # 环境配置示例 +├── README.md # 项目说明 +├── AGENTS.md # AI助手文档 +├── layout_output.txt # 缓存的布局文本 +├── debug/ # 调试输出目录 +│ └── layout_output_*.txt # 带时间戳的调试文件 +├── data/ # 数据目录 +│ └── daily_logs.db # SQLite3 数据库 +└── src/ # 代码模块 + ├── __init__.py + ├── confluence.py # Confluence API 客户端 + ├── extractor.py # HTML 文本提取器 + ├── parser.py # 日志解析器 + ├── database.py # SQLite3 数据库操作 + └── report.py # 日报生成器 ``` ## 核心模块 @@ -45,6 +51,8 @@ OrbitIn/ - `query_by_ship(ship_name)` - 按船名查询 - `query_all(limit)` - 查询所有 - `get_stats()` - 获取统计信息 +- `insert_unaccounted(year_month, teu, note)` - 添加未统计数据 +- `get_unaccounted(year_month)` - 获取未统计数据 ### [`DailyReportGenerator`](src/report.py:15) - `generate_report(date)` - 生成日报 @@ -78,3 +86,17 @@ python3 main.py parse-test # 添加未统计数据 python3 main.py --unaccounted 118 --month 2025-12 ``` + +## 配置 + +在 `.env` 文件中配置 Confluence 连接信息: + +```bash +CONFLUENCE_BASE_URL=https://confluence.westwell-lab.com/rest/api +CONFLUENCE_TOKEN=your-api-token +CONFLUENCE_CONTENT_ID=155764524 +``` + +## 测试模式 + +如果设置了环境变量 `DEBUG_MODE=true`,系统会使用本地 `layout_output.txt` 文件而不是从 Confluence API 获取数据,方便离线测试。 diff --git a/README.md b/README.md index fee6ead..e99c57b 100644 --- a/README.md +++ b/README.md @@ -36,19 +36,22 @@ OrbitIn/ ### 安装依赖 ```bash -pip install requests beautifulsoup4 +pip install requests beautifulsoup4 python-dotenv ``` ### 配置 Confluence -在 `main.py` 中配置: +在 `.env` 文件中配置: -```python -CONFLUENCE_URL = "https://your-confluence.atlassian.net" -CONFLUENCE_USER = "your-email@example.com" -CONFLUENCE_API_TOKEN = "your-api-token" +```bash +# .env +CONFLUENCE_BASE_URL=https://your-confluence.atlassian.net/rest/api +CONFLUENCE_TOKEN=your-api-token +CONFLUENCE_CONTENT_ID=155764524 ``` +参考 `.env.example` 文件创建 `.env` 文件。 + ### 使用方法 ```bash diff --git a/main.py b/main.py index 2564a4b..3056934 100644 --- a/main.py +++ b/main.py @@ -14,10 +14,14 @@ from src.parser import HandoverLogParser from src.database import DailyLogsDatabase from src.report import DailyReportGenerator -# 配置 -CONF_BASE_URL = 'https://confluence.westwell-lab.com/rest/api' -CONF_TOKEN = 'NDE1NTcwMDE1ODQ0OiinqS5HLm12v2orWEYyjJcI1bl5' -CONF_CONTENT_ID = '155764524' +# 加载环境变量 +from dotenv import load_dotenv +load_dotenv() + +# 配置(从环境变量读取) +CONF_BASE_URL = os.getenv('CONFLUENCE_BASE_URL') +CONF_TOKEN = os.getenv('CONFLUENCE_TOKEN') +CONF_CONTENT_ID = os.getenv('CONFLUENCE_CONTENT_ID') DEBUG_DIR = 'debug' @@ -35,6 +39,10 @@ def get_timestamp(): def fetch_html(): """获取HTML内容""" + if not CONF_BASE_URL or not CONF_TOKEN or not CONF_CONTENT_ID: + print('错误:未配置 Confluence 信息,请检查 .env 文件') + sys.exit(1) + print('正在从 Confluence 获取 HTML 内容...') client = ConfluenceClient(CONF_BASE_URL, CONF_TOKEN) html = client.get_html(CONF_CONTENT_ID) @@ -187,7 +195,7 @@ def main(): fetch-save 获取、提取、解析并保存到数据库 fetch-debug 获取、提取并保存带时间戳的debug文件 report 生成日报(默认今天) - report-today 生成今天日报 + report-today 生成今日日报 parse-test 解析测试(使用已有的layout_output.txt) stats 显示今日统计