调整chrome内容
This commit is contained in:
15
robot.py
15
robot.py
@@ -183,6 +183,7 @@ class Robot(Job):
|
||||
|
||||
# 开启自动心跳(作为后台任务)
|
||||
heartbeat_task = asyncio.create_task(self._heartbeat_task())
|
||||
heartbeat_task_long = asyncio.create_task(self._heartbeat_task_long())
|
||||
self.message_storage = MessageStorage(self.ipad_bot)
|
||||
|
||||
# 初始化消息工具类 - 使用联系人管理器
|
||||
@@ -308,6 +309,20 @@ class Robot(Job):
|
||||
self.LOG.error(f"wechat_ipad heartbeat: {e}")
|
||||
await asyncio.sleep(5)
|
||||
|
||||
async def _heartbeat_task_long(self):
|
||||
"""wechat_ipad心跳任务"""
|
||||
self.LOG.info("开启wechat_ipad长连接心跳!")
|
||||
while self.ipad_running:
|
||||
try:
|
||||
success = await self.ipad_bot.heartbeat_long()
|
||||
if success:
|
||||
self.LOG.success("长连接心跳进行中")
|
||||
else:
|
||||
self.LOG.warning("长连接心跳失败")
|
||||
except Exception as e:
|
||||
self.LOG.error(f"wechat_ipad heartbeat long: {e}")
|
||||
await asyncio.sleep(5)
|
||||
|
||||
async def _process_ipad_message(self, message: WxMessage):
|
||||
"""处理wechat_ipad消息"""
|
||||
try:
|
||||
|
||||
@@ -184,6 +184,27 @@ class LoginMixin(WechatAPIClientBase):
|
||||
else:
|
||||
self.error_handler(json_resp)
|
||||
|
||||
async def heartbeat_long(self) -> bool:
|
||||
"""发送心跳包。
|
||||
|
||||
Returns:
|
||||
bool: 成功返回True,否则返回False
|
||||
|
||||
Raises:
|
||||
UserLoggedOut: 如果未登录时调用
|
||||
根据error_handler处理错误
|
||||
"""
|
||||
if not self.wxid:
|
||||
raise UserLoggedOut("请先登录")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
response = await session.post(f'http://{self.ip}:{self.port}/api/Login/HeartBeatLong?wxid={self.wxid}')
|
||||
json_resp = await response.json()
|
||||
if json_resp.get("Success"):
|
||||
return True
|
||||
else:
|
||||
self.error_handler(json_resp)
|
||||
|
||||
@staticmethod
|
||||
def create_device_name() -> str:
|
||||
"""生成一个随机的设备名。
|
||||
|
||||
@@ -197,7 +197,6 @@ def meitu_dowload_pic(dl_path, dl_url):
|
||||
print(f"共找到 {len(images)} 张图片,开始下载...")
|
||||
for idx, img_url in enumerate(images, 1):
|
||||
# 增加随机延时
|
||||
time.sleep(random.uniform(0.1, 0.4))
|
||||
if not download_image(img_url, folder_path, idx):
|
||||
print(f"图片 {img_url} 下载失败,继续下一张...")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user