2021-05-23 13:24:20 +00:00
|
|
|
|
import time
|
|
|
|
|
import tools
|
|
|
|
|
import config
|
|
|
|
|
import random
|
|
|
|
|
import setting
|
2021-06-13 02:33:38 +00:00
|
|
|
|
from request import http
|
2021-05-23 13:24:20 +00:00
|
|
|
|
|
2021-06-06 07:27:33 +00:00
|
|
|
|
Today_getcoins = 0
|
|
|
|
|
Today_have_getcoins = 0 #这个变量以后可能会用上,先留着了
|
|
|
|
|
Have_coins = 0
|
|
|
|
|
|
2021-05-23 13:24:20 +00:00
|
|
|
|
class mihoyobbs:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.headers = {
|
|
|
|
|
"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",
|
2021-05-25 09:45:35 +00:00
|
|
|
|
"x-rpc-device_id": tools.Get_deviceid(),
|
2021-05-23 13:24:20 +00:00
|
|
|
|
"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",
|
|
|
|
|
"User-Agent": "okhttp/4.8.0"
|
|
|
|
|
}
|
2021-06-06 04:16:28 +00:00
|
|
|
|
self.Task_do = {
|
|
|
|
|
"bbs_Sign": False,
|
|
|
|
|
"bbs_Read_posts": False,
|
2021-08-06 00:53:51 +00:00
|
|
|
|
"bbs_Read_posts_num": 3,
|
2021-06-06 04:16:28 +00:00
|
|
|
|
"bbs_Like_posts": False,
|
2021-08-06 00:53:51 +00:00
|
|
|
|
"bbs_Like_posts_num": 5,
|
2021-06-06 04:16:28 +00:00
|
|
|
|
"bbs_Share": False
|
|
|
|
|
}
|
|
|
|
|
self.Get_taskslist()
|
|
|
|
|
#如果这三个任务都做了就没必要获取帖子了
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if self.Task_do["bbs_Read_posts"] and self.Task_do["bbs_Like_posts"] and self.Task_do["bbs_Share"]:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
self.postsList = self.Getlist()
|
2021-05-25 09:45:35 +00:00
|
|
|
|
|
2021-06-06 04:16:28 +00:00
|
|
|
|
#获取任务列表,用来判断做了哪些任务
|
2021-06-05 14:44:07 +00:00
|
|
|
|
def Get_taskslist(self):
|
2021-06-06 07:27:33 +00:00
|
|
|
|
global Today_getcoins
|
|
|
|
|
global Today_have_getcoins
|
|
|
|
|
global Have_coins
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("正在获取任务列表")
|
2021-06-13 02:33:38 +00:00
|
|
|
|
req = http.get(url=setting.bbs_Taskslist, headers=self.headers)
|
2021-06-06 04:16:28 +00:00
|
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
|
if "err" in data["message"]:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("获取任务列表失败,你的cookie可能已过期,请重新设置cookie。")
|
|
|
|
|
config.Clear_cookies()
|
2021-07-16 11:44:30 +00:00
|
|
|
|
exit(1)
|
2021-06-06 04:16:28 +00:00
|
|
|
|
else:
|
2021-06-07 07:14:47 +00:00
|
|
|
|
Today_getcoins = data["data"]["can_get_points"]
|
|
|
|
|
Today_have_getcoins = data["data"]["already_received_points"]
|
2021-06-06 07:27:33 +00:00
|
|
|
|
Have_coins = data["data"]["total_points"]
|
2021-06-06 04:16:28 +00:00
|
|
|
|
#如果当日可获取米游币数量为0直接判断全部任务都完成了
|
2021-06-07 07:14:47 +00:00
|
|
|
|
if Today_getcoins == 0:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
self.Task_do["bbs_Sign"] = True
|
|
|
|
|
self.Task_do["bbs_Read_posts"] = True
|
|
|
|
|
self.Task_do["bbs_Like_posts"] = True
|
|
|
|
|
self.Task_do["bbs_Share"] = True
|
|
|
|
|
else:
|
|
|
|
|
#如果第0个大于或等于62则直接判定任务没做
|
2021-06-06 13:19:28 +00:00
|
|
|
|
if data["data"]["states"][0]["mission_id"] >= 62:
|
2021-06-06 07:27:33 +00:00
|
|
|
|
tools.log.info(f"新的一天,今天可以获得{Today_getcoins}个米游币")
|
2021-06-06 04:16:28 +00:00
|
|
|
|
pass
|
|
|
|
|
else:
|
2021-06-06 07:27:33 +00:00
|
|
|
|
tools.log.info(f"似乎还有任务没完成,今天还能获得{Today_getcoins}")
|
2021-06-06 04:16:28 +00:00
|
|
|
|
for i in data["data"]["states"]:
|
|
|
|
|
#58是讨论区签到
|
2021-06-06 13:19:28 +00:00
|
|
|
|
if i["mission_id"] == 58:
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if i["is_get_award"]:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
self.Task_do["bbs_Sign"] = True
|
|
|
|
|
#59是看帖子
|
2021-06-06 13:19:28 +00:00
|
|
|
|
elif i["mission_id"] == 59:
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if i["is_get_award"]:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
self.Task_do["bbs_Read_posts"] = True
|
2021-08-06 00:53:51 +00:00
|
|
|
|
else:
|
|
|
|
|
self.Task_do["bbs_Read_posts_num"] -= i["happened_times"]
|
2021-06-06 04:16:28 +00:00
|
|
|
|
#60是给帖子点赞
|
2021-06-06 13:19:28 +00:00
|
|
|
|
elif i["mission_id"] == 60:
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if i["is_get_award"]:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
self.Task_do["bbs_Like_posts"] = True
|
2021-08-06 00:53:51 +00:00
|
|
|
|
else:
|
|
|
|
|
self.Task_do["bbs_Like_posts_num"] -= i["happened_times"]
|
2021-06-06 04:16:28 +00:00
|
|
|
|
#61是分享帖子
|
2021-06-06 13:19:28 +00:00
|
|
|
|
elif i["mission_id"] == 61:
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if i["is_get_award"]:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
self.Task_do["bbs_Share"] = True
|
|
|
|
|
#分享帖子,是最后一个任务,到这里了下面都是一次性任务,直接跳出循环
|
|
|
|
|
break
|
2021-06-05 14:44:07 +00:00
|
|
|
|
|
|
|
|
|
#获取要帖子列表
|
|
|
|
|
def Getlist(self) -> list:
|
|
|
|
|
temp_List = []
|
|
|
|
|
tools.log.info("正在获取帖子列表......")
|
2021-08-06 00:53:51 +00:00
|
|
|
|
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)))
|
2021-06-06 13:19:28 +00:00
|
|
|
|
return temp_List
|
2021-06-05 14:44:07 +00:00
|
|
|
|
|
2021-05-23 13:24:20 +00:00
|
|
|
|
#进行签到操作
|
2021-08-03 02:35:55 +00:00
|
|
|
|
def Signin(self):
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if self.Task_do["bbs_Sign"]:
|
|
|
|
|
tools.log.info("讨论区任务已经完成过了~")
|
|
|
|
|
else:
|
|
|
|
|
tools.log.info("正在签到......")
|
2021-07-16 11:44:30 +00:00
|
|
|
|
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"]))
|
2021-08-06 00:53:51 +00:00
|
|
|
|
time.sleep(random.randint(2, 8))
|
2021-07-16 11:44:30 +00:00
|
|
|
|
else:
|
|
|
|
|
tools.log.info("签到失败,你的cookie可能已过期,请重新设置cookie。")
|
|
|
|
|
config.Clear_cookies()
|
|
|
|
|
exit(1)
|
2021-05-25 09:45:35 +00:00
|
|
|
|
|
2021-05-23 13:24:20 +00:00
|
|
|
|
#看帖子
|
|
|
|
|
def Readposts(self):
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if self.Task_do["bbs_Read_posts"]:
|
|
|
|
|
tools.log.info("看帖任务已经完成过了~")
|
|
|
|
|
else:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("正在看帖......")
|
2021-08-06 00:53:51 +00:00
|
|
|
|
for i in range(self.Task_do["bbs_Read_posts_num"]):
|
2021-06-13 02:33:38 +00:00
|
|
|
|
req = http.get(url=setting.bbs_Detailurl.format(self.postsList[i][0]), headers=self.headers)
|
2021-06-06 04:16:28 +00:00
|
|
|
|
data = req.json()
|
|
|
|
|
if data["message"] == "OK":
|
|
|
|
|
tools.log.info("看帖:{} 成功".format(self.postsList[i][1]))
|
2021-08-06 00:53:51 +00:00
|
|
|
|
time.sleep(random.randint(2, 8))
|
2021-05-25 09:45:35 +00:00
|
|
|
|
|
2021-05-23 13:24:20 +00:00
|
|
|
|
#点赞
|
|
|
|
|
def Likeposts(self):
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if self.Task_do["bbs_Like_posts"]:
|
|
|
|
|
tools.log.info("点赞任务已经完成过了~")
|
|
|
|
|
else:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("正在点赞......")
|
2021-08-06 00:53:51 +00:00
|
|
|
|
for i in range(self.Task_do["bbs_Like_posts_num"]):
|
2021-06-13 02:33:38 +00:00
|
|
|
|
req = http.post(url=setting.bbs_Likeurl, headers=self.headers,
|
2021-06-06 04:16:28 +00:00
|
|
|
|
json={"post_id": self.postsList[i][0], "is_cancel": False})
|
2021-05-23 13:24:20 +00:00
|
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
|
if data["message"] == "OK":
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("点赞:{} 成功".format(self.postsList[i][1]))
|
|
|
|
|
#判断取消点赞是否打开
|
2021-06-06 13:19:28 +00:00
|
|
|
|
if config.mihoyobbs["bbs_Unlike"] == True:
|
2021-08-06 00:53:51 +00:00
|
|
|
|
time.sleep(random.randint(2, 8))
|
2021-06-13 02:33:38 +00:00
|
|
|
|
req = http.post(url=setting.bbs_Likeurl, headers=self.headers,
|
2021-06-06 04:16:28 +00:00
|
|
|
|
json={"post_id": self.postsList[i][0], "is_cancel": True})
|
|
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
|
if data["message"] == "OK":
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("取消点赞:{} 成功".format(self.postsList[i][1]))
|
2021-08-06 00:53:51 +00:00
|
|
|
|
time.sleep(random.randint(2, 8))
|
2021-05-25 09:45:35 +00:00
|
|
|
|
|
|
|
|
|
#分享操作
|
2021-05-23 13:24:20 +00:00
|
|
|
|
def Share(self):
|
2021-08-06 00:53:51 +00:00
|
|
|
|
if self.Task_do["bbs_Share"]:
|
|
|
|
|
tools.log.info("分享任务已经完成过了~")
|
|
|
|
|
else:
|
2021-06-06 04:16:28 +00:00
|
|
|
|
tools.log.info("正在分享......")
|
2021-06-13 02:33:38 +00:00
|
|
|
|
req = http.get(url=setting.bbs_Shareurl.format(self.postsList[0][0]), headers=self.headers)
|
2021-06-06 04:16:28 +00:00
|
|
|
|
data = req.json()
|
|
|
|
|
if data["message"] == "OK":
|
|
|
|
|
tools.log.info("分享:{} 成功".format(self.postsList[0][1]))
|
2021-08-06 00:53:51 +00:00
|
|
|
|
time.sleep(random.randint(2, 8))
|