Finance Report Analyzer
Generate financial analysis reports from uploaded Excel/PDF files with inline SVG sparkline trend charts and multi-format output.
Quick Start
CODEBLOCK0
Output Formats
INLINECODE0 flag controls output. HTML is always generated as the base; other formats convert from HTML.
| Flag | Output | Requires |
|---|
| INLINECODE1 | HTML only | (built-in) |
| INLINECODE2 |
HTML + PDF (default) | wkhtmltopdf or chromium |
|
-o doc | HTML + DOCX | pandoc |
|
-o md | HTML + Markdown | pandoc or markdownify |
Workflow
Step 1: Acquire Data File
Try in order:
- 1. Feishu chat file attachment — Download via API:
# Get token
TOKEN=$(curl -s -X POST 'https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal' \
-H 'Content-Type: application/json' \
-d '{"app_id":"APP_ID","app_secret":"APP_SECRET"}' | python3 -c "import json,sys; print(json.load(sys.stdin)['tenant_access_token'])")
# Get file_key from message
curl -s "https://open.feishu.cn/open-apis/im/v1/messages/{message_id}" -H "Authorization: Bearer $TOKEN"
# Download
curl -s "https://open.feishu.cn/open-apis/im/v1/messages/{message_id}/resources/{file_key}?type=file" \
-H "Authorization: Bearer $TOKEN" -o /tmp/data.xlsx
Get app credentials: read
channels.feishu.appId/
appSecret from openclaw.json.
- 2. Feishu Doc/Bitable link — Use feishudoc/feishubitable tools
- Local file — Use directly
- Pasted text — Parse and save as xlsx
Step 2: Generate Report
CODEBLOCK2
Step 3: Web Search Enhancement (Optional)
Search for industry benchmarks:
CODEBLOCK3
Step 4: Deliver File via Feishu API
The message tool may send paths as text. Use direct Feishu API to send real file messages:
CODEBLOCK4
Report Features
- - Sparkline trend charts: Each metric row has an inline SVG showing the trend (solid=actual, dashed=forecast)
- Forecast markers: Predicted values marked with ⟡ symbol and yellow background
- Color coding: Green=positive, Red=negative
- Responsive: Works on mobile and desktop
- Print-ready: CSS print styles included
Metric Definitions
See references/metrics.md for financial metric calculations.
财务报告分析器
从上传的Excel/PDF文件生成财务分析报告,包含内联SVG迷你趋势图和多格式输出。
快速开始
bash
python3 scripts/generate_report.py input.xlsx -o pdf --company 公司名 --ticker 000001.SZ
输出格式
-o 参数控制输出格式。HTML始终作为基础格式生成;其他格式由HTML转换而来。
| 参数 | 输出 | 依赖 |
|---|
| -o html | 仅HTML | (内置) |
| -o pdf |
HTML + PDF (默认) | wkhtmltopdf 或 chromium |
| -o doc | HTML + DOCX | pandoc |
| -o md | HTML + Markdown | pandoc 或 markdownify |
工作流程
第一步:获取数据文件
按顺序尝试:
- 1. 飞书聊天文件附件 — 通过API下载:
bash
# 获取令牌
TOKEN=$(curl -s -X POST https://open.feishu.cn/open-apis/auth/v3/tenant
accesstoken/internal \
-H Content-Type: application/json \
-d {app
id:APPID,app
secret:APPSECRET} | python3 -c import json,sys; print(json.load(sys.stdin)[tenant
accesstoken]))
# 从消息中获取file_key
curl -s https://open.feishu.cn/open-apis/im/v1/messages/{message_id} -H Authorization: Bearer $TOKEN
# 下载
curl -s https://open.feishu.cn/open-apis/im/v1/messages/{message
id}/resources/{filekey}?type=file \
-H Authorization: Bearer $TOKEN -o /tmp/data.xlsx
获取应用凭证:从openclaw.json中读取channels.feishu.appId/appSecret。
- 2. 飞书文档/多维表格链接 — 使用feishudoc/feishubitable工具
- 本地文件 — 直接使用
- 粘贴文本 — 解析并保存为xlsx
第二步:生成报告
bash
python3 scripts/generate_report.py /tmp/data.xlsx -o pdf \
--company 百济神州-U --ticker 688235.SH --output-dir /tmp/reports
第三步:网络搜索增强(可选)
搜索行业基准:
web_search({company} 行业对比 市场份额 {year})
第四步:通过飞书API发送文件
message工具可能将路径作为文本发送。使用飞书API直接发送真实文件消息:
bash
1. 上传文件获取file_key
UPLOAD=$(curl -s -X POST https://open.feishu.cn/open-apis/im/v1/files \
-H Authorization: Bearer $TOKEN \
-F file_type=stream \
-F file_name=report.html \
-F file=@/path/to/report.html)
FILE
KEY=$(echo $UPLOAD | python3 -c import json,sys; print(json.load(sys.stdin)[data][filekey]))
2. 向聊天发送文件消息
curl -s -X POST https://open.feishu.cn/open-apis/im/v1/messages?receive
idtype=chat_id \
-H Authorization: Bearer $TOKEN \
-H Content-Type: application/json \
-d {\receive
id\:\CHATID\,\msg
type\:\file\,\content\:\{\\\filekey\\\:\\\$FILE_KEY\\\}\}
报告特性
- - 迷你趋势图:每个指标行包含内联SVG趋势图(实线=实际值,虚线=预测值)
- 预测标记:预测值以⟡符号和黄色背景标记
- 颜色编码:绿色=正面,红色=负面
- 响应式设计:支持移动端和桌面端
- 打印就绪:包含CSS打印样式
指标定义
财务指标计算方法请参见 references/metrics.md。