Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python_open_ai
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haojie
python_open_ai
Commits
451a6662
Commit
451a6662
authored
Apr 12, 2023
by
lei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
04fa942b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
56 deletions
+55
-56
ai_pyppeteer.py
+55
-56
No files found.
ai_pyppeteer.py
View file @
451a6662
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment