From afd2a98a7ff9e6f15fc128e3862ac96d31714f2d Mon Sep 17 00:00:00 2001 From: Admirepowered <1204844044@qq.com> Date: Fri, 5 Aug 2022 17:09:03 +0800 Subject: [PATCH 1/2] server mod --- README.md | 17 ++++++ server.py | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 server.py diff --git a/README.md b/README.md index 052e6df..fd07d11 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,23 @@ docker-compose logs -f 若需要添加配置文件或修改配置文件,可直接在主机config文件夹中修改,修改的内容将实时同步在容器中。 每次运行Docker容器后,容器内将自动按照参数执行签到活动,签到完成后容器将默认在每天上午9:30运行一次,如果想自行修改时间可自行编辑`docker-compose.yml`文件中的`CRON_SIGNIN`,将其修改成想运行的时间。 +## 使用python运行(screen) + +将本项目Clone至本地后,安装好依赖直接运行python3 server.py +在后台运行时请安装screen +使用screen -S automhy进入后台线程 +Ctrl+A组合键再按下d键回到主线程 +screen -r automhy回到线程 +如果不能回到线程请先screen -d automhy挂起线程 + +命令窗口如下 +stop:关闭程序 +mulit:测试多用户签到 +mod x:mod 1为单用户模式 mod 2为多用户模式 +add 'yourcookie': 直接 add cookie 添加Cookie,根据提示输入用户存档名称 +time x:设置任务巡查时间,默认720分钟(12小时) +set user enable true(设置user.json 的enable属性为true) + ## 使用云函数运行 diff --git a/server.py b/server.py new file mode 100644 index 0000000..9a36f48 --- /dev/null +++ b/server.py @@ -0,0 +1,174 @@ +#Server Mod +from code import interact +from glob import glob +import os +import time +import threading +from turtle import Turtle +import main as single +import main_multi as multi +from loghelper import log +import json +time_interval=720 #默认签到间隔时间,单位minute(分钟) +mod=1 #单用户模式/自动判断 +def runingtime(): + return int(time.time()) +def control(time_interval,mod,event): + last_time=runingtime() + while True: + now_time=runingtime() + if now_time>last_time+time_interval*60: + if mod==1: + try: + single.main() + except: + log.info("single_user start failed") + + else: + try: + multi.main_multi(True) + except: + log.info("multi_user start failed") + last_time=runingtime() + if event.is_set(): + log.info("Stoping") + break + log.info("The Next check time is {}s".format(last_time-now_time+time_interval*60)) + time.sleep(20) +def command(): + global mod + global time_interval + 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 'yourcookie'\nset user attribute value: such set username(*.json) enable(attribute) Ture(value)\ntime x:set interval time (minute)" + log.info(help) + while True: + command=input() + if command=="help" or command=="?" or command=="": + log.info(help) + if command=="stop" or command=="exit": + return False + + if command=="reload": + return True + if command=="test": + try: + single.main() + except: + log.info("single_user start failed") + if command=="single": + try: + single.main() + except: + log.info("single_user start failed") + if command=="mulit": + try: + multi.main_multi(True) + except: + log.info("multi_user start failed") + command=command.split(' ') + for i in range(0,len(command)): + if command[i]=="time": + if len(command)==2: + time_interval=int(command[1]) + log.info("switching interval to {} minute".format(mod)) + if command[i]=="mod": + if len(command)==2: + + if mod >2 or mod <0: + log.info("error mod") + else: + mod=int(command[1]) + log.info("switching mod to {}".format(mod)) + else: + log.info("Error Command") + if command[i]=="add": + if len(command)==2: + + log.info("adding") + if (mod==1): + name="config" + else: + log.info("Plase input your config name(*.json):") + name=input() + config = { + 'enable': True, 'version': 5, + 'account': { + 'cookie': command[1], + 'login_ticket': '', + '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() + else: + log.info("Error Command") + if command[i]=="set": + if len(command)==4: + file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/"+command[1]+".json" + if os.path.exists(file_path)==False: + log.info("User is not exist") + else: + with open(file_path, "r") as f: + new_conifg=json.load(f) + value=command[3] + if (command[3]=="true"): + value=True + if (command[3]=="false"): + value=False + if (command[3].isdigit()): + value=int(command[3]) + new_conifg[command[2]]=value + + file=open(file_path,'w') + file.write(json.dumps(new_conifg)) + file.close() + + +if __name__=='__main__': + log.info('Running in Server Mod') + time_interval = 720 + file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/config.json" + if os.path.exists(file_path): + mod=1 + else: + mod=2 + + while True: + log.info("switching to mod {}".format(mod)) + t1_stop = threading.Event() + thread1 = threading.Thread(name='time_check',target= control,args=(time_interval,mod,t1_stop)) + thread1.start() + + if command(): + t1_stop.set() + continue + else: + t1_stop.set() + break + + + + + + \ No newline at end of file From 6b32f1e0d6b334b8c76a599c3e3e323f6904789e Mon Sep 17 00:00:00 2001 From: Admirepowered <1204844044@qq.com> Date: Fri, 5 Aug 2022 18:01:07 +0800 Subject: [PATCH 2/2] fix --- README.md | 2 ++ server.py | 55 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index fd07d11..ff83747 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ screen -r automhy回到线程 命令窗口如下 stop:关闭程序 mulit:测试多用户签到 +single:测试多用户签到 +reload:重载配置文件 mod x:mod 1为单用户模式 mod 2为多用户模式 add 'yourcookie': 直接 add cookie 添加Cookie,根据提示输入用户存档名称 time x:设置任务巡查时间,默认720分钟(12小时) diff --git a/server.py b/server.py index 9a36f48..6f326b5 100644 --- a/server.py +++ b/server.py @@ -1,6 +1,4 @@ #Server Mod -from code import interact -from glob import glob import os import time import threading @@ -31,7 +29,7 @@ def control(time_interval,mod,event): log.info("multi_user start failed") last_time=runingtime() if event.is_set(): - log.info("Stoping") + log.info("Stoping threading") break log.info("The Next check time is {}s".format(last_time-now_time+time_interval*60)) time.sleep(20) @@ -45,6 +43,7 @@ def command(): if command=="help" or command=="?" or command=="": log.info(help) if command=="stop" or command=="exit": + log.info("Stoping Server Plase Wait") return False if command=="reload": @@ -69,7 +68,8 @@ def command(): if command[i]=="time": if len(command)==2: time_interval=int(command[1]) - log.info("switching interval to {} minute".format(mod)) + log.info("switching interval to {} minute".format(time_interval)) + return True if command[i]=="mod": if len(command)==2: @@ -81,18 +81,19 @@ def command(): else: log.info("Error Command") if command[i]=="add": - if len(command)==2: - - log.info("adding") - if (mod==1): - name="config" - else: - log.info("Plase input your config name(*.json):") - name=input() - config = { + cookie="" + for m in range(i,len(command)): + cookie+=command[m] + log.info("adding") + if (mod==1): + name="config" + else: + log.info("Plase input your config name(*.json):") + name=input() + config = { 'enable': True, 'version': 5, 'account': { - 'cookie': command[1], + 'cookie': cookie, 'login_ticket': '', 'stuid': '', 'stoken': '' @@ -117,12 +118,11 @@ def command(): } - file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/"+name+".json" - file=open(file_path,'w') - file.write(json.dumps(config)) - file.close() - else: - log.info("Error Command") + 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") if command[i]=="set": if len(command)==4: file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/"+command[1]+".json" @@ -143,7 +143,7 @@ def command(): file=open(file_path,'w') file.write(json.dumps(new_conifg)) file.close() - + return True if __name__=='__main__': log.info('Running in Server Mod') @@ -159,13 +159,16 @@ if __name__=='__main__': t1_stop = threading.Event() thread1 = threading.Thread(name='time_check',target= control,args=(time_interval,mod,t1_stop)) thread1.start() - - if command(): + try: + if command(): + t1_stop.set() + continue + else: + t1_stop.set() + break + except: t1_stop.set() continue - else: - t1_stop.set() - break