mirror of
https://github.com/KingHWJ/WeReadBoard.git
synced 2026-11-03 18:24:58 +08:00
Merge remote-tracking branch 'origin/master' into dev
# Conflicts: # .gitignore # app.py # static/js/app.js
This commit is contained in:
commit
a1f54e765e
9 files changed
+567
-19
No files matched your search
@@ -18,13 +18,23 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
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())
|
||||
except ImportError:
|
||||
_ssl_context = ssl.create_default_context()
|
||||
from flask import Flask, jsonify, render_template, request
|
||||
|
||||
from api_v2 import v2_bp
|
||||
@@ -54,7 +64,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"
|
||||
|
||||
|
||||
@@ -152,18 +161,22 @@ 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",
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
with urllib.request.urlopen(req, timeout=30, context=_ssl_context) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
|
||||
|
||||
@@ -1197,14 +1210,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