refactor: Move configuration to external config.json file

This commit is contained in:
OpenClaw Agent
2026-02-06 21:46:42 +00:00
parent f8cab7f1be
commit b3d6b2338d
2 changed files with 34 additions and 8 deletions

10
config.json Normal file
View File

@@ -0,0 +1,10 @@
{
"version": "v2.3.8",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=579c755e-24d2-47ae-9ca1-3ede6998327a",
"data_file": "security_data_v2.json",
"timezone_offset": "+08:00",
"webdav": {
"base": "https://chfs.ouaone.top/webdav/openclaw/backup/security/",
"auth": "openclaw:Khh13579"
}
}

View File

@@ -6,15 +6,31 @@ import requests
import sys
import subprocess
# ================= 配置 =================
VERSION = "v2.3.8"
WEBHOOK_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=579c755e-24d2-47ae-9ca1-3ede6998327a"
DATA_FILE = "security_data_v2.json"
BEIJING_TZ = timezone(timedelta(hours=8))
# ================= 配置管理 =================
# WebDAV 配置
WEBDAV_BASE = "https://chfs.ouaone.top/webdav/openclaw/backup/security/"
WEBDAV_AUTH = "openclaw:Khh13579"
def load_config():
"""加载配置文件"""
config_file = os.path.join(os.path.dirname(__file__), 'config.json')
try:
with open(config_file, 'r', encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
print(f"错误: 配置文件未找到: {config_file}")
sys.exit(1)
except json.JSONDecodeError as e:
print(f"错误: 配置文件解析失败: {e}")
sys.exit(1)
# 加载配置
CONFIG = load_config()
# 从配置文件中获取配置项
VERSION = CONFIG.get('version', '')
WEBHOOK_URL = CONFIG.get('webhook_url', '')
DATA_FILE = CONFIG.get('data_file', '')
BEIJING_TZ = timezone(timedelta(hours=8)) # 时区配置也可以从配置文件读取,此处保持不变
WEBDAV_BASE = CONFIG.get('webdav', {}).get('base', '')
WEBDAV_AUTH = CONFIG.get('webdav', {}).get('auth', '')
# ================= 核心工具 =================