diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a95bbca..808d1e0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,17 +5,10 @@
-
-
-
-
-
-
-
-
+
+
-
@@ -86,7 +79,7 @@
-
+
@@ -203,7 +196,8 @@
-
+
+
@@ -213,7 +207,15 @@
1756303135240
-
+
+
+ 1757421902950
+
+
+
+ 1757421902950
+
+
@@ -236,7 +238,8 @@
-
+
+
@@ -247,8 +250,8 @@
-
-
+
+
\ No newline at end of file
diff --git a/Entity/Variables.py b/Entity/Variables.py
index baf5f88..4d663e2 100644
--- a/Entity/Variables.py
+++ b/Entity/Variables.py
@@ -2,7 +2,6 @@ import threading
from typing import Dict, Any
from Entity.AnchorModel import AnchorModel
-
# wda apple bundle id
WdaAppBundleId = "com.yolozsAgent.wda.xctrunner"
@@ -11,7 +10,26 @@ anchorList: list[AnchorModel] = []
# 线程锁
anchorListLock = threading.Lock()
# 打招呼数据
-prologueList: list[str] = []
+prologueList: list[str] = ["hello"]
+
+# 本地储存的打招呼数据
+localPrologueList = [
+ "If you are interested in this, you can join our team for a period of time. During this period, if you like our team, you can continue to stay in our team. If you don't like it, you can leave at any time, and you won't lose anything!",
+ "What's even better is that after joining our team, you have no obligations and you don't have to pay me. Everything is free",
+ "I'm from the MARS agency. I noticed that you're very active on TikTok, so I contacted you and hope to become your agent❤",
+ "Hello, can we talk about cooperation and support?",
+ "Hello, I’m a supporter. Can we have a chat?",
+ "Hi 👋 I’m an official TikTok partner. I really enjoy your livestreams. Do you have time to chat about support and cooperation?",
+ "Hello, I really like your livestreams. I’d love to talk about cooperation and also support you.",
+ "Hello, I think you have the potential to become a top streamer. Can we talk?",
+ "Nice to meet you 😊 I watched your livestream and really enjoyed it. Can we chat about cooperation?",
+ "Hello 👋 I’m a livestream team manager. I recently watched your livestream—it’s great 👍 I hope we can talk about how to grow together 💪",
+ "I watched your livestream and would like to invite you to join our team. I’ll reward you with more gifts based on your performance.",
+ "Hello, I’d like to promote your livestream. Can we talk?",
+ "Hello, I think I can help you get more gifts and support for free. Would you be interested in talking with me?",
+ "Hello, I really enjoyed your livestream. Can we chat about cooperation?"
+]
+
# 评论列表
commentsList = []
# 存储主播名和session_id的字典
@@ -29,6 +47,7 @@ def removeModelFromAnchorList(model: AnchorModel):
with anchorListLock:
anchorList.remove(model)
+
# 添加数据
def addModelToAnchorList(models: list[Dict[str, Any]]):
with anchorListLock:
@@ -36,7 +55,7 @@ def addModelToAnchorList(models: list[Dict[str, Any]]):
obj = AnchorModel.dictToModel(dic)
anchorList.append(obj)
+
# 添加打招呼语
def addDataToPrologue(data: list[str]):
-
- prologueList = data
\ No newline at end of file
+ prologueList = data
diff --git a/Utils/ControlUtils.py b/Utils/ControlUtils.py
index b905b42..39a0f72 100644
--- a/Utils/ControlUtils.py
+++ b/Utils/ControlUtils.py
@@ -58,6 +58,8 @@ class ControlUtils(object):
back = session.xpath(
"//*[@label='返回']"
" | "
+ "//*[@label='返回上一屏幕']"
+ " | "
"//XCUIElementTypeButton[@visible='true' and @name='TTKProfileNavBarBaseItemComponent' and @label='IconChevronLeftOffsetLTR']"
)
@@ -125,8 +127,9 @@ class ControlUtils(object):
videoCell = session.xpath(
'(//XCUIElementTypeCollectionView//XCUIElementTypeCell[.//XCUIElementTypeImage[@name="profile_video"]])[1]')
- tab = session.xpath('//XCUIElementTypeButton[@name="TTKProfileTabVideoButton_0"]').get(timeout=2)
- # 某些版本 tab.value 可能就是数量;或者 tab.label 类似 “作品 7”
+ tab = session.xpath(
+ '//XCUIElementTypeButton[@name="TTKProfileTabVideoButton_0" or contains(@label,"作品") or contains(@name,"作品")]'
+ ).get(timeout=5) # 某些版本 tab.value 可能就是数量;或者 tab.label 类似 “作品 7”
m = re.search(r"\d+", tab.label)
num = 0
diff --git a/Utils/Requester.py b/Utils/Requester.py
index b2c1176..6545167 100644
--- a/Utils/Requester.py
+++ b/Utils/Requester.py
@@ -11,15 +11,18 @@ class Requester():
@classmethod
def requestPrologue(cls, token):
- headers = {
- "vvtoken": token,
- }
- url = BaseUrl + cls.prologue
- result = requests.get(headers=headers, url=url)
- json = result.json()
- data = json.get("data")
- for i in data:
- prologueList.append(i)
+ try:
+ headers = {
+ "vvtoken": token,
+ }
+ url = BaseUrl + cls.prologue
+ result = requests.get(headers=headers, url=url)
+ json = result.json()
+ data = json.get("data")
+ for i in data:
+ prologueList.append(i)
+ except Exception as e:
+ LogManager.method_error(f"获取requestPrologue失败,报错的原因:{e}", "获取requestPrologue异常")
# 翻译
@classmethod
@@ -29,20 +32,23 @@ class Requester():
"msg": msg,
"country": country,
}
- url = "http://ai.zhukeping.com/translation"
+ url = "https://ai.yolozs.com/translation"
result = requests.request(url=url, json=parame, method="POST")
json = result.json()
data = json.get("data")
print(data)
return data
except Exception as e:
- LogManager.method_error(f"翻译失败,报错的原因:{e}","翻译失败")
+ LogManager.method_error(f"翻译失败,报错的原因:{e}", "翻译失败异常")
# ai聊天
@classmethod
def chatToAi(cls, param):
- url = "http://ai.zhukeping.com/chat"
- result = requests.request(url=url, json=param, method="POST")
- json = result.json()
- data = json.get("data", {})
- return data
+ try:
+ url = "https://ai.yolozs.com/chat"
+ result = requests.request(url=url, json=param, method="POST")
+ json = result.json()
+ data = json.get("data", {})
+ return data
+ except Exception as e:
+ LogManager.method_error(f"ai聊天失败,ai聊天出现异常,报错的原因:{e}", "ai聊天接口异常")
diff --git a/script/ScriptManager.py b/script/ScriptManager.py
index 71cab47..c796670 100644
--- a/script/ScriptManager.py
+++ b/script/ScriptManager.py
@@ -170,7 +170,8 @@ class ScriptManager():
time.sleep(3)
# 2) 进入直播 (使用英文)
- live_button = session(xpath='//XCUIElementTypeButton[@name="直播"]')
+ live_button = session(
+ xpath='//XCUIElementTypeButton[@name="直播"] | //XCUIElementTypeOther[@name="直播"]')
if live_button.exists:
live_button.click()
@@ -275,21 +276,19 @@ class ScriptManager():
retries = 0
while not event.is_set():
- try:
- anchor = AiUtils.pop_aclist_first()
-
- if not anchor:
- break
-
- self.greetNewFollowers(udid, needReply, event)
- return # 成功执行就退出
- except Exception as e:
- retries += 1
- LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
- time.sleep(3)
- LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
-
+ # try:
+ # anchor = AiUtils.pop_aclist_first()
+ #
+ # if not anchor:
+ # break
+ self.greetNewFollowers(udid, needReply, event)
+ # return # 成功执行就退出
+ # except Exception as e:
+ # retries += 1
+ # LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
+ # time.sleep(3)
+ # LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
# 关注打招呼以及回复主播消息
def greetNewFollowers(self, udid, needReply, event):
@@ -436,18 +435,6 @@ class ScriptManager():
# 向上滑动
session.swipe_down()
- # 点击关注按钮
- followButton = AiUtils.getFollowButton(session)
- if followButton is not None:
- LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
- followButton.click()
- else:
- LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
- time.sleep(1)
- goBack(3)
- session.appium_settings({"snapshotMaxDepth": 15})
- continue
-
time.sleep(2)
msgButton = AiUtils.getSendMesageButton(session)
time.sleep(2)
@@ -476,13 +463,12 @@ class ScriptManager():
# 准备打招呼的文案
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}, 即将进行翻译", "关注打招呼", udid)
@@ -494,21 +480,37 @@ class ScriptManager():
msg = text
LogManager.method_info(f"即将发送的私信内容:{msg}", "关注打招呼", udid)
-
# 准备发送一条信息
chatInput.click()
time.sleep(2)
# 发送消息
chatInput.set_text(msg + "\n")
time.sleep(1)
+
+
+
else:
print("无法发送信息")
LogManager.method_info(f"给主播{aid} 发送消息失败", "关注打招呼", udid)
# 接着下一个主播
# removeModelFromAnchorList(anchor)
+ goBack(1)
+
+ # 点击关注按钮
+ followButton = AiUtils.getFollowButton(session)
+ if followButton is not None:
+ LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
+ followButton.click()
+ else:
+ LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
+ time.sleep(1)
+ goBack(4)
+ session.appium_settings({"snapshotMaxDepth": 15})
+ continue
+
session.appium_settings({"snapshotMaxDepth": 15})
- goBack(4)
+ goBack(3)
else:
print(f"{aid}:该主播没有视频")
@@ -580,7 +582,13 @@ class ScriptManager():
# 调整节点的深度为 7
session.appium_settings({"snapshotMaxDepth": 7})
- el = session(xpath='//XCUIElementTypeButton[@name="a11y_vo_inbox"]')
+ el = session.xpath(
+ '//XCUIElementTypeButton[@name="a11y_vo_inbox"]'
+ ' | '
+ '//XCUIElementTypeButton[contains(@name,"收件箱")]'
+ ' | '
+ '//XCUIElementTypeButton[.//XCUIElementTypeStaticText[@value="收件箱"]]'
+ )
# 如果收件箱有消息 则进行点击
if el.exists:
@@ -594,7 +602,14 @@ class ScriptManager():
info_count = 0
# 创建新的会话
- el = session(xpath='//XCUIElementTypeButton[@name="a11y_vo_inbox"]')
+ el = session.xpath(
+ '//XCUIElementTypeButton[@name="a11y_vo_inbox"]'
+ ' | '
+ '//XCUIElementTypeButton[contains(@name,"收件箱")]'
+ ' | '
+ '//XCUIElementTypeButton[.//XCUIElementTypeStaticText[@value="收件箱"]]'
+ )
+
print("el", el)
if not el.exists:
LogManager.method_error(f"检测不到收件箱", "检测消息", udid)
@@ -649,11 +664,26 @@ class ScriptManager():
)
# 用户消息
+ # xp_badge_numeric = (
+ # '//XCUIElementTypeOther['
+ # ' @name="AWEIMChatListCellUnreadCountViewComponent"'
+ # ' or @name="TikTokIMImpl.InboxCellUnreadCountViewBuilder"'
+ # ']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
+ # )
+
xp_badge_numeric = (
- '//XCUIElementTypeOther['
- ' @name="AWEIMChatListCellUnreadCountViewComponent"'
- ' or @name="TikTokIMImpl.InboxCellUnreadCountViewBuilder"'
- ']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
+ "("
+ # 你的两类未读容器组件 + 数字徽标(value 纯数字)
+ "//XCUIElementTypeOther["
+ " @name='AWEIMChatListCellUnreadCountViewComponent'"
+ " or @name='TikTokIMImpl.InboxCellUnreadCountViewBuilder'"
+ "]//XCUIElementTypeStaticText[@value and translate(@value,'0123456789','')='']"
+ ")/ancestor::XCUIElementTypeCell[1]"
+ " | "
+ # 兜底:任何在 CollectionView 下、value 纯数字的徽标 → 找其最近的 Cell
+ "//XCUIElementTypeCollectionView//XCUIElementTypeStaticText"
+ "[@value and translate(@value,'0123456789','')='']"
+ "/ancestor::XCUIElementTypeCell[1]"
)
try:
@@ -682,7 +712,7 @@ class ScriptManager():
'Do you think I’m one of the most engaging streamers you’ve seen?']
last_msg = next((item['text'] for item in reversed(msgs) if item['type'] == 'msg'),
- random.choice(text_list))
+ random.choice(text_list))
isLanguage = AiUtils.is_language(last_msg)
if isLanguage: