diff --git a/core/__init__.py b/core/__init__.py index 1988beb..129738c 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,3 +1,3 @@ # zcbot 版本号单一事实源:web/app.py 的 FastAPI version、/healthz 返回、前端展示都引这里。 # 改版本只动这一行。 -__version__ = "0.26.4" +__version__ = "0.26.5" diff --git a/scripts/diag_wecom.py b/scripts/diag_wecom.py index c161ae6..67570f2 100644 --- a/scripts/diag_wecom.py +++ b/scripts/diag_wecom.py @@ -12,11 +12,33 @@ import os import sys -try: - from dotenv import find_dotenv, load_dotenv - load_dotenv(find_dotenv()) -except Exception: - pass +# 仓库根加入 sys.path(脚本在 scripts/ 下,直跑时 core 在上一级) +_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if _ROOT not in sys.path: + sys.path.insert(0, _ROOT) + + +def _load_env(path: str) -> None: + """加载 .env:优先 python-dotenv,没装则手动解析(只填未设置的 key)。""" + try: + from dotenv import load_dotenv + load_dotenv(path) + return + except Exception: + pass + try: + with open(path, encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + k, v = line.split("=", 1) + os.environ.setdefault(k.strip(), v.strip().strip('"').strip("'")) + except FileNotFoundError: + pass + + +_load_env(os.path.join(_ROOT, ".env")) from core.wechat import wecom