临时提交

This commit is contained in:
zw
2025-08-12 22:03:08 +08:00
parent 1ce16cff46
commit cd61c2138a
4 changed files with 131 additions and 112 deletions

View File

@@ -82,7 +82,6 @@ class Deviceinfo(object):
d.app_start(WdaAppBundleId) d.app_start(WdaAppBundleId)
d.home() d.home()
time.sleep(2) time.sleep(2)
# d.app_start(tikTokApp)
target = self.relayDeviceScreenPort() target = self.relayDeviceScreenPort()
self.pidList.append({ self.pidList.append({
"target": target, "target": target,

View File

@@ -6,6 +6,7 @@ import numpy as np
import wda import wda
from Utils.LogManager import LogManager from Utils.LogManager import LogManager
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from wda import Client
# 工具类 # 工具类
class AiUtils(object): class AiUtils(object):
@@ -236,10 +237,46 @@ class AiUtils(object):
and (e.get('visible') in (None, 'true')) and (e.get('visible') in (None, 'true'))
) )
# 获取关注按钮
@classmethod
def getFollowButton(cls, session: Client):
followButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]/Button[1]")
if followButton.exists:
print("找到了")
return followButton
else:
print("没找到")
return None
# 查找发消息按钮
@classmethod
def getSendMesageButton(cls, session: Client):
msgButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]")
if msgButton.exists:
print("找到了")
return msgButton
else:
print("没找到")
return None
# 获取当前屏幕上的节点 # 获取当前屏幕上的节点
@classmethod @classmethod
def getCurrentScreenSource(cls): def getCurrentScreenSource(cls):
client = wda.USBClient("eca000fcb6f55d7ed9b4c524055214c26a7de7aa") client = wda.USBClient("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")
print(client.source()) print(client.source())
# AiUtils.getCurrentScreenSource()
# 查找app主页上的收件箱按钮
@classmethod
def getMsgBoxButton(cls, session: Client):
box = session.xpath("//XCUIElementTypeButton[name='a11y_vo_inbox']")
if box.exists:
return box
else:
return None
# 获取收件箱中的未读消息数
@classmethod
def getUnReadMsgCount(cls, session: Client):
btn = cls.getMsgBoxButton(session)
return cls.findNumber(btn.label)

View File

@@ -53,16 +53,20 @@ class ControlUtils(object):
@classmethod @classmethod
def clickBack(cls, session: Client): def clickBack(cls, session: Client):
try: try:
x, y = AiUtils.findImageInScreen("back") back = session.xpath("//*[@label='返回']")
if x > 0: if back.exists:
r = session.swipe_right() back.click()
if r.status == 0: return True
elif session.xpath("//*[@name='nav_bar_start_back']").exists:
back = session.xpath("//*[@name='nav_bar_start_back']")
back.click()
return True
elif session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]").exists:
back = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]")
back.click()
return True return True
else: else:
return False return False
else:
print("本页面无法返回")
return False
except Exception as e: except Exception as e:
print(e) print(e)
return False return False
@@ -80,23 +84,6 @@ class ControlUtils(object):
else: else:
print("没有找到目标") print("没有找到目标")
return False return False
# 点击评论
# @classmethod
# def clickComment(cls, session: Client):
# scale = session.scale
# x, y = AiUtils.findImageInScreen("add")
# print(x,y)
# if x > -1:
# print("找到目标了")
# r = session.click(x // scale, y // scale + 120)
# if r.status == 0:
# return True
# else:
# return False
# else:
# print("没有找到目标")
# return False
# 点击搜索 # 点击搜索
@classmethod @classmethod
@@ -110,6 +97,16 @@ class ControlUtils(object):
print(e) print(e)
return False return False
# 点击收件箱按钮
@classmethod
def clickMsgBox(cls, session: Client):
box = session.xpath("//XCUIElementTypeButton[name='a11y_vo_inbox']")
if box.exists:
box.click()
return True
else:
return False
# 获取主播详情页的第一个视频 # 获取主播详情页的第一个视频
@classmethod @classmethod
def clickFirstVideoFromDetailPage(cls, session: Client): def clickFirstVideoFromDetailPage(cls, session: Client):
@@ -121,28 +118,5 @@ class ControlUtils(object):
else: else:
return False return False
# 获取关注按钮
@classmethod
def clickFollowButton(cls, session: Client):
followButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]/Button[1]")
if followButton.exists:
print("找到了")
followButton.click()
return True
else:
print("没找到")
return False
# 查找发消息按钮
@classmethod
def clickSendMesageButton(cls, session: Client):
msgButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]")
if msgButton.exists:
print("找到了")
print(msgButton.name)
msgButton.click()
return True
else:
print("没找到")
return False

View File

@@ -196,6 +196,28 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 15}) session.appium_settings({"snapshotMaxDepth": 15})
# 点击搜索按钮 # 点击搜索按钮
ControlUtils.clickSearch(session) ControlUtils.clickSearch(session)
# 返回上一步
def goBack(count):
# 如需回复消息
if needReply:
count += 1
for i in range(count):
ControlUtils.clickBack(session)
time.sleep(2)
# 循环条件。1、 循环关闭 2、 数据处理完毕
while not event.is_set() or len(anchorList) > 0:
if needReply:
print("如果需要回复主播消息。走此逻辑")
if AiUtils.getUnReadMsgCount(session) > 0:
# 此处调用另外一个方法处理
# 设置查找深度
session.appium_settings({"snapshotMaxDepth": 15})
# 点击搜索按钮
ControlUtils.clickSearch(session)
# 查找输入框 # 查找输入框
input = session.xpath('//XCUIElementTypeSearchField') input = session.xpath('//XCUIElementTypeSearchField')
# 如果找到了输入框,就点击并且输入内容 # 如果找到了输入框,就点击并且输入内容
@@ -203,18 +225,6 @@ class ScriptManager():
# 稍作停顿 # 稍作停顿
time.sleep(1) time.sleep(1)
# 返回上一步
def goBack():
# ControlUtils.clickBack(session)
client.swipe(5,120, 50, 120)
# 删除数据
removeModelFromAnchorList(anchor)
# 循环条件。1、 循环关闭 2、 数据处理完毕
while not event.is_set() or len(anchorList) > 0:
# 获取一个主播 # 获取一个主播
anchor = anchorList[0] anchor = anchorList[0]
aid = anchor.anchorId aid = anchor.anchorId
@@ -229,16 +239,18 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 25}) session.appium_settings({"snapshotMaxDepth": 25})
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页 # 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
follow_button = session.xpath( follow_button = session.xpath('//XCUIElementTypeOther[@name="zhang1231511"]//XCUIElementTypeButton[@enabled="true" and @visible="true"]')
'//XCUIElementTypeCell[@index="1"]//XCUIElementTypeButton[@index="1"]').get() time.sleep(2)
if follow_button: if follow_button.exists:
print("找到关注按钮!") print("找到关注按钮!")
x = follow_button.bounds.x - 200 x = follow_button.bounds.x - 200
y = follow_button.bounds.y y = follow_button.bounds.y
client.click(x, y) client.click(x, y)
else: else:
goBack(1)
removeModelFromAnchorList(anchor)
print("未找到关注按钮") print("未找到关注按钮")
continue
time.sleep(3) time.sleep(3)
# 找到并点击第一个视频 # 找到并点击第一个视频
@@ -248,7 +260,8 @@ class ScriptManager():
def viewAnchorVideo(): def viewAnchorVideo():
print("开始查看视频") print("开始查看视频")
count = 2 count = 2
while count > 0: while count != 0:
time.sleep(5)
print("条件满足,继续查看") print("条件满足,继续查看")
img = client.screenshot() img = client.screenshot()
time.sleep(1) time.sleep(1)
@@ -256,44 +269,49 @@ class ScriptManager():
img.save(filePath) img.save(filePath)
LogManager.info("保存屏幕图像成功", udid) LogManager.info("保存屏幕图像成功", udid)
print("保存了背景图") print("保存了背景图")
time.sleep(1) time.sleep(2)
# 查找add图标
addX, addY = AiUtils.findImageInScreen("add", udid) addX, addY = AiUtils.findImageInScreen("add", udid)
if addX != -1: if addX != -1:
r = ControlUtils.clickLike(session, udid) r = ControlUtils.clickLike(session, udid)
# 如果点了赞,总数量-1 否则划下一个视频,无法点赞的原因多。指不定是什么原因。所以直接下一个视频比较好 # 点赞成功。总数量减1否则就滑到下一个视频。原因多。不好判断。不如直接下一个视频
if r: if r == True:
count -= 1 count -= 1
else: else:
client.swipe_up() client.swipe_up()
else: else:
print("没找有效视频")
client.swipe_up() client.swipe_up()
continue
# 假装看几秒视频
time.sleep(10)
client.swipe_up()
if count == 1:
client.swipe_right()
break break
# 点击第一个视频后的逻辑 # 假装看几秒视频
if cellClickResult: time.sleep(5)
client.swipe_up()
if count == 0:
ControlUtils.clickBack(session)
break
# 如果打开视频失败。说明该主播没有视频
if cellClickResult == True:
print("点击了视频") print("点击了视频")
session.appium_settings({"snapshotMaxDepth": 5}) session.appium_settings({"snapshotMaxDepth": 15})
time.sleep(2)
print("重新设置了匹配深度") print("重新设置了匹配深度")
viewAnchorVideo() viewAnchorVideo()
time.sleep(2) time.sleep(2)
print("视频看完了") print("视频看完了")
session.appium_settings({"snapshotMaxDepth": 25}) session.appium_settings({"snapshotMaxDepth": 25})
# 视频看完需要点关注。 # 点击关注按钮
r = ControlUtils.clickFollowButton(session) followButton = AiUtils.getFollowButton(session)
if r == False: if followButton.exists:
print("执行失败了") followButton.click()
else:
goBack(2)
return
time.sleep(2) time.sleep(2)
ControlUtils.clickFollowButton(session) AiUtils.getSendMesageButton(session)
time.sleep(2) time.sleep(2)
# 查找聊天界面中的输入框节点 # 查找聊天界面中的输入框节点
@@ -303,40 +321,31 @@ class ScriptManager():
# 准备发送一条信息 # 准备发送一条信息
chatInput.click() chatInput.click()
time.sleep(2) time.sleep(2)
# text = random.choice(prologueList) text = random.choice(prologueList)
# msg = Requester.translation(text, anchorCountry) msg = Requester.translation(text, anchorCountry)
chatInput.set_text("哈哈哈" + "\n") chatInput.set_text(msg + "\n")
time.sleep(1) time.sleep(1)
client.swipe_right()
time.sleep(1)
client.swipe_right()
time.sleep(2)
else: else:
print("没找到") print("无法发送信息,换个主播")
client.swipe_right() # 接着下一个主播
time.sleep(1) goBack(3)
client.swipe_right()
time.sleep(2)
break
# 清除数据 else:
print("没找到主播的第一个视频")
# 删除当前数据
removeModelFromAnchorList(anchor) removeModelFromAnchorList(anchor)
# 流程结束 goBack(2)
# client.swipe_right()
# time.sleep(1)
else:
print("获取该主播第一个视频失败")
goBack()
def test(self, udid): def test(self, udid):
client = wda.USBClient(udid) client = wda.USBClient(udid)
client.swipe_right() session = client.session()
session.appium_settings({"snapshotMaxDepth": 10})
print(client.source())
manager = ScriptManager() # manager = ScriptManager()
manager.test("eca000fcb6f55d7ed9b4c524055214c26a7de7aa") # manager.test("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")
# manager.growAccount("eca000fcb6f55d7ed9b4c524055214c26a7de7aa") # manager.growAccount("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")