From b3d6b2338d59aab01f62e1a25a4a8d304923d841 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Fri, 6 Feb 2026 21:46:42 +0000 Subject: [PATCH] refactor: Move configuration to external config.json file --- config.json | 10 ++++++++++ update_security_ranking_v2.py | 32 ++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..db35f2c --- /dev/null +++ b/config.json @@ -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" + } +} diff --git a/update_security_ranking_v2.py b/update_security_ranking_v2.py index ca44c25..25c7bc2 100644 --- a/update_security_ranking_v2.py +++ b/update_security_ranking_v2.py @@ -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', '') # ================= 核心工具 =================