新增获取爆米花任务id,执行爆米花日常任务

This commit is contained in:
echo 2024-09-24 23:59:10 +08:00
parent 20c5921bf0
commit f2d53da8a7

View File

@ -16,6 +16,7 @@ from bs4 import BeautifulSoup
from fn_print import fn_print from fn_print import fn_print
from sendNotify import send_notification_message_collection from sendNotify import send_notification_message_collection
if 'Hykb_cookie' in os.environ: if 'Hykb_cookie' in os.environ:
hykb_cookie = re.split("@", os.environ.get("Hykb_cookie")) hykb_cookie = re.split("@", os.environ.get("Hykb_cookie"))
print(f"查找到{len(hykb_cookie)}个账号") print(f"查找到{len(hykb_cookie)}个账号")
@ -37,6 +38,7 @@ class AsyncHykbTasks:
verify=False) verify=False)
self.cookie = cookie self.cookie = cookie
self.temp_id = [] self.temp_id = []
self.bmh_tasks = []
self.items = [] self.items = []
async def get_task_ids(self): async def get_task_ids(self):
@ -54,6 +56,28 @@ class AsyncHykbTasks:
"id": re.search(r"hd_id=(.+)", parts[1]).group(1) "id": re.search(r"hd_id=(.+)", parts[1]).group(1)
}) })
async def get_bmh_task_ids(self):
"""
获取爆米花相关任务的id
:return:
"""
response = await self.client.get("/n/hykb/cornfarm/index.php?imm=0")
html = response.text
soup = BeautifulSoup(html, 'html.parser')
task_list = soup.select(".taskDailyUl > li")
for task_item in task_list:
tasks_infos = task_item.select_one("dl")
id_param = tasks_infos.select_one("dd")["class"][0]
title_param = tasks_infos.select_one("dt").get_text()
reward_param = tasks_infos.select_one("dd").get_text()
self.bmh_tasks.append(
{
"bmh_task_id": re.search(r"daily_dd_(.+)", id_param).group(1),
"bmh_task_title": re.search(r"分享福利:(.*)", title_param).group(1),
"reward_num": re.search(r"可得+(.+)", reward_param).group(1)
}
)
async def get_task(self, a, hd_id_): async def get_task(self, a, hd_id_):
try: try:
payload = f"ac={a}&hd_id={hd_id_}&hd_id2={hd_id_}&t={datetime.now().strftime('%Y-%m-%d %H:%M:%S')}&r=0.{random.randint(1000000000000000, 8999999999999999)}&scookie={self.cookie}" payload = f"ac={a}&hd_id={hd_id_}&hd_id2={hd_id_}&t={datetime.now().strftime('%Y-%m-%d %H:%M:%S')}&r=0.{random.randint(1000000000000000, 8999999999999999)}&scookie={self.cookie}"
@ -69,11 +93,14 @@ class AsyncHykbTasks:
print(e) print(e)
return None return None
async def process_item(self, item): async def process_item(self, item, bmh_itme):
id = item["id"] id = item["id"]
await self.get_task("login", id) await self.get_task("login", id)
data = await self.get_task("signToday", id) data = await self.get_task("signToday", id)
await self.do_tasks_every_day(bmh_itme)
await self.get_task_reward(bmh_itme)
key = str(data["key"]) key = str(data["key"])
if key == "-1005": if key == "-1005":
fn_print("体验游戏中,请一分钟后再刷新领取☑️") fn_print("体验游戏中,请一分钟后再刷新领取☑️")
@ -98,12 +125,69 @@ class AsyncHykbTasks:
return False return False
return True return True
async def do_tasks_every_day(self, task_items: dict):
"""
调度每日必做任务
:return:
"""
# 分享任务
share_url = "https://huodong3.3839.com/n/hykb/cornfarm/ajax_daily.php"
share_data = {
"ac": "DailyShareCallback",
"id": "{}".format(task_items["bmh_task_id"]),
"mode": "qq",
"source": "ds",
"r": f"0.{random.randint(100000000000000, 8999999999999999)}",
"scookie": self.cookie,
"device": "kbA25014349F11473F467DC6FF5C89E9D6"
}
share_response = await self.client.post(url=share_url, json=share_data)
try:
share_response_json = share_response.json()
if share_response_json["key"] == "ok" and share_response_json["info"] == "可以领奖":
fn_print("任务: {}, 可以领奖了.".format(task_items["bmh_task_title"]))
return True
else:
fn_print("任务: {}, 不可以领奖".format(task_items["bmh_task_title"]))
return False
except Exception as e:
fn_print("调度任务异常:", e)
fn_print(share_response.text)
async def get_task_reward(self, task_items: dict):
"""
领取任务奖励
:param task_items: 任务组
:return:
"""
url = "https://huodong3.3839.com/n/hykb/cornfarm/ajax_daily.php"
data = {
"ac": "DailyShareLing",
"smdeviceid": "BOMLz9iBlx4KwA+wayGk+H/+P91GAH9pC0q9dvBQcvwlVTppakJAfBnJr1K5lyBgzXtIcTgeBqAXtI7NWFaaz8A==",
"verison": "1.5.7.507",
"id": "{}".format(task_items["bmh_task_id"]),
"r": f"0.{random.randint(100000000000000, 8999999999999999)}",
"scookie": self.cookie,
"device": "kbA25014349F11473F467DC6FF5C89E9D6"
}
response = await self.client.post(url=url, json=data)
try:
response_json = response.json()
if response_json["key"] == "ok" and response_json["message"] == "成功":
fn_print(
f"任务: {task_items['bmh_task_title']}- ✅奖励领取成功!\n成熟度+{response_json['reward_csd_num']}\n已完成任务数量:{response_json['daily_renwu_success_total']}\n今日获得成熟度{response_json['daily_day_all_chengshoudu']}")
else:
fn_print("奖励领取失败!")
except Exception:
print(response.text)
async def task(self): async def task(self):
cookie = urllib.parse.quote(self.cookie) if "|" in self.cookie else self.cookie cookie = urllib.parse.quote(self.cookie) if "|" in self.cookie else self.cookie
await self.get_task_ids() await self.get_task_ids()
await self.get_bmh_task_ids()
for item in self.items: for item, bmh_item in self.items, self.bmh_tasks:
if not await self.process_item(item): if not await self.process_item(item, bmh_item):
break break
# if self.temp_id: # if self.temp_id:
# print("等待体验结束...") # print("等待体验结束...")
@ -141,6 +225,7 @@ async def run_all_tasks(cookies):
async def main(): async def main():
hykb_cookie = []
await run_all_tasks(hykb_cookie) await run_all_tasks(hykb_cookie)