合并代码
This commit is contained in:
5
.idea/workspace.xml
generated
5
.idea/workspace.xml
generated
@@ -5,11 +5,10 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="20250904-初步功能已完成">
|
||||
<change afterPath="$PROJECT_DIR$/resources/2335890f77fb51322361bd46b85f7fd1311aed53/bgv.png" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/resources/3157d8bd35c230012cb3640d2f26ffd0b61a10d1/bgv.png" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Module/FlaskService.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/FlaskService.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Utils/ThreadManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ThreadManager.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Utils/LogManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/LogManager.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/script/ScriptManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/script/ScriptManager.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
||||
@@ -305,6 +305,39 @@ def passAnchorData():
|
||||
LogManager.error(e)
|
||||
return ResultData(data="", code=1001).toJson()
|
||||
|
||||
@app.route('/followAndGreetUnion', methods=['POST'])
|
||||
def followAndGreetUnion():
|
||||
try:
|
||||
LogManager.method_info("关注打招呼", "关注打招呼(联盟号)")
|
||||
data: Dict[str, Any] = request.get_json()
|
||||
# 设备列表
|
||||
idList = data.get("deviceList", [])
|
||||
# 主播列表
|
||||
acList = data.get("anchorList", [])
|
||||
LogManager.info(f"[INFO] 获取数据: {idList} {acList}")
|
||||
|
||||
AiUtils.save_aclist_flat_append(acList)
|
||||
|
||||
# 是否需要回复
|
||||
needReply = data.get("needReply", True)
|
||||
# 获取打招呼数据
|
||||
ev.prologueList = data.get("prologueList", [])
|
||||
|
||||
# 添加主播数据
|
||||
addModelToAnchorList(acList)
|
||||
# 启动线程,执行脚本
|
||||
for udid in idList:
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
# 启动脚本
|
||||
thread = threading.Thread(target=manager.safe_followAndGreetUnion, args=(udid, needReply, event))
|
||||
# 添加到线程管理
|
||||
ThreadManager.add(udid, thread, event)
|
||||
return ResultData(data="").toJson()
|
||||
except Exception as e:
|
||||
LogManager.error(e)
|
||||
return ResultData(data="", code=1001).toJson()
|
||||
|
||||
|
||||
# 获取私信数据
|
||||
@app.route("/getPrologueList", methods=['GET'])
|
||||
|
||||
Binary file not shown.
@@ -26,7 +26,7 @@ def _force_utf8_everywhere():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# _force_utf8_everywhere()
|
||||
_force_utf8_everywhere()
|
||||
|
||||
class LogManager:
|
||||
"""
|
||||
|
||||
Binary file not shown.
@@ -621,6 +621,265 @@ class ScriptManager():
|
||||
|
||||
print("greetNewFollowers方法执行完毕")
|
||||
|
||||
def safe_followAndGreetUnion(self, udid, needReply, event):
|
||||
|
||||
retries = 0
|
||||
while not event.is_set():
|
||||
try:
|
||||
self.followAndGreetUnion(udid, needReply, event)
|
||||
|
||||
except Exception as e:
|
||||
retries += 1
|
||||
LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
|
||||
event.wait(timeout=3)
|
||||
|
||||
if event.is_set():
|
||||
LogManager.method_info("外层 while 检测到停止,即将 break", "关注打招呼", udid)
|
||||
break
|
||||
LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
|
||||
|
||||
# 关注打招呼以及回复主播消息(联盟号)
|
||||
def followAndGreetUnion(self, udid, needReply, event):
|
||||
|
||||
client = wda.USBClient(udid)
|
||||
session = client.session()
|
||||
|
||||
print(f"是否要自动回复消息:{needReply}")
|
||||
|
||||
LogManager.method_info(f"是否要自动回复消息:{needReply}", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 先关闭Tik Tok
|
||||
ControlUtils.closeTikTok(session, udid)
|
||||
event.wait(timeout=1)
|
||||
|
||||
# 重新打开Tik Tok
|
||||
ControlUtils.openTikTok(session, udid)
|
||||
event.wait(timeout=3)
|
||||
LogManager.method_info(f"重启tiktok", "关注打招呼(联盟号)", udid)
|
||||
# 设置查找深度
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
|
||||
# 创建udid名称的目录
|
||||
AiUtils.makeUdidDir(udid)
|
||||
|
||||
# 返回上一步
|
||||
def goBack(count):
|
||||
for i in range(count):
|
||||
LogManager.method_info(f"返回上一步", "关注打招呼(联盟号)", udid)
|
||||
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
ControlUtils.clickBack(session)
|
||||
event.wait(timeout=2)
|
||||
|
||||
LogManager.method_info(f"循环条件1:{not event.is_set()}", "关注打招呼(联盟号)", udid)
|
||||
LogManager.method_info(f"循环条件2:{len(anchorList) > 0}", "关注打招呼(联盟号)", udid)
|
||||
LogManager.method_info(f"循环条件3:{not event.is_set() and len(anchorList) > 0}", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 循环条件。1、 循环关闭 2、 数据处理完毕
|
||||
while not event.is_set():
|
||||
|
||||
LogManager.method_info("=== 外层 while 新一轮 ===", "关注打招呼(联盟号)", udid)
|
||||
if event.is_set():
|
||||
break
|
||||
|
||||
# 获取一个主播,
|
||||
LogManager.method_info(f"开始获取数据", "关注打招呼(联盟号)", udid)
|
||||
# 获取一个主播,
|
||||
result = AiUtils.peek_aclist_first()
|
||||
LogManager.method_info(f"数据是:{result}", "关注打招呼(联盟号)", udid)
|
||||
|
||||
state = result.get("state", 0)
|
||||
if not state:
|
||||
LogManager.method_info(f"当前主播的状态是:{state} 不通行,取出数据移到列表尾部 继续下一个",
|
||||
"关注打招呼(联盟号)",
|
||||
udid)
|
||||
AiUtils.pop_aclist_first(mode="move")
|
||||
continue
|
||||
|
||||
# 并删除
|
||||
anchor = AiUtils.pop_aclist_first()
|
||||
LogManager.method_info(f"当前主播的状态是:{state} 通行,取出数据删除", "关注打招呼(联盟号)", udid)
|
||||
|
||||
if not anchor:
|
||||
LogManager.method_info(f"数据库中的数据不足", "关注打招呼(联盟号)", udid)
|
||||
if not self.interruptible_sleep(event, 30):
|
||||
continue
|
||||
|
||||
aid = anchor.get("anchorId", "")
|
||||
anchorCountry = anchor.get("country", "")
|
||||
|
||||
LogManager.method_info(f"主播的数据,用户名:{aid},国家:{anchorCountry}", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 点击搜索按钮
|
||||
ControlUtils.clickSearch(session)
|
||||
|
||||
LogManager.method_info(f"点击搜索按钮", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 强制刷新session
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
|
||||
# 查找输入框
|
||||
input = session.xpath('//XCUIElementTypeSearchField')
|
||||
|
||||
# 如果找到了输入框,就点击并且输入内容
|
||||
if input.exists:
|
||||
input.click()
|
||||
# 稍作停顿
|
||||
event.wait(timeout=0.5)
|
||||
else:
|
||||
print(f"找不到输入框")
|
||||
|
||||
input = session.xpath('//XCUIElementTypeSearchField')
|
||||
if input.exists:
|
||||
input.clear_text()
|
||||
event.wait(timeout=1)
|
||||
# 输入主播id
|
||||
input.set_text(f"{aid or '暂无数据'}\n")
|
||||
|
||||
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
|
||||
|
||||
session.appium_settings({"snapshotMaxDepth": 25})
|
||||
|
||||
try:
|
||||
# 点击进入首页
|
||||
ControlUtils.clickFollow(session, aid)
|
||||
LogManager.method_info("点击进入主播首页", "关注打招呼(联盟号)", udid)
|
||||
except wda.WDAElementNotFoundError:
|
||||
LogManager.method_info("未找到进入主播首页的按钮,使用第二个方案。", "关注打招呼(联盟号)", udid)
|
||||
enter_room = ControlUtils.userClickProfile(session, aid)
|
||||
if not enter_room:
|
||||
goBack(2)
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
continue
|
||||
|
||||
event.wait(timeout=2)
|
||||
|
||||
session.appium_settings({"snapshotMaxDepth": 25})
|
||||
event.wait(timeout=0.5)
|
||||
# 向上滑动
|
||||
session.swipe_down()
|
||||
|
||||
event.wait(timeout=2)
|
||||
msgButton = AiUtils.getSendMesageButton(session)
|
||||
event.wait(timeout=2)
|
||||
|
||||
if msgButton.exists:
|
||||
# 进入聊天页面
|
||||
msgButton.click()
|
||||
LogManager.method_info("找到发消息按钮了", "关注打招呼(联盟号)", udid)
|
||||
print("找到发消息按钮了")
|
||||
else:
|
||||
LogManager.method_info("没有识别出发消息按钮", "关注打招呼(联盟号)", udid)
|
||||
print("没有识别出发消息按钮")
|
||||
goBack(3)
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
continue
|
||||
|
||||
event.wait(timeout=3)
|
||||
# 查找聊天界面中的输入框节点
|
||||
chatInput = session.xpath("//TextView")
|
||||
if chatInput.exists:
|
||||
|
||||
print("找到输入框了, 准备发送一条打招呼消息")
|
||||
LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼(联盟号)", udid)
|
||||
|
||||
print("打招呼的数据", ev.prologueList)
|
||||
LogManager.method_info(f"传递的打招呼的数据:{ev.prologueList}", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 准备打招呼的文案
|
||||
text = random.choice(ev.prologueList)
|
||||
# text = 'hello'
|
||||
|
||||
LogManager.method_info(f"取出打招呼的数据,{text}, 判断是否需要翻译", "关注打招呼(联盟号)", udid)
|
||||
|
||||
isContainChniese = AiUtils.contains_chinese(text)
|
||||
|
||||
if isContainChniese:
|
||||
# 翻译成主播国家的语言
|
||||
LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译",
|
||||
"关注打招呼(联盟号)", udid)
|
||||
|
||||
msg = Requester.translation(text, anchorCountry)
|
||||
|
||||
LogManager.method_info(f"翻译成功:{msg}, ", "关注打招呼(联盟号)", udid)
|
||||
|
||||
else:
|
||||
msg = text
|
||||
LogManager.method_info(f"即将发送的私信内容:{msg}", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 准备发送一条信息
|
||||
chatInput = session.xpath("//TextView")
|
||||
if chatInput.exists:
|
||||
chatInput.click()
|
||||
chatInput.set_text(f"{msg or '暂无数据'}\n")
|
||||
event.wait(timeout=2)
|
||||
# 发送消息
|
||||
# input.set_text(f"{aid or '暂无数据'}\n")
|
||||
event.wait(timeout=1)
|
||||
else:
|
||||
print("无法发送信息")
|
||||
LogManager.method_info(f"给主播{aid} 发送消息失败", "关注打招呼(联盟号)", udid)
|
||||
|
||||
# 接着下一个主播
|
||||
goBack(1)
|
||||
|
||||
# 点击关注按钮
|
||||
# followButton = AiUtils.getFollowButton(session).get(timeout=5)
|
||||
# if followButton is not None:
|
||||
# # LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
|
||||
# # followButton.click()
|
||||
# x, y, w, h = followButton.bounds
|
||||
# cx = int(x + w / 2)
|
||||
# cy = int(y + h / 2)
|
||||
# # 随机偏移 ±5 px(可自己改范围)
|
||||
# cx += random.randint(-5, 5)
|
||||
# cy += random.randint(-5, 5)
|
||||
#
|
||||
# ControlUtils.tap_mini_cluster(cx, cy, session)
|
||||
#
|
||||
# else:
|
||||
# LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
|
||||
# time.sleep(1)
|
||||
# goBack(4)
|
||||
# session.appium_settings({"snapshotMaxDepth": 15})
|
||||
# continue
|
||||
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
goBack(3)
|
||||
|
||||
# 设置查找深度
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
event.wait(timeout=2)
|
||||
print("即将要回复消息")
|
||||
LogManager.method_info("即将要回复消息", "关注打招呼(联盟号)", udid)
|
||||
|
||||
if needReply:
|
||||
print("如果需要回复主播消息。走此逻辑")
|
||||
|
||||
print("----------------------------------------------------------")
|
||||
print("监控回复消息")
|
||||
# 执行回复消息逻辑
|
||||
self.monitorMessages(session, udid, event)
|
||||
|
||||
homeButton = AiUtils.findHomeButton(udid)
|
||||
if homeButton.exists:
|
||||
homeButton.click()
|
||||
else:
|
||||
ControlUtils.closeTikTok(session, udid)
|
||||
event.wait(timeout=2)
|
||||
ControlUtils.openTikTok(session, udid)
|
||||
event.wait(timeout=3)
|
||||
|
||||
print("重新创建wda会话 防止wda会话失效")
|
||||
client = wda.USBClient(udid)
|
||||
session = client.session()
|
||||
# 执行完成之后。继续点击搜索
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
else:
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
|
||||
print("greetNewFollowers方法执行完毕")
|
||||
|
||||
# 检测消息
|
||||
def replyMessages(self, udid, event):
|
||||
client = wda.USBClient(udid)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user