mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-10 14:12:31 +08:00
代码优化
This commit is contained in:
parent
8eccadae3a
commit
863dd718d0
@ -72,8 +72,8 @@ def save_config():
|
||||
data["mihoyobbs_Stoken"] = mihoyobbs_Stoken
|
||||
f.seek(0)
|
||||
f.truncate()
|
||||
temp_Text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
|
||||
f.write(temp_Text)
|
||||
temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
|
||||
f.write(temp_text)
|
||||
f.flush()
|
||||
f.close()
|
||||
log.info("Config保存完毕")
|
||||
@ -89,9 +89,8 @@ def clear_cookies():
|
||||
data["mihoyobbs_Cookies"] = ""
|
||||
f.seek(0)
|
||||
f.truncate()
|
||||
temp_Text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
|
||||
f.write(temp_Text)
|
||||
temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
|
||||
f.write(temp_text)
|
||||
f.flush()
|
||||
f.close()
|
||||
log.info("Cookie删除完毕")
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ from crontab import CronTab
|
||||
|
||||
time_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
def stop_me(_signo, _stack):
|
||||
log.info("Docker container has stoped....")
|
||||
exit(-1)
|
||||
|
||||
@ -74,7 +74,8 @@ class Genshin:
|
||||
json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]})
|
||||
data = req.json()
|
||||
if data["retcode"] == 0:
|
||||
log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}")
|
||||
log.info("旅行者{i[0]}签到成功~\r\n今天获得的奖励是"
|
||||
f"{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}")
|
||||
sign_days += 1
|
||||
elif data["retcode"] == -5003:
|
||||
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
||||
|
||||
11
login.py
11
login.py
@ -1,6 +1,6 @@
|
||||
import config
|
||||
import request
|
||||
import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
|
||||
@ -12,16 +12,17 @@ def login():
|
||||
raise CookieError('No cookie')
|
||||
# 判断Cookie里面是否有login_ticket 没有的话直接退了
|
||||
if "login_ticket" in config.mihoyobbs_Cookies:
|
||||
temp_Cookies = config.mihoyobbs_Cookies.split(";")
|
||||
for i in temp_Cookies:
|
||||
temp_cookies = config.mihoyobbs_Cookies.split(";")
|
||||
for i in temp_cookies:
|
||||
if i.split("=")[0] == " login_ticket":
|
||||
config.mihoyobbs_Login_ticket = i.split("=")[1]
|
||||
break
|
||||
# 这里获取Stuid,但是实际是可以直接拿cookie里面的Uid
|
||||
data = request.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket))
|
||||
data = http.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket)).json()
|
||||
if "成功" in data["data"]["msg"]:
|
||||
config.mihoyobbs_Stuid = str(data["data"]["cookie_info"]["account_id"])
|
||||
data = request.get(url=setting.bbs_Cookie_url2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid))
|
||||
data = http.get(url=setting.bbs_Cookie_url2.format(
|
||||
config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid)).json()
|
||||
config.mihoyobbs_Stoken = data["data"]["list"][0]["token"]
|
||||
log.info("登录成功!")
|
||||
log.info("正在保存Config!")
|
||||
|
||||
@ -32,7 +32,7 @@ def main_multi(autorun: bool):
|
||||
log.info(f"已搜索到{len(config_list)}个配置文件,请确认是否无多余文件!\r\n{config_list}")
|
||||
try:
|
||||
input("请输入回车继续,需要重新搜索配置文件请Ctrl+C退出脚本")
|
||||
except:
|
||||
except KeyboardInterrupt:
|
||||
exit(0)
|
||||
results = {"ok": [], "close": [], "error": []}
|
||||
for i in iter(config_list):
|
||||
@ -51,7 +51,8 @@ def main_multi(autorun: bool):
|
||||
log.info(f"{i}执行完毕")
|
||||
time.sleep(random.randint(3, 10))
|
||||
print("")
|
||||
push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,没执行{len(results["close"])}个,失败{len(results["error"])}个'\
|
||||
push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,' \
|
||||
f'没执行{len(results["close"])}个,失败{len(results["error"])}个' \
|
||||
f'\r\n没执行的配置文件: {results["close"]}\r\n执行失败的配置文件: {results["error"]}'
|
||||
log.info(push_message)
|
||||
push.push(0, push_message)
|
||||
|
||||
32
request.py
32
request.py
@ -5,39 +5,13 @@ try:
|
||||
http = httpx.Client(timeout=10, transport=httpx.HTTPTransport(retries=5))
|
||||
# 当openssl版本小于1.0.2的时候直接进行一个空请求让httpx报错
|
||||
import tools
|
||||
|
||||
if tools.get_openssl_version() <= 102:
|
||||
httpx.get()
|
||||
except:
|
||||
except (TypeError, ModuleNotFoundError):
|
||||
import requests
|
||||
from requests.adapters import HTTPAdapter
|
||||
|
||||
http = requests.Session()
|
||||
http.mount('http://', HTTPAdapter(max_retries=5))
|
||||
http.mount('https://', HTTPAdapter(max_retries=5))
|
||||
|
||||
|
||||
# 这里实际上应该加个"-> dict"但是考虑到请求可能失败的关系,所以直接不声明返回变量
|
||||
def get(url: str, **headers: dict):
|
||||
try:
|
||||
req = http.get(url, headers=headers)
|
||||
return req.json()
|
||||
except:
|
||||
print("请求失败,网络错误!")
|
||||
return ""
|
||||
|
||||
|
||||
def post(url: str, data: dict, **headers: dict):
|
||||
try:
|
||||
req = http.post(url, data=data, headers=headers)
|
||||
return req.json()
|
||||
except:
|
||||
print("请求失败,网络错误!")
|
||||
return ""
|
||||
|
||||
|
||||
def post_json(url: str, json, **headers: dict):
|
||||
try:
|
||||
req = http.post(url, json=json, headers=headers)
|
||||
return req.json()
|
||||
except:
|
||||
print("请求失败,网络错误!")
|
||||
return ""
|
||||
|
||||
@ -73,13 +73,13 @@ honkai2_Sign_url = web_Api + "/event/luna/sign"
|
||||
|
||||
# 崩坏3自动签到相关的设置
|
||||
honkai3rd_Act_id = "ea20211026151532"
|
||||
honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除
|
||||
honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除
|
||||
honkai3rd_Is_signurl = web_Api + "/common/eutheniav2/index?act_id={}®ion={}&uid={}"
|
||||
honkai3rd_SignUrl = web_Api + "/common/eutheniav2/sign"
|
||||
|
||||
# 原神自动签到相关的设置
|
||||
genshin_Act_id = "e202009291139501"
|
||||
genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除
|
||||
genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除
|
||||
genshin_Signlisturl = web_Api + "/event/bbs_sign_reward/home?act_id={}"
|
||||
genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}"
|
||||
genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign"
|
||||
|
||||
6
tools.py
6
tools.py
@ -53,10 +53,10 @@ def get_item(raw_data: dict) -> str:
|
||||
|
||||
|
||||
# 获取明天早晨0点的时间戳
|
||||
def nextday() -> int:
|
||||
def next_day() -> int:
|
||||
now_time = int(time.time())
|
||||
nextday_time = now_time - now_time % 86400 + time.timezone + 86400
|
||||
return nextday_time
|
||||
next_day_time = now_time - now_time % 86400 + time.timezone + 86400
|
||||
return next_day_time
|
||||
|
||||
|
||||
# 获取Openssl版本
|
||||
|
||||
Loading…
Reference in New Issue
Block a user