Commit 451a6662 by lei

1

parent 04fa942b
......@@ -226,65 +226,64 @@ class ToWork:
async def check_img_load_process(self, page, task):
logger.info('开始检测任务状态')
# 先写单个任务的,获取最后一张图片
# 获取开始时间
start_time = get_current_time()
while True:
# 获取开始时间
start_time = get_current_time()
while True:
# 再次获取当前时间
current_time = get_current_time()
# 最多等待一分钟
if current_time - start_time >= 60:
# end
await self.img_callback(task, '', '任务已超时')
break
cur_type = 1 # 获取最后一个
if cur_type == 1:
# 判断文字中是否存在进度条
text_path = '//div[contains(@id, "message-content-")]'
text_el = await self.FindElement(page, text_path, 'last')
if text_el:
title = await page.evaluate('(element) => element.textContent', text_el)
# 判断失败
if 'Failed to process your command' in title or 'Sorry! Could not complete the job' in title:
logger.info('本次任务失败')
# 回调
await self.img_callback(task, '', title)
return
elif '%)' not in title and '(Waiting to start)' not in title and '正在发送命令' not in title and 'fast' in title:
logger.info('任务完成')
# 最后一个链接
'//*[@id="message-accessories-1095187577776124025"]/div[1]/div/div/div/div/div/a'
img_path = '//*[contains(@id, "message-accessories-")]/div[1]/div/div/div/div/div/a'
img_el = await self.FindElement(page, img_path, 'last')
if img_el:
href = await page.evaluate('img_el => img_el.href', img_el)
if href:
logger.info(href)
# 回调
await self.img_callback(task, href)
return
else:
logger.info('任务进行中')
# 再次获取当前时间
current_time = get_current_time()
# 最多等待一分钟
if current_time - start_time >= 60:
# end
await self.img_callback(task, '', '任务已超时')
break
cur_type = 1 # 获取最后一个
if cur_type == 1:
# 判断文字中是否存在进度条
text_path = '//div[contains(@id, "message-content-")]'
text_el = await self.FindElement(page, text_path, 'last')
if text_el:
title = await page.evaluate('(element) => element.textContent', text_el)
# 判断失败
if 'Failed to process your command' in title or 'Sorry! Could not complete the job' in title:
logger.info('本次任务失败')
# 回调
await self.img_callback(task, '', title)
return
elif '%)' not in title and '(Waiting to start)' not in title and '正在发送命令' not in title and 'fast' in title:
logger.info('任务完成')
# 最后一个链接
'//*[@id="message-accessories-1095187577776124025"]/div[1]/div/div/div/div/div/a'
img_path = '//*[contains(@id, "message-accessories-")]/div[1]/div/div/div/div/div/a'
img_el = await self.FindElement(page, img_path, 'last')
if img_el:
href = await page.evaluate('img_el => img_el.href', img_el)
if href:
logger.info(href)
# 回调
await self.img_callback(task, href)
return
else:
logger.info('文本元素不存在')
logger.info('任务进行中')
else:
# 开始判断
element = '//ol[@data-list-id="chat-messages"]/li'
# 消息列表
message_list = await self.CheckElement(page, element, 20, 'list')
if message_list:
logger.info('消息列表存在')
# 找到所有子元素
for e in message_list:
# 找到文本并匹配
path = '//div[contains(@id, "message-content-")]/strong'
label_element = await self.FindElement(e, path)
if label_element:
title = await page.evaluate('(element) => element.textContent', label_element)
logger.info(title)
else:
logger.info('未找到文本')
await asyncio.sleep(1)
logger.info('文本元素不存在')
else:
# 开始判断
element = '//ol[@data-list-id="chat-messages"]/li'
# 消息列表
message_list = await self.CheckElement(page, element, 20, 'list')
if message_list:
logger.info('消息列表存在')
# 找到所有子元素
for e in message_list:
# 找到文本并匹配
path = '//div[contains(@id, "message-content-")]/strong'
label_element = await self.FindElement(e, path)
if label_element:
title = await page.evaluate('(element) => element.textContent', label_element)
logger.info(title)
else:
logger.info('未找到文本')
await asyncio.sleep(1)
# 循环输入指令
async def enter_prompt(self, page, tasks):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment