refactor: Move configuration to external config.json file
This commit is contained in:
10
config.json
Normal file
10
config.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,15 +6,31 @@ import requests
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
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 配置
|
def load_config():
|
||||||
WEBDAV_BASE = "https://chfs.ouaone.top/webdav/openclaw/backup/security/"
|
"""加载配置文件"""
|
||||||
WEBDAV_AUTH = "openclaw:Khh13579"
|
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', '')
|
||||||
|
|
||||||
# ================= 核心工具 =================
|
# ================= 核心工具 =================
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user