feat: 添加配置读取工具,支持从环境变量和 .env 文件加载 WEREAD_API_KEY

fix: 修复启动脚本中的 Python 解释器路径识别
style: 更新样式以支持按钮最小宽度和灵活布局
docs: 添加项目最终文档,整合各类信息与说明
This commit is contained in:
admin committed 2026-07-17 22:11:27 +08:00
1 parent 3d5a402117
commit 92a48d14cd
9 files changed
+461 -20

No files matched your search

+9 -4
View File
@@ -26,9 +26,10 @@ import time
import urllib.request
from datetime import datetime, timezone, timedelta
from config_utils import get_env_value
# ===== 配置 =====
API_URL = "https://i.weread.qq.com/api/agent/gateway"
API_KEY = os.environ.get("WEREAD_API_KEY", "")
SKILL_VERSION = "1.0.4"
DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "weread.db")
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -54,13 +55,17 @@ def now_str():
def api_call(api_name, **kwargs):
"""调用微信读书 API"""
api_key = get_env_value("WEREAD_API_KEY", "")
if not api_key:
raise RuntimeError("WEREAD_API_KEY 未设置,请检查当前终端环境、项目 .env 或 ~/.zshrc")
body = {"api_name": api_name, "skill_version": SKILL_VERSION}
body.update(kwargs)
req = urllib.request.Request(
API_URL,
data=json.dumps(body).encode("utf-8"),
headers={
"Authorization": f"Bearer {API_KEY}",
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
method="POST",
@@ -1020,9 +1025,9 @@ def fetch_notebooks(conn):
# ===== 主函数 =====
def main():
if not API_KEY:
if not get_env_value("WEREAD_API_KEY", ""):
print("错误: 请先设置 WEREAD_API_KEY 环境变量")
print(" export WEREAD_API_KEY=wrk-xxxxxxxx")
print(" 可配置在当前终端、项目 .env,或 ~/.zshrc")
return
print("=" * 60)