diff --git a/common/config.py b/common/config.py index a52f58d..8ad7991 100644 --- a/common/config.py +++ b/common/config.py @@ -26,7 +26,7 @@ local_data = threading.local() def get_data_connection(): # 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象 if not hasattr(local_data, 'connection'): - local_data.connection = sqlite3.connect('data.db') + local_data.connection = sqlite3.connect('./data/data.db') return local_data.connection @@ -37,7 +37,7 @@ local_cache = threading.local() def get_cache_connection(): # 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象 if not hasattr(local_cache, 'connection'): - local_cache.connection = sqlite3.connect('cache.db') + local_cache.connection = sqlite3.connect('./data/cache.db') return local_cache.connection @@ -320,7 +320,7 @@ default = { def handle_default_config(): - with open("./config.json", "w", encoding="utf-8") as f: + with open("./data/config.json", "w", encoding="utf-8") as f: f.write(json.dumps(default, indent=2, ensure_ascii=False, escape_forward_slashes=False)) f.close() @@ -512,7 +512,7 @@ def push_to_list(key, obj): def write_config(key, value): config = None - with open('config.json', 'r', encoding='utf-8') as f: + with open('./data/config.json', 'r', encoding='utf-8') as f: config = json.load(f) keys = key.split('.') @@ -524,7 +524,7 @@ def write_config(key, value): current[keys[-1]] = value variable.config = config - with open('config.json', 'w', encoding='utf-8') as f: + with open('./data/config.json', 'w', encoding='utf-8') as f: json.dump(config, f, indent=2, ensure_ascii=False, escape_forward_slashes=False) f.close() @@ -621,18 +621,18 @@ def write_data(key, value): def initConfig(): try: - with open("./config.json", "r", encoding="utf-8") as f: + with open("./data/config.json", "r", encoding="utf-8") as f: try: variable.config = json.loads(f.read()) if (not isinstance(variable.config, dict)): logger.warning('配置文件并不是一个有效的字典,使用默认值') variable.config = default - with open("./config.json", "w", encoding="utf-8") as f: + with open("./data/config.json", "w", encoding="utf-8") as f: f.write(json.dumps(variable.config, indent=2, ensure_ascii=False, escape_forward_slashes=False)) f.close() except: - if os.path.getsize("./config.json") != 0: + if os.path.getsize("./data/config.json") != 0: logger.error("配置文件加载失败,请检查是否遵循JSON语法规范") sys.exit(1) else: