Fix Config Use
This commit is contained in:
parent
62bf1e0d59
commit
e587c588c5
19
config.py
19
config.py
@ -40,7 +40,8 @@ config = {
|
|||||||
path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
||||||
config_Path_json = f"{path}/config.json"
|
config_Path_json = f"{path}/config.json"
|
||||||
config_Path = f"{path}/config.yaml"
|
config_Path = f"{path}/config.yaml"
|
||||||
|
def copy_config():
|
||||||
|
return config
|
||||||
|
|
||||||
def load_config_json():
|
def load_config_json():
|
||||||
with open(config_Path_json, "r") as f:
|
with open(config_Path_json, "r") as f:
|
||||||
@ -86,23 +87,29 @@ def update_config():
|
|||||||
log.error("请本地更新一下config")
|
log.error("请本地更新一下config")
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config(p_path=None):
|
||||||
global config
|
global config
|
||||||
with open(config_Path, "r", encoding='utf-8') as f:
|
if not p_path:
|
||||||
|
p_path=config_Path
|
||||||
|
with open(p_path, "r", encoding='utf-8') as f:
|
||||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
log.info("Config加载完毕")
|
log.info("Config加载完毕")
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def save_config():
|
def save_config(p_path=None,p_config=None):
|
||||||
global serverless
|
global serverless
|
||||||
if serverless:
|
if serverless:
|
||||||
log.info("云函数执行,无法保存")
|
log.info("云函数执行,无法保存")
|
||||||
return None
|
return None
|
||||||
with open(config_Path, "w+") as f:
|
if not p_path:
|
||||||
|
p_path=config_Path
|
||||||
|
p_config=config
|
||||||
|
with open(p_path, "w+") as f:
|
||||||
try:
|
try:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
f.write(yaml.dump(config, Dumper=yaml.Dumper, sort_keys=False))
|
f.write(yaml.dump(p_config, Dumper=yaml.Dumper, sort_keys=False))
|
||||||
f.flush()
|
f.flush()
|
||||||
except OSError:
|
except OSError:
|
||||||
serverless = True
|
serverless = True
|
||||||
|
97
server.py
97
server.py
@ -1,7 +1,8 @@
|
|||||||
# Server Mod
|
# Server Mod
|
||||||
import os
|
import os
|
||||||
import json
|
#import json
|
||||||
import time
|
import time
|
||||||
|
import config
|
||||||
import threading
|
import threading
|
||||||
import main as single
|
import main as single
|
||||||
import main_multi as multi
|
import main_multi as multi
|
||||||
@ -20,6 +21,7 @@ def control(time_interval, mod, event, detal):
|
|||||||
while True:
|
while True:
|
||||||
now_time = runingtime()
|
now_time = runingtime()
|
||||||
if now_time > last_time + time_interval * 60:
|
if now_time > last_time + time_interval * 60:
|
||||||
|
last_time = runingtime()
|
||||||
if mod == 1:
|
if mod == 1:
|
||||||
try:
|
try:
|
||||||
single.main()
|
single.main()
|
||||||
@ -31,7 +33,6 @@ def control(time_interval, mod, event, detal):
|
|||||||
multi.main_multi(True)
|
multi.main_multi(True)
|
||||||
except:
|
except:
|
||||||
log.info("multi_user start failed")
|
log.info("multi_user start failed")
|
||||||
last_time = runingtime()
|
|
||||||
if event.is_set():
|
if event.is_set():
|
||||||
log.info("Stoping threading")
|
log.info("Stoping threading")
|
||||||
break
|
break
|
||||||
@ -44,17 +45,17 @@ def command(detal):
|
|||||||
global mod
|
global mod
|
||||||
global time_interval
|
global time_interval
|
||||||
global show
|
global show
|
||||||
show = False # 显示倒计时信息
|
#show = False # 显示倒计时信息
|
||||||
if show:
|
#if show:
|
||||||
detal.set()
|
# detal.set()
|
||||||
help = "command windows\nstop:stop server\nreload:reload config and refish tiem\nsingle:test single " \
|
help = "command windows\nstop:stop server\nreload:reload config and refish tiem\nsingle:test single " \
|
||||||
"config\nmulit:test mulit conifg\nmod x:x is refer single or multi 1 is single 2 is multi\nadd " \
|
"config\nmulit:test mulit conifg\nmod x:x is refer single or multi, 1 is single, 2 is multi\nadd " \
|
||||||
"'yourcookie'\nset user attribute value: such set username(*.json) enable(attribute) Ture(value)\ntime " \
|
"'yourcookie'\nset user attribute value: such set username(*.yaml) enable(attribute) Ture(value)\ntime " \
|
||||||
"x:set interval time (minute)\nshow true/false:show the time count "
|
"x:set interval time (minute)\nshow true/false:show the time count "
|
||||||
log.info(help)
|
log.info(help)
|
||||||
while True:
|
while True:
|
||||||
command = input()
|
command = input()
|
||||||
if command == "help" or command == "?" or command == "":
|
if command == "help" or command == "exit" or command == "?" or command == "":
|
||||||
log.info(help)
|
log.info(help)
|
||||||
if command == "stop" or command == "exit":
|
if command == "stop" or command == "exit":
|
||||||
log.info("Stoping Server Plase Wait")
|
log.info("Stoping Server Plase Wait")
|
||||||
@ -63,10 +64,16 @@ def command(detal):
|
|||||||
if command == "reload":
|
if command == "reload":
|
||||||
return True
|
return True
|
||||||
if command == "test":
|
if command == "test":
|
||||||
|
if mod==1:
|
||||||
try:
|
try:
|
||||||
single.main()
|
single.main()
|
||||||
except:
|
except:
|
||||||
log.info("single_user start failed")
|
log.info("single_user start failed")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
multi.main_multi(True)
|
||||||
|
except:
|
||||||
|
log.info("multi_user start failed")
|
||||||
if command == "single":
|
if command == "single":
|
||||||
try:
|
try:
|
||||||
single.main()
|
single.main()
|
||||||
@ -98,13 +105,11 @@ def command(detal):
|
|||||||
if len(command) == 2:
|
if len(command) == 2:
|
||||||
|
|
||||||
if command[1] == "true":
|
if command[1] == "true":
|
||||||
show = True
|
|
||||||
detal.set()
|
detal.set()
|
||||||
log.info("switching to detail mod")
|
log.info("switching to detail mod")
|
||||||
|
|
||||||
if command[1] == "false":
|
if command[1] == "false":
|
||||||
detal.unset()
|
detal.clear()
|
||||||
show = False
|
|
||||||
log.info("switching to slient mod")
|
log.info("switching to slient mod")
|
||||||
|
|
||||||
|
|
||||||
@ -112,54 +117,34 @@ def command(detal):
|
|||||||
log.info("Error Command")
|
log.info("Error Command")
|
||||||
if command[i] == "add":
|
if command[i] == "add":
|
||||||
cookie = ""
|
cookie = ""
|
||||||
for m in range(i, len(command)):
|
for m in range(i+1, len(command)):
|
||||||
cookie += command[m]
|
cookie += command[m]
|
||||||
log.info("adding")
|
log.info("adding")
|
||||||
if mod == 1:
|
if mod == 1:
|
||||||
name = "config"
|
name = "config"
|
||||||
else:
|
else:
|
||||||
log.info("Plase input your config name(*.json):")
|
log.info("Plase input your config name(*.yaml):")
|
||||||
name = input()
|
name = input()
|
||||||
config = {
|
new_config = config.copy_config()
|
||||||
'enable': True, 'version': 5,
|
new_config['account']['cookie']=cookie
|
||||||
'account': {
|
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/" + name + ".yaml"
|
||||||
'cookie': cookie,
|
try:
|
||||||
'login_ticket': '',
|
config.save_config(file_path,new_config)
|
||||||
'stuid': '',
|
|
||||||
'stoken': ''
|
|
||||||
},
|
|
||||||
'mihoyobbs': {
|
|
||||||
'enable': True, 'checkin': True, 'checkin_multi': True, 'checkin_multi_list': [2, 5],
|
|
||||||
'read_posts': True, 'like_posts': True, 'un_like': True, 'share_post': True
|
|
||||||
},
|
|
||||||
'games': {
|
|
||||||
'cn': {
|
|
||||||
'enable': True,
|
|
||||||
'genshin': {'auto_checkin': True, 'black_list': []},
|
|
||||||
'hokai2': {'auto_checkin': False, 'black_list': []},
|
|
||||||
'honkai3rd': {'auto_checkin': False, 'black_list': []},
|
|
||||||
'tears_of_themis': {'auto_checkin': False, 'black_list': []},
|
|
||||||
},
|
|
||||||
'os': {
|
|
||||||
'enable': False, 'cookie': '',
|
|
||||||
'genshin': {'auto_checkin': False, 'black_list': []}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/" + name + ".json"
|
|
||||||
file = open(file_path, 'w')
|
|
||||||
file.write(json.dumps(config))
|
|
||||||
file.close()
|
|
||||||
log.info("Saving OK")
|
log.info("Saving OK")
|
||||||
|
except:
|
||||||
|
log.info('Saving failed,plase check your file system')
|
||||||
|
#file = open(file_path, 'w')
|
||||||
|
#file.write(json.dumps(config))
|
||||||
|
#file.close()
|
||||||
|
|
||||||
if command[i] == "set":
|
if command[i] == "set":
|
||||||
if len(command) == 4:
|
if len(command) == 4:
|
||||||
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/" + command[1] + ".json"
|
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/" + command[1] + ".yaml"
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
log.info("User is not exist")
|
log.info("User is not exist")
|
||||||
else:
|
else:
|
||||||
with open(file_path, "r") as f:
|
new_config = config.load_config(file_path)
|
||||||
new_conifg = json.load(f)
|
#json.load(f)
|
||||||
value = command[3]
|
value = command[3]
|
||||||
if command[3] == "true":
|
if command[3] == "true":
|
||||||
value = True
|
value = True
|
||||||
@ -167,18 +152,22 @@ def command(detal):
|
|||||||
value = False
|
value = False
|
||||||
if command[3].isdigit():
|
if command[3].isdigit():
|
||||||
value = int(command[3])
|
value = int(command[3])
|
||||||
new_conifg[command[2]] = value
|
new_config[command[2]] = value
|
||||||
|
try:
|
||||||
file = open(file_path, 'w')
|
config.save_config(file_path,new_config)
|
||||||
file.write(json.dumps(new_conifg))
|
log.info("Saving OK")
|
||||||
file.close()
|
except:
|
||||||
|
log.info('Saving failed,plase check your file system')
|
||||||
|
#file = open(file_path, 'w')
|
||||||
|
#file.write(json.dumps(new_conifg))
|
||||||
|
#file.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
log.info('Running in Server Mod')
|
log.info('Running in Server Mod')
|
||||||
time_interval = 720
|
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/config.yaml"
|
||||||
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/config.json"
|
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
mod = 1
|
mod = 1
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user