feat: 添加 weread 启停命令 & 修复 macOS SSL 证书问题

- 新增 weread CLI 脚本,支持 weread start/stop [port] 一键管理服务
- app.py 端口改为从环境变量 WEREAD_PORT 读取,默认 8080
- 修复 macOS Python urllib 调用微信读书 API 时 SSL 证书验证失败问题(引入 certifi)
This commit is contained in:
admin committed 2026-07-17 14:34:35 +08:00
1 parent c3f5c0ff03
commit 5608562f02
2 files changed
+113 -3

No files matched your search

+11 -3
View File
@@ -18,6 +18,7 @@
import json
import os
import ssl
import subprocess
import time
import urllib.request
@@ -25,6 +26,12 @@ from datetime import datetime
from functools import wraps
import pymysql
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
# ======================================================================
@@ -158,7 +165,7 @@ def weread_api_call(api_name, **kwargs):
},
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"))
@@ -1270,5 +1277,6 @@ if __name__ == "__main__":
else:
print(f"[信息] {msg}")
# 启动 Flask 服务,监听 8080 端口
app.run(host="0.0.0.0", port=8080, debug=False)
# 启动 Flask 服务,端口从环境变量 WEREAD_PORT 读取,默认 8080
port = int(os.environ.get("WEREAD_PORT", 8080))
app.run(host="0.0.0.0", port=port, debug=False)