LoL History API
这是一个用于《英雄联盟》战绩查询和数据分析的 Python 项目。它支持 League Client(LCU)、SGP和 HTTP API,并提供 Python SDK、趋势分析、只读分享页面和可选的 AI 教练分析。
当前版本:0.6.1
功能
- 获取玩家信息、段位和最近对局。
- 使用 SQLite 持久化历史战绩。
- 按时间窗口分页获取历史对局并自动去重。
- 支持全部、排位、海克斯大乱斗、斗魂竞技场、普通和其他模式。
- 提供胜率、每日表现、英雄池和位置分布分析。
- 生成无需额外点击的只读分享链接。
- 可选接入 DeepSeek,生成 AI 教练总结和训练计划。
- 提供同步 Python SDK,方便机器人或其他应用调用。
项目结构
lol-history-api/
|-- lol_history_api/
| |-- api/ # HTTP routes and validation
| |-- application/ # Application services and use cases
| |-- config/ # Environment variables and defaults
| |-- domain/ # Trends, modes, and match analysis
| |-- infrastructure/ # LCU, SGP, AI, and SQLite
| |-- sdk/ # Python SDK
| `-- web/ # Dashboard and read-only pages
|-- tests/ # Automated tests
|-- Scripts/ # Startup and release scripts
|-- docs/ # Chinese documentation
|-- .env.example # Configuration template
|-- pyproject.toml # Package metadata and CLI entry
|-- start.bat # Windows one-click startup
`-- README.md
The project is layered as HTTP API -> application -> domain -> infrastructure for easier parallel development.
环境要求
- Python 3.10 或更高版本。
- Windows 10/11(需要读取本机 League Client 时)。
- League Client 已启动并登录,才能查询真实 LCU 数据。
- Linux 云服务器可以部署 API、Nginx 和分享页面,但不能替代 League Client。
安装
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"
Copy-Item .env.example .env
环境变量
.env 只保存在本地或服务器安全目录中,禁止提交到 GitHub。
| 变量 | 说明 |
|---|---|
LOL_LCU_BRIDGE_HOST |
API 监听地址,默认 127.0.0.1 |
LOL_LCU_BRIDGE_PORT |
API 监听端口,默认 18181 |
LOL_LCU_BRIDGE_TOKEN |
非本机监听时必需的 Token |
LOL_HISTORY_DB_PATH |
SQLite 数据库路径 |
LOL_HISTORY_PUBLIC_BASE_URL |
生成分享链接时使用的公网基础地址 |
DEEPSEEK_API_KEY |
可选,启用 AI 分析时使用 |
CVM_HOST |
云服务器地址,仅部署脚本使用 |
CVM_ROOT |
云服务器账户,仅部署脚本使用 |
CVM_SSH_KEY |
SSH 私钥路径,仅部署脚本使用 |
PYPI_TOKEN |
PyPI 发布 Token,仅发布脚本使用 |
启动
在项目根目录双击 start.bat,或执行:
.\Scripts\start_api.ps1
显式指定监听地址:
.\Scripts\start_api.ps1 `
-BindAddress 100.107.221.69 `
-Port 18181
PyPI 安装后:
python -m pip install lol-history-api==0.6.1
lol-history-api
API 接口
GET /health
GET /lol/regions
GET /lol/player
GET /lol/history
GET /lol/trends
POST /lol/trends/share
GET /shared/{share_id}
GET /ai/status
GET /lol/coach/ai
趋势查询示例:
GET /lol/trends?game_name=Player&tag_line=1234®ion=HN10&days=30&mode=ranked
mode 支持:all、ranked、aram、arena、normal 和 other。
趋势刷新会按页获取历史对局,直到覆盖指定时间窗口或上游没有更多数据,并通过 game_id 自动去重。
Python SDK
from lol_history_api import LoLHistoryClient
client = LoLHistoryClient("http://127.0.0.1:18181", "your-bridge-token")
report = client.trends("Player", "1234", region="HN10", mode="ranked", days=30)
share = client.create_trend_share(
"Player", "1234", region="HN10", mode="ranked",
days=30, refresh=True, include_ai=True,
)
print(share["url"])
分享链接是只读快照,打开后直接展示完整报告。
多人协作
推荐分支结构:
main 稳定版本和生产发布
develop 日常集成
feature/* 新功能
fix/* 问题修复
docs/* 文档修改
git checkout develop
git pull
git checkout -b feature/your-feature
python -B -m pytest tests -q
python -B -m compileall -q lol_history_api
GitHub Actions 会自动执行测试。详细规范见 CONTRIBUTING.md。
云服务器部署
建议使用独立目录 /opt/lol-history-api/,不要与 QQBot 共用目录、虚拟环境或数据库。
Nginx :18080
127.0.0.1:18181
lol-history-api systemd service
服务器上的 .env、Token、AI Key、SSH 私钥和 SQLite 数据库都不进入 Git 仓库。
测试与发布
python -B -m pytest tests -q
python -m build
python -m twine check dist/*
在 .env 中配置 PYPI_TOKEN 后,运行 Scripts/publish_pypi.bat 发布。
安全注意
- 不要提交
.env、SQLite 数据库、日志、构建产物和真实 Token。 - 不要在 Issue、Pull Request 或聊天中发送 AI Key、SSH 私钥和服务器密码。
- 不要让所有开发者共用 root 密码。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lol_history_api-0.6.2.tar.gz.
File metadata
- Download URL: lol_history_api-0.6.2.tar.gz
- Upload date:
- Size: 84.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2722e36643666dfe5cbc6d38b6f9017be363ba66cb5204539cde6c581b55489f
|
|
| MD5 |
21b9fee16c69794a0350880ad6e2a450
|
|
| BLAKE2b-256 |
ad7955499d98d1f6a42b3360883ad30384042331a00f7556dc4ad6519943f780
|
File details
Details for the file lol_history_api-0.6.2-py3-none-any.whl.
File metadata
- Download URL: lol_history_api-0.6.2-py3-none-any.whl
- Upload date:
- Size: 90.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36d9ab8a80dd3ab028944fffee077dfaf2099b95c7c9c7f53ebdeee5e2ce017c
|
|
| MD5 |
7a7225f450e8c174a65d6d4468661c19
|
|
| BLAKE2b-256 |
1c2292ce58a2f087968c95a9256500773ebdb80edd0cbc9bd397b07cb4fa21b8
|