变量名小写,Log单独文件
This commit is contained in:
parent
08a5e53233
commit
3903607f7e
14
config.py
14
config.py
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
import tools
|
||||
from loghelper import log
|
||||
|
||||
# 是否启用config
|
||||
enable_Config = True
|
||||
@ -41,7 +41,7 @@ path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
||||
config_Path = f"{path}/config.json"
|
||||
|
||||
|
||||
def Load_config():
|
||||
def load_config():
|
||||
with open(config_Path, "r") as f:
|
||||
data = json.load(f)
|
||||
global enable_Config
|
||||
@ -68,10 +68,10 @@ def Load_config():
|
||||
genshin_Auto_sign = data["genshin_Auto_sign"]
|
||||
honkai3rd_Auto_sign = data["honkai3rd_Auto_sign"]
|
||||
f.close()
|
||||
tools.log.info("Config加载完毕")
|
||||
log.info("Config加载完毕")
|
||||
|
||||
|
||||
def Save_config():
|
||||
def save_config():
|
||||
with open(config_Path, "r+") as f:
|
||||
data = json.load(f)
|
||||
data["mihoyobbs_Login_ticket"] = mihoyobbs_Login_ticket
|
||||
@ -83,10 +83,10 @@ def Save_config():
|
||||
f.write(temp_Text)
|
||||
f.flush()
|
||||
f.close()
|
||||
tools.log.info("Config保存完毕")
|
||||
log.info("Config保存完毕")
|
||||
|
||||
|
||||
def Clear_cookies():
|
||||
def clear_cookies():
|
||||
with open(config_Path, "r+") as f:
|
||||
data = json.load(f)
|
||||
data["enable_Config"] = False
|
||||
@ -100,4 +100,4 @@ def Clear_cookies():
|
||||
f.write(temp_Text)
|
||||
f.flush()
|
||||
f.close()
|
||||
tools.log.info("Cookie删除完毕")
|
||||
log.info("Cookie删除完毕")
|
||||
|
3
error.py
3
error.py
@ -1,5 +1,6 @@
|
||||
class cookieError(Exception):
|
||||
class CookieError(Exception):
|
||||
def __init__(self, info):
|
||||
self.info = info
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.info)
|
61
genshin.py
61
genshin.py
@ -4,13 +4,14 @@ import config
|
||||
import random
|
||||
import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
|
||||
|
||||
class genshin:
|
||||
class Genshin:
|
||||
def __init__(self) -> None:
|
||||
self.headers = {
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'DS': tools.Get_ds(web=True, web_old=True),
|
||||
'DS': tools.get_ds(web=True, web_old=True),
|
||||
'Origin': 'https://webstatic.mihoyo.com',
|
||||
'x-rpc-app_version': setting.mihoyobbs_Version_old,
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0',
|
||||
@ -20,75 +21,75 @@ class genshin:
|
||||
'Accept-Language': 'zh-CN,en-US;q=0.8',
|
||||
'X-Requested-With': 'com.mihoyo.hyperion',
|
||||
"Cookie": config.mihoyobbs_Cookies,
|
||||
'x-rpc-device_id': tools.Get_deviceid()
|
||||
'x-rpc-device_id': tools.get_device_id()
|
||||
}
|
||||
self.acc_List = self.Getacc_list()
|
||||
self.acc_List = self.get_account_list()
|
||||
if len(self.acc_List) != 0:
|
||||
self.sign_Give = self.Get_signgive()
|
||||
self.sign_Give = self.get_signgive()
|
||||
|
||||
# 获取绑定的账号列表
|
||||
def Getacc_list(self) -> list:
|
||||
tools.log.info("正在获取米哈游账号绑定原神账号列表...")
|
||||
temp_List = []
|
||||
def get_account_list(self) -> list:
|
||||
log.info("正在获取米哈游账号绑定原神账号列表...")
|
||||
temp_list = []
|
||||
req = http.get(setting.genshin_Account_info_url, headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
tools.log.warning("获取账号列表失败!")
|
||||
log.warning("获取账号列表失败!")
|
||||
exit(1)
|
||||
for i in data["data"]["list"]:
|
||||
temp_List.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
tools.log.info(f"已获取到{len(temp_List)}个原神账号信息")
|
||||
return temp_List
|
||||
temp_list.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
log.info(f"已获取到{len(temp_list)}个原神账号信息")
|
||||
return temp_list
|
||||
|
||||
# 获取已经签到奖励列表
|
||||
def Get_signgive(self) -> list:
|
||||
tools.log.info("正在获取签到奖励列表...")
|
||||
def get_signgive(self) -> list:
|
||||
log.info("正在获取签到奖励列表...")
|
||||
req = http.get(setting.genshin_Signlisturl.format(setting.genshin_Act_id), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
tools.log.warning("获取签到奖励列表失败")
|
||||
log.warning("获取签到奖励列表失败")
|
||||
print(req.text)
|
||||
exit(1)
|
||||
return data["data"]["awards"]
|
||||
|
||||
# 判断签到
|
||||
def Is_sign(self, region: str, uid: str):
|
||||
def is_sign(self, region: str, uid: str):
|
||||
req = http.get(setting.genshin_Is_signurl.format(setting.genshin_Act_id, region, uid), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
tools.log.warning("获取账号签到信息失败!")
|
||||
log.warning("获取账号签到信息失败!")
|
||||
print(req.text)
|
||||
exit(1)
|
||||
return data["data"]
|
||||
|
||||
# 签到
|
||||
def Sign_acc(self):
|
||||
def sign_account(self):
|
||||
if len(self.acc_List) != 0:
|
||||
for i in self.acc_List:
|
||||
tools.log.info(f"正在为旅行者{i[0]}进行签到...")
|
||||
log.info(f"正在为旅行者{i[0]}进行签到...")
|
||||
time.sleep(random.randint(2, 8))
|
||||
is_data = self.Is_sign(region=i[2], uid=i[1])
|
||||
is_data = self.is_sign(region=i[2], uid=i[1])
|
||||
if is_data["first_bind"]:
|
||||
tools.log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次")
|
||||
log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次")
|
||||
else:
|
||||
sign_Days = is_data["total_sign_day"] - 1
|
||||
sign_days = is_data["total_sign_day"] - 1
|
||||
if is_data["is_sign"]:
|
||||
tools.log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.Get_item(self.sign_Give[sign_Days])}")
|
||||
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
||||
else:
|
||||
time.sleep(random.randint(2, 8))
|
||||
req = http.post(url=setting.genshin_Signurl, headers=self.headers,
|
||||
json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]})
|
||||
data = req.json()
|
||||
if data["retcode"] == 0:
|
||||
if sign_Days == 0:
|
||||
tools.log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.Get_item(self.sign_Give[sign_Days])}")
|
||||
if sign_days == 0:
|
||||
log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
||||
else:
|
||||
tools.log.info(
|
||||
f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.Get_item(self.sign_Give[sign_Days + 1])}")
|
||||
log.info(
|
||||
f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days + 1])}")
|
||||
elif data["retcode"] == -5003:
|
||||
tools.log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.Get_item(self.sign_Give[sign_Days])}")
|
||||
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
||||
else:
|
||||
tools.log.warning("账号签到失败!")
|
||||
log.warning("账号签到失败!")
|
||||
print(req.text)
|
||||
else:
|
||||
tools.log.warning("账号没有绑定任何原神账号!")
|
||||
log.warning("账号没有绑定任何原神账号!")
|
||||
|
25
honkai3rd.py
25
honkai3rd.py
@ -4,13 +4,14 @@ import config
|
||||
import random
|
||||
import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
|
||||
|
||||
class honkai3rd:
|
||||
def __init__(self) -> None:
|
||||
self.headers = {
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'DS': tools.Get_ds(web=True, web_old=True),
|
||||
'DS': tools.get_ds(web=True, web_old=True),
|
||||
'Origin': 'https://webstatic.mihoyo.com',
|
||||
'x-rpc-app_version': setting.mihoyobbs_Version_old,
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
@ -23,22 +24,22 @@ class honkai3rd:
|
||||
'Accept-Language': 'zh-CN,en-US;q=0.8',
|
||||
'X-Requested-With': 'com.mihoyo.hyperion',
|
||||
"Cookie": config.mihoyobbs_Cookies,
|
||||
'x-rpc-device_id': tools.Get_deviceid()
|
||||
'x-rpc-device_id': tools.get_device_id()
|
||||
}
|
||||
self.acc_List = self.Getacc_list()
|
||||
|
||||
# 获取绑定的账号列表
|
||||
def Getacc_list(self) -> list:
|
||||
tools.log.info("正在获取米哈游账号绑定的崩坏3账号列表...")
|
||||
log.info("正在获取米哈游账号绑定的崩坏3账号列表...")
|
||||
temp_List = []
|
||||
req = http.get(setting.honkai3rd_Account_info_url, headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
tools.log.warning("获取账号列表失败!")
|
||||
log.warning("获取账号列表失败!")
|
||||
exit(1)
|
||||
for i in data["data"]["list"]:
|
||||
temp_List.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
tools.log.info(f"已获取到{len(temp_List)}个崩坏3账号信息")
|
||||
log.info(f"已获取到{len(temp_List)}个崩坏3账号信息")
|
||||
return temp_List
|
||||
|
||||
# 获取今天已经签到了的dict
|
||||
@ -57,21 +58,21 @@ class honkai3rd:
|
||||
req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, region, uid), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
tools.log.warning("获取账号签到信息失败!")
|
||||
log.warning("获取账号签到信息失败!")
|
||||
print(req.text)
|
||||
exit(1)
|
||||
today_Item = self.Get_today_item(data["data"]["sign"]["list"])
|
||||
if today_Item["status"] == 1:
|
||||
return True
|
||||
else:
|
||||
tools.log.info(f"舰长{nickname}今天已经签到过了~\r\n今天获得的奖励是{tools.Get_item(today_Item)}")
|
||||
log.info(f"舰长{nickname}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(today_Item)}")
|
||||
return False
|
||||
|
||||
# 签到
|
||||
def Sign_acc(self):
|
||||
if len(self.acc_List) != 0:
|
||||
for i in self.acc_List:
|
||||
tools.log.info(f"正在为舰长{i[0]}进行签到...")
|
||||
log.info(f"正在为舰长{i[0]}进行签到...")
|
||||
time.sleep(random.randint(2, 8))
|
||||
is_data = self.Is_sign(region=i[2], uid=i[1], nickname=i[0])
|
||||
if is_data:
|
||||
@ -81,12 +82,12 @@ class honkai3rd:
|
||||
data = req.json()
|
||||
if data["retcode"] == 0:
|
||||
today_Item = self.Get_today_item(data["data"]["list"])
|
||||
tools.log.info(f"舰长{i[0]}签到成功~\r\n今天获得的奖励是{tools.Get_item(today_Item)}")
|
||||
log.info(f"舰长{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(today_Item)}")
|
||||
elif data["retcode"] == -5003:
|
||||
# 崩坏3应为奖励列表和签到信息在一起了,加上上面已经可以进行了一次判断,所以这里旧不重复再次执行判断来获取内容了
|
||||
tools.log.info(f"舰长{i[0]}今天已经签到过了~")
|
||||
log.info(f"舰长{i[0]}今天已经签到过了~")
|
||||
else:
|
||||
tools.log.warning("账号签到失败!")
|
||||
log.warning("账号签到失败!")
|
||||
print(req.text)
|
||||
else:
|
||||
tools.log.warning("账号没有绑定任何崩坏3账号!")
|
||||
log.warning("账号没有绑定任何崩坏3账号!")
|
||||
|
16
loghelper.py
Normal file
16
loghelper.py
Normal file
@ -0,0 +1,16 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
# Log输出,这里提供了自定义logging输出的机会,只需要创建一个logging.ini并且写入配置文件即可自定义输出
|
||||
file_path = os.path.dirname(os.path.realpath(__file__)) + "/config/logging.ini"
|
||||
if os.path.exists(file_path):
|
||||
import logging.config
|
||||
|
||||
logging.config.fileConfig(file_path)
|
||||
log = logging.getLogger("AutoMihoyoBBS")
|
||||
else:
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s %(levelname)s %(message)s',
|
||||
datefmt='%Y-%m-%dT%H:%M:%S')
|
||||
log = logger = logging
|
18
login.py
18
login.py
@ -1,15 +1,15 @@
|
||||
import config
|
||||
import request
|
||||
import setting
|
||||
from tools import log
|
||||
from error import cookieError
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
|
||||
|
||||
def login():
|
||||
if config.mihoyobbs_Cookies == '':
|
||||
log.error("请填入Cookies!")
|
||||
config.Clear_cookies()
|
||||
raise cookieError('No cookie')
|
||||
config.clear_cookies()
|
||||
raise CookieError('No cookie')
|
||||
# 判断Cookie里面是否有login_ticket 没有的话直接退了
|
||||
if "login_ticket" in config.mihoyobbs_Cookies:
|
||||
temp_Cookies = config.mihoyobbs_Cookies.split(";")
|
||||
@ -25,12 +25,12 @@ def login():
|
||||
config.mihoyobbs_Stoken = data["data"]["list"][0]["token"]
|
||||
log.info("登录成功!")
|
||||
log.info("正在保存Config!")
|
||||
config.Save_config()
|
||||
config.save_config()
|
||||
else:
|
||||
log.error("cookie已失效,请重新登录米游社抓取cookie")
|
||||
config.Clear_cookies()
|
||||
raise cookieError('Cookie expires')
|
||||
config.clear_cookies()
|
||||
raise CookieError('Cookie expires')
|
||||
else:
|
||||
log.error("cookie中没有'login_ticket'字段,请重新登录米游社,重新抓取cookie!")
|
||||
config.Clear_cookies()
|
||||
raise cookieError('Cookie lost login_ticket')
|
||||
config.clear_cookies()
|
||||
raise CookieError('Cookie lost login_ticket')
|
||||
|
39
main.py
39
main.py
@ -7,12 +7,13 @@ import genshin
|
||||
import setting
|
||||
import mihoyobbs
|
||||
import honkai3rd
|
||||
from error import cookieError
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
|
||||
|
||||
def main():
|
||||
# 初始化,加载配置
|
||||
config.Load_config()
|
||||
config.load_config()
|
||||
if config.enable_Config:
|
||||
# 检测参数是否齐全,如果缺少就进行登入操作
|
||||
if config.mihoyobbs_Login_ticket == "" or config.mihoyobbs_Stuid == "" or config.mihoyobbs_Stoken == "":
|
||||
@ -43,44 +44,44 @@ def main():
|
||||
bbs = mihoyobbs.mihoyobbs()
|
||||
if bbs.Task_do["bbs_Sign"] and bbs.Task_do["bbs_Read_posts"] and bbs.Task_do["bbs_Like_posts"] and \
|
||||
bbs.Task_do["bbs_Share"]:
|
||||
tools.log.info(f"今天已经全部完成了!一共获得{mihoyobbs.Today_have_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币")
|
||||
log.info(f"今天已经全部完成了!一共获得{mihoyobbs.Today_have_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币")
|
||||
else:
|
||||
if config.mihoyobbs["bbs_Signin"]:
|
||||
bbs.Signin()
|
||||
bbs.signing()
|
||||
if config.mihoyobbs["bbs_Read_posts"]:
|
||||
bbs.Readposts()
|
||||
bbs.read_posts()
|
||||
if config.mihoyobbs["bbs_Like_posts"]:
|
||||
bbs.Likeposts()
|
||||
if config.mihoyobbs["bbs_Share"]:
|
||||
bbs.Share()
|
||||
bbs.share_post()
|
||||
bbs.Get_taskslist()
|
||||
tools.log.info(
|
||||
log.info(
|
||||
f"今天已经获得{mihoyobbs.Today_have_getcoins}个米游币,还能获得{mihoyobbs.Today_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币")
|
||||
time.sleep(random.randint(2, 8))
|
||||
else:
|
||||
tools.log.info("米游社功能未启用!")
|
||||
log.info("米游社功能未启用!")
|
||||
# 原神签到
|
||||
if config.genshin_Auto_sign:
|
||||
tools.log.info("正在进行原神签到")
|
||||
genshin_Help = genshin.genshin()
|
||||
genshin_Help.Sign_acc()
|
||||
log.info("正在进行原神签到")
|
||||
genshin_help = genshin.Genshin()
|
||||
genshin_help.sign_account()
|
||||
time.sleep(random.randint(2, 8))
|
||||
else:
|
||||
tools.log.info("原神签到功能未启用!")
|
||||
log.info("原神签到功能未启用!")
|
||||
# 崩坏3签到
|
||||
if config.honkai3rd_Auto_sign:
|
||||
tools.log.info("正在进行崩坏3签到")
|
||||
honkai3rd_Help = honkai3rd.honkai3rd()
|
||||
honkai3rd_Help.Sign_acc()
|
||||
log.info("正在进行崩坏3签到")
|
||||
honkai3rd_help = honkai3rd.honkai3rd()
|
||||
honkai3rd_help.Sign_acc()
|
||||
else:
|
||||
tools.log.info("崩坏3签到功能未启用!")
|
||||
log.info("崩坏3签到功能未启用!")
|
||||
else:
|
||||
tools.log.warning("Config未启用!")
|
||||
log.warning("Config未启用!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except cookieError:
|
||||
tools.log.error("账号Cookie有问题!")
|
||||
except CookieError:
|
||||
log.error("账号Cookie有问题!")
|
||||
pass
|
||||
|
@ -2,51 +2,51 @@ import os
|
||||
import sys
|
||||
import main
|
||||
import time
|
||||
import tools
|
||||
import config
|
||||
import random
|
||||
import setting
|
||||
from error import cookieError
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
|
||||
|
||||
# 搜索配置文件
|
||||
def Fund_config() -> list:
|
||||
file_Name = []
|
||||
def fund_config() -> list:
|
||||
file_name = []
|
||||
for files in os.listdir(config.path):
|
||||
if os.path.splitext(files)[1] == '.json':
|
||||
file_Name.append(files)
|
||||
return file_Name
|
||||
file_name.append(files)
|
||||
return file_name
|
||||
|
||||
|
||||
def main_multi(autorun: bool):
|
||||
tools.log.info("AutoMihoyoBBS Multi User mode")
|
||||
tools.log.info("正在搜索配置文件!")
|
||||
config_List = Fund_config()
|
||||
if len(config_List) == 0:
|
||||
tools.log.warning("未检测到配置文件,请确认config文件夹存在.json后缀名的配置文件!")
|
||||
log.info("AutoMihoyoBBS Multi User mode")
|
||||
log.info("正在搜索配置文件!")
|
||||
config_list = fund_config()
|
||||
if len(config_list) == 0:
|
||||
log.warning("未检测到配置文件,请确认config文件夹存在.json后缀名的配置文件!")
|
||||
exit(1)
|
||||
if autorun:
|
||||
tools.log.info(f"已搜索到{len(config_List)}个配置文件,正在开始执行!")
|
||||
log.info(f"已搜索到{len(config_list)}个配置文件,正在开始执行!")
|
||||
else:
|
||||
tools.log.info(f"已搜索到{len(config_List)}个配置文件,请确认是否无多余文件!\r\n{config_List}")
|
||||
log.info(f"已搜索到{len(config_list)}个配置文件,请确认是否无多余文件!\r\n{config_list}")
|
||||
try:
|
||||
input("请输入回车继续,需要重新搜索配置文件请Ctrl+C退出脚本")
|
||||
except:
|
||||
exit(0)
|
||||
results = {"ok":[],"error":[]}
|
||||
for i in iter(config_List):
|
||||
tools.log.info(f"正在执行{i}")
|
||||
results = {"ok": [], "error": []}
|
||||
for i in iter(config_list):
|
||||
log.info(f"正在执行{i}")
|
||||
setting.mihoyobbs_List_Use = []
|
||||
config.config_Path = f"{config.path}/{i}"
|
||||
try:
|
||||
main.main()
|
||||
except cookieError:
|
||||
except CookieError:
|
||||
results["error"].append(i)
|
||||
else:
|
||||
results["ok"].append(i)
|
||||
tools.log.info(f"{i}执行完毕")
|
||||
log.info(f"{i}执行完毕")
|
||||
time.sleep(random.randint(3, 10))
|
||||
tools.log.info(f'脚本执行完毕,共执行{len(config_List)}个配置文件,成功{len(results["ok"])}个,失败{len(results["error"])}个')
|
||||
log.info(f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,失败{len(results["error"])}个')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
73
mihoyobbs.py
73
mihoyobbs.py
@ -4,7 +4,8 @@ import config
|
||||
import random
|
||||
import setting
|
||||
from request import http
|
||||
from error import cookieError
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
|
||||
|
||||
Today_getcoins = 0
|
||||
@ -15,14 +16,14 @@ Have_coins = 0
|
||||
class mihoyobbs:
|
||||
def __init__(self):
|
||||
self.headers = {
|
||||
"DS": tools.Get_ds(web=False, web_old=False),
|
||||
"DS": tools.get_ds(web=False, web_old=False),
|
||||
"cookie": f"stuid={config.mihoyobbs_Stuid};stoken={config.mihoyobbs_Stoken}",
|
||||
"x-rpc-client_type": setting.mihoyobbs_Client_type,
|
||||
"x-rpc-app_version": setting.mihoyobbs_Version,
|
||||
"x-rpc-sys_version": "6.0.1",
|
||||
"x-rpc-channel": "mihoyo",
|
||||
"x-rpc-device_id": tools.Get_deviceid(),
|
||||
"x-rpc-device_name": tools.Random_text(random.randint(1, 10)),
|
||||
"x-rpc-device_id": tools.get_device_id(),
|
||||
"x-rpc-device_name": tools.random_text(random.randint(1, 10)),
|
||||
"x-rpc-device_model": "Mi 10",
|
||||
"Referer": "https://app.mihoyo.com",
|
||||
"Host": "bbs-api.mihoyo.com",
|
||||
@ -41,20 +42,20 @@ class mihoyobbs:
|
||||
if self.Task_do["bbs_Read_posts"] and self.Task_do["bbs_Like_posts"] and self.Task_do["bbs_Share"]:
|
||||
pass
|
||||
else:
|
||||
self.postsList = self.Getlist()
|
||||
self.postsList = self.get_list()
|
||||
|
||||
# 获取任务列表,用来判断做了哪些任务
|
||||
def Get_taskslist(self):
|
||||
global Today_getcoins
|
||||
global Today_have_getcoins
|
||||
global Have_coins
|
||||
tools.log.info("正在获取任务列表")
|
||||
log.info("正在获取任务列表")
|
||||
req = http.get(url=setting.bbs_Taskslist, headers=self.headers)
|
||||
data = req.json()
|
||||
if "err" in data["message"] or data["retcode"] == -100:
|
||||
tools.log.error("获取任务列表失败,你的cookie可能已过期,请重新设置cookie。")
|
||||
config.Clear_cookies()
|
||||
raise cookieError('Cookie expires')
|
||||
log.error("获取任务列表失败,你的cookie可能已过期,请重新设置cookie。")
|
||||
config.clear_cookies()
|
||||
raise CookieError('Cookie expires')
|
||||
else:
|
||||
Today_getcoins = data["data"]["can_get_points"]
|
||||
Today_have_getcoins = data["data"]["already_received_points"]
|
||||
@ -68,10 +69,10 @@ class mihoyobbs:
|
||||
else:
|
||||
# 如果第0个大于或等于62则直接判定任务没做
|
||||
if data["data"]["states"][0]["mission_id"] >= 62:
|
||||
tools.log.info(f"新的一天,今天可以获得{Today_getcoins}个米游币")
|
||||
log.info(f"新的一天,今天可以获得{Today_getcoins}个米游币")
|
||||
pass
|
||||
else:
|
||||
tools.log.info(f"似乎还有任务没完成,今天还能获得{Today_getcoins}")
|
||||
log.info(f"似乎还有任务没完成,今天还能获得{Today_getcoins}")
|
||||
for i in data["data"]["states"]:
|
||||
# 58是讨论区签到
|
||||
if i["mission_id"] == 58:
|
||||
@ -97,58 +98,58 @@ class mihoyobbs:
|
||||
break
|
||||
|
||||
# 获取要帖子列表
|
||||
def Getlist(self) -> list:
|
||||
temp_List = []
|
||||
tools.log.info("正在获取帖子列表......")
|
||||
def get_list(self) -> list:
|
||||
temp_list = []
|
||||
log.info("正在获取帖子列表......")
|
||||
req = http.get(url=setting.bbs_Listurl.format(setting.mihoyobbs_List_Use[0]["forumId"]), headers=self.headers)
|
||||
data = req.json()
|
||||
for n in range(5):
|
||||
temp_List.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]])
|
||||
tools.log.info("已获取{}个帖子".format(len(temp_List)))
|
||||
return temp_List
|
||||
temp_list.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]])
|
||||
log.info("已获取{}个帖子".format(len(temp_list)))
|
||||
return temp_list
|
||||
|
||||
# 进行签到操作
|
||||
def Signin(self):
|
||||
def signing(self):
|
||||
if self.Task_do["bbs_Sign"]:
|
||||
tools.log.info("讨论区任务已经完成过了~")
|
||||
log.info("讨论区任务已经完成过了~")
|
||||
else:
|
||||
tools.log.info("正在签到......")
|
||||
log.info("正在签到......")
|
||||
for i in setting.mihoyobbs_List_Use:
|
||||
req = http.post(url=setting.bbs_Signurl.format(i["id"]), data={}, headers=self.headers)
|
||||
data = req.json()
|
||||
if "err" not in data["message"]:
|
||||
tools.log.info(str(i["name"] + data["message"]))
|
||||
log.info(str(i["name"] + data["message"]))
|
||||
time.sleep(random.randint(2, 8))
|
||||
else:
|
||||
tools.log.error("签到失败,你的cookie可能已过期,请重新设置cookie。")
|
||||
config.Clear_cookies()
|
||||
raise cookieError('Cookie expires')
|
||||
log.error("签到失败,你的cookie可能已过期,请重新设置cookie。")
|
||||
config.clear_cookies()
|
||||
raise CookieError('Cookie expires')
|
||||
|
||||
# 看帖子
|
||||
def Readposts(self):
|
||||
def read_posts(self):
|
||||
if self.Task_do["bbs_Read_posts"]:
|
||||
tools.log.info("看帖任务已经完成过了~")
|
||||
log.info("看帖任务已经完成过了~")
|
||||
else:
|
||||
tools.log.info("正在看帖......")
|
||||
log.info("正在看帖......")
|
||||
for i in range(self.Task_do["bbs_Read_posts_num"]):
|
||||
req = http.get(url=setting.bbs_Detailurl.format(self.postsList[i][0]), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
tools.log.info("看帖:{} 成功".format(self.postsList[i][1]))
|
||||
log.info("看帖:{} 成功".format(self.postsList[i][1]))
|
||||
time.sleep(random.randint(2, 8))
|
||||
|
||||
# 点赞
|
||||
def Likeposts(self):
|
||||
if self.Task_do["bbs_Like_posts"]:
|
||||
tools.log.info("点赞任务已经完成过了~")
|
||||
log.info("点赞任务已经完成过了~")
|
||||
else:
|
||||
tools.log.info("正在点赞......")
|
||||
log.info("正在点赞......")
|
||||
for i in range(self.Task_do["bbs_Like_posts_num"]):
|
||||
req = http.post(url=setting.bbs_Likeurl, headers=self.headers,
|
||||
json={"post_id": self.postsList[i][0], "is_cancel": False})
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
tools.log.info("点赞:{} 成功".format(self.postsList[i][1]))
|
||||
log.info("点赞:{} 成功".format(self.postsList[i][1]))
|
||||
# 判断取消点赞是否打开
|
||||
if config.mihoyobbs["bbs_Unlike"]:
|
||||
time.sleep(random.randint(2, 8))
|
||||
@ -156,18 +157,18 @@ class mihoyobbs:
|
||||
json={"post_id": self.postsList[i][0], "is_cancel": True})
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
tools.log.info("取消点赞:{} 成功".format(self.postsList[i][1]))
|
||||
log.info("取消点赞:{} 成功".format(self.postsList[i][1]))
|
||||
time.sleep(random.randint(2, 8))
|
||||
|
||||
# 分享操作
|
||||
|
||||
def Share(self):
|
||||
def share_post(self):
|
||||
if self.Task_do["bbs_Share"]:
|
||||
tools.log.info("分享任务已经完成过了~")
|
||||
log.info("分享任务已经完成过了~")
|
||||
else:
|
||||
tools.log.info("正在分享......")
|
||||
log.info("正在分享......")
|
||||
req = http.get(url=setting.bbs_Shareurl.format(self.postsList[0][0]), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
tools.log.info("分享:{} 成功".format(self.postsList[0][1]))
|
||||
log.info("分享:{} 成功".format(self.postsList[0][1]))
|
||||
time.sleep(random.randint(2, 8))
|
||||
|
@ -5,7 +5,7 @@ try:
|
||||
http = httpx.Client(timeout=10, transport=httpx.HTTPTransport(retries=5))
|
||||
# 当openssl版本小于1.0.2的时候直接进行一个空请求让httpx报错
|
||||
import tools
|
||||
if tools.Get_openssl_Version() <= 102:
|
||||
if tools.get_openssl_version() <= 102:
|
||||
httpx.get()
|
||||
except:
|
||||
import requests
|
||||
|
48
tools.py
48
tools.py
@ -1,46 +1,31 @@
|
||||
import os
|
||||
import uuid
|
||||
import time
|
||||
import config
|
||||
import random
|
||||
import string
|
||||
import logging
|
||||
import hashlib
|
||||
import setting
|
||||
|
||||
# Log输出,这里提供了自定义logging输出的机会,只需要创建一个logging.ini并且写入配置文件即可自定义输出
|
||||
if os.path.exists(f"{config.path}/logging.ini"):
|
||||
import logging.config
|
||||
|
||||
logging.config.fileConfig(f"{config.path}/logging.ini")
|
||||
log = logging.getLogger("AutoMihoyoBBS")
|
||||
else:
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s %(levelname)s %(message)s',
|
||||
datefmt='%Y-%m-%dT%H:%M:%S')
|
||||
log = logger = logging
|
||||
|
||||
|
||||
# md5计算
|
||||
def MD5(text: str) -> str:
|
||||
def md5(text: str) -> str:
|
||||
md5 = hashlib.md5()
|
||||
md5.update(text.encode())
|
||||
return md5.hexdigest()
|
||||
|
||||
|
||||
# 随机文本
|
||||
def Random_text(num: int) -> str:
|
||||
def random_text(num: int) -> str:
|
||||
return ''.join(random.sample(string.ascii_lowercase + string.digits, num))
|
||||
|
||||
|
||||
# 时间戳
|
||||
def Timestamp() -> int:
|
||||
def timestamp() -> int:
|
||||
return int(time.time())
|
||||
|
||||
|
||||
# 获取请求Header里的DS 当web为true则生成网页端的DS
|
||||
def Get_ds(web: bool, web_old: bool) -> str:
|
||||
def get_ds(web: bool, web_old: bool) -> str:
|
||||
if web:
|
||||
if web_old:
|
||||
n = setting.mihoyobbs_Salt_web_old
|
||||
@ -48,40 +33,41 @@ def Get_ds(web: bool, web_old: bool) -> str:
|
||||
n = setting.mihoyobbs_Salt_web
|
||||
else:
|
||||
n = setting.mihoyobbs_Salt
|
||||
i = str(Timestamp())
|
||||
r = Random_text(6)
|
||||
c = MD5("salt=" + n + "&t=" + i + "&r=" + r)
|
||||
i = str(timestamp())
|
||||
r = random_text(6)
|
||||
c = md5("salt=" + n + "&t=" + i + "&r=" + r)
|
||||
return f"{i},{r},{c}"
|
||||
|
||||
|
||||
# 生成一个device id
|
||||
def Get_deviceid() -> str:
|
||||
def get_device_id() -> str:
|
||||
return str(uuid.uuid3(uuid.NAMESPACE_URL, config.mihoyobbs_Cookies)).replace(
|
||||
'-', '').upper()
|
||||
|
||||
|
||||
# 获取签到的奖励名称
|
||||
def Get_item(raw_data: dict) -> str:
|
||||
temp_Name = raw_data["name"]
|
||||
temp_Cnt = raw_data["cnt"]
|
||||
return f"{temp_Name}x{temp_Cnt}"
|
||||
def get_item(raw_data: dict) -> str:
|
||||
temp_name = raw_data["name"]
|
||||
temp_cnt = raw_data["cnt"]
|
||||
return f"{temp_name}x{temp_cnt}"
|
||||
|
||||
|
||||
# 获取明天早晨0点的时间戳
|
||||
def Nextday() -> int:
|
||||
def nextday() -> int:
|
||||
now_time = int(time.time())
|
||||
nextday_time = now_time - now_time % 86400 + time.timezone + 86400
|
||||
return nextday_time
|
||||
|
||||
|
||||
# 获取Openssl版本
|
||||
def Get_openssl_Version() -> int:
|
||||
def get_openssl_version() -> int:
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
from loghelper import log
|
||||
log.error("Openssl Lib Error !!")
|
||||
# return -99
|
||||
# 建议直接更新Python的版本,有特殊情况请提交issues
|
||||
exit(-1)
|
||||
temp_List = ssl.OPENSSL_VERSION_INFO
|
||||
return int(f"{str(temp_List[0])}{str(temp_List[1])}{str(temp_List[2])}")
|
||||
temp_list = ssl.OPENSSL_VERSION_INFO
|
||||
return int(f"{str(temp_list[0])}{str(temp_list[1])}{str(temp_list[2])}")
|
||||
|
Loading…
Reference in New Issue
Block a user