mirror of
https://github.com/KingHWJ/WeReadBoard.git
synced 2026-11-03 18:24:58 +08:00
feat: 添加配置读取工具,支持从环境变量和 .env 文件加载 WEREAD_API_KEY
fix: 修复启动脚本中的 Python 解释器路径识别 style: 更新样式以支持按钮最小宽度和灵活布局 docs: 添加项目最终文档,整合各类信息与说明
This commit is contained in:
1 parent
3d5a402117
commit
92a48d14cd
9 files changed
+461
-20
No files matched your search
@@ -20,6 +20,7 @@ import json
|
||||
import os
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
@@ -27,6 +28,8 @@ from functools import wraps
|
||||
|
||||
import pymysql
|
||||
|
||||
from config_utils import get_env_value
|
||||
|
||||
try:
|
||||
import certifi
|
||||
_ssl_context = ssl.create_default_context(cafile=certifi.where())
|
||||
@@ -56,7 +59,6 @@ MYSQL_CONFIG = {
|
||||
# 微信读书 API 配置
|
||||
# ======================================================================
|
||||
WEREAD_API_URL = "https://i.weread.qq.com/api/agent/gateway"
|
||||
WEREAD_API_KEY = os.environ.get("WEREAD_API_KEY", "")
|
||||
WEREAD_SKILL_VERSION = "1.0.4"
|
||||
|
||||
|
||||
@@ -154,13 +156,17 @@ def weread_api_call(api_name, **kwargs):
|
||||
Raises:
|
||||
Exception: 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": WEREAD_SKILL_VERSION}
|
||||
body.update(kwargs)
|
||||
req = urllib.request.Request(
|
||||
WEREAD_API_URL,
|
||||
data=json.dumps(body).encode("utf-8"),
|
||||
headers={
|
||||
"Authorization": f"Bearer {WEREAD_API_KEY}",
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method="POST",
|
||||
@@ -1199,14 +1205,14 @@ def api_search(conn):
|
||||
def sync_data():
|
||||
"""运行 fetch_data.py + migrate_to_mysql.py,全量同步数据"""
|
||||
project_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
python_bin = os.path.join(
|
||||
os.path.expanduser("~"),
|
||||
".workbuddy/binaries/python/envs/default/bin/python",
|
||||
)
|
||||
python_bin = sys.executable or "python3"
|
||||
env = os.environ.copy()
|
||||
env["WEREAD_API_KEY"] = env.get("WEREAD_API_KEY", "")
|
||||
env["WEREAD_API_KEY"] = get_env_value("WEREAD_API_KEY", "")
|
||||
if not env["WEREAD_API_KEY"]:
|
||||
return jsonify({"ok": False, "error": "WEREAD_API_KEY 未设置"}), 500
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "WEREAD_API_KEY 未设置,请检查当前终端环境、项目 .env 或 ~/.zshrc",
|
||||
}), 500
|
||||
|
||||
results = {"steps": []}
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user