mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-02 18:43:42 +08:00
删除json版本兼容
This commit is contained in:
parent
b2d3286375
commit
44364f112a
48
config.py
48
config.py
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
|
||||||
import yaml
|
import yaml
|
||||||
from loghelper import log
|
from loghelper import log
|
||||||
|
|
||||||
@ -48,7 +47,6 @@ config_raw.update(config)
|
|||||||
path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
||||||
if os.getenv("AutoMihoyoBBS_config_path") is not None:
|
if os.getenv("AutoMihoyoBBS_config_path") is not None:
|
||||||
path = os.getenv("AutoMihoyoBBS_config_path")
|
path = os.getenv("AutoMihoyoBBS_config_path")
|
||||||
config_Path_json = f"{path}/config.json"
|
|
||||||
config_Path = f"{path}/config.yaml"
|
config_Path = f"{path}/config.yaml"
|
||||||
|
|
||||||
|
|
||||||
@ -56,52 +54,6 @@ def copy_config():
|
|||||||
return config_raw
|
return config_raw
|
||||||
|
|
||||||
|
|
||||||
def load_config_json():
|
|
||||||
with open(config_Path_json, "r") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
if data.get('version') == 5:
|
|
||||||
config_json = data
|
|
||||||
try:
|
|
||||||
config_json["mihoyobbs"]["like_post"]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
config_json["mihoyobbs"]["read_posts"] = config_json["mihoyobbs"]["read_post"]
|
|
||||||
config_json["mihoyobbs"]["like_posts"] = config_json["mihoyobbs"]["like_post"]
|
|
||||||
del config_json["mihoyobbs"]["like_post"]
|
|
||||||
del config_json["mihoyobbs"]["read_post"]
|
|
||||||
else:
|
|
||||||
log.error("config版本过低,请手动更新到基于yaml版本的新版本配置文件,更新完成后请删除json版的配置文件")
|
|
||||||
exit(1)
|
|
||||||
log.info("v5Config加载完毕")
|
|
||||||
return config_json
|
|
||||||
|
|
||||||
|
|
||||||
def update_config():
|
|
||||||
global config
|
|
||||||
global update_config_need
|
|
||||||
update_config_need = True
|
|
||||||
log.info("正在更新config....")
|
|
||||||
config_json = load_config_json()
|
|
||||||
config['account'] = config_json['account']
|
|
||||||
config['mihoyobbs'].update(config_json['mihoyobbs'])
|
|
||||||
del config['mihoyobbs']['un_like']
|
|
||||||
config['mihoyobbs']['cancel_like_posts'] = config_json['mihoyobbs']['un_like']
|
|
||||||
for i in config_json['games']['cn'].keys():
|
|
||||||
if i == 'enable':
|
|
||||||
continue
|
|
||||||
config['games']['cn'][i] = config_json['games']['cn'][i]
|
|
||||||
config['games']['os'] = config_json['games']['os']
|
|
||||||
config = config_v7_update(config)
|
|
||||||
print(config)
|
|
||||||
save_config()
|
|
||||||
log.info('config更新完毕')
|
|
||||||
if not serverless:
|
|
||||||
os.remove(config_Path_json)
|
|
||||||
else:
|
|
||||||
log.error("请本地更新一下config")
|
|
||||||
|
|
||||||
|
|
||||||
def config_v7_update(data: dict):
|
def config_v7_update(data: dict):
|
||||||
global update_config_need
|
global update_config_need
|
||||||
update_config_need = True
|
update_config_need = True
|
||||||
|
|||||||
@ -22,17 +22,6 @@ def fund_config(ext: str) -> list:
|
|||||||
def main_multi(autorun: bool):
|
def main_multi(autorun: bool):
|
||||||
log.info("AutoMihoyoBBS Multi User mode")
|
log.info("AutoMihoyoBBS Multi User mode")
|
||||||
log.info("正在搜索配置文件!")
|
log.info("正在搜索配置文件!")
|
||||||
json_config = fund_config('.json')
|
|
||||||
if len(json_config) != 0:
|
|
||||||
log.info(f'已搜索到{len(json_config)}个旧版config文件,正在进行升级')
|
|
||||||
for i in json_config:
|
|
||||||
log.info(f'开始处理{i}')
|
|
||||||
config.config_Path_json = f"{config.path}/{i}"
|
|
||||||
config.config_Path = f"{config.path}/{i[:-4]}yaml"
|
|
||||||
config.update_config()
|
|
||||||
if config.serverless:
|
|
||||||
push.push(1, "云函数环境请手动执行一下脚本更新config文件!")
|
|
||||||
exit(1)
|
|
||||||
config_list = fund_config('.yaml')
|
config_list = fund_config('.yaml')
|
||||||
if len(config_list) == 0:
|
if len(config_list) == 0:
|
||||||
log.warning("未检测到配置文件,请确认config文件夹存在.yaml后缀名的配置文件!")
|
log.warning("未检测到配置文件,请确认config文件夹存在.yaml后缀名的配置文件!")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user