feat: 新增企微 Delta 模式相关配置读取函数
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,13 +3,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
BOT_DIR = ROOT / "bot"
|
||||
OUTPUT_DIR = ROOT / "output"
|
||||
LOG_DIR = ROOT / "logs"
|
||||
CACHE_DIR = ROOT / ".cache"
|
||||
@@ -45,16 +43,11 @@ def wecom_max_bytes() -> int:
|
||||
"""兼容旧配置名。"""
|
||||
return wecom_chunk_bytes()
|
||||
|
||||
|
||||
load_dotenv(ROOT / ".env")
|
||||
load_dotenv(ROOT / ".env.local", override=True)
|
||||
|
||||
|
||||
def ensure_bot_on_path() -> None:
|
||||
bot = str(BOT_DIR)
|
||||
if bot not in sys.path:
|
||||
sys.path.insert(0, bot)
|
||||
|
||||
|
||||
def _clean_env_value(raw: str | None) -> str | None:
|
||||
if raw is None:
|
||||
return None
|
||||
@@ -79,3 +72,32 @@ def env_int(key: str, default: int) -> int:
|
||||
return int(raw)
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
|
||||
def env_bool(key: str, default: bool) -> bool:
|
||||
raw = env(key)
|
||||
if raw is None:
|
||||
return default
|
||||
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def wecom_mode() -> str:
|
||||
raw = (env("DAILY_WECOM_MODE") or "delta").strip().lower()
|
||||
return raw if raw in {"full", "delta"} else "delta"
|
||||
|
||||
|
||||
def news_dedup_days() -> int:
|
||||
return max(1, env_int("DAILY_NEWS_DEDUP_DAYS", 7))
|
||||
|
||||
|
||||
def skip_push_when_silent() -> bool:
|
||||
return env_bool("DAILY_SKIP_PUSH_WHEN_SILENT", True)
|
||||
|
||||
|
||||
def delta_baseline_fallback() -> str:
|
||||
raw = (env("DAILY_DELTA_BASELINE_FALLBACK") or "full").strip().lower()
|
||||
return raw if raw in {"full", "empty"} else "full"
|
||||
|
||||
|
||||
def force_push() -> bool:
|
||||
return env_bool("DAILY_FORCE_PUSH", False)
|
||||
|
||||
Reference in New Issue
Block a user