20250904-初步功能已完成

This commit is contained in:
2025-09-10 16:54:05 +08:00
parent e2e9e0b348
commit f6dda59c9f
5 changed files with 136 additions and 75 deletions

33
.idea/workspace.xml generated
View File

@@ -5,17 +5,10 @@
</component>
<component name="ChangeListManager">
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="20250904-初步功能已完成">
<change afterPath="$PROJECT_DIR$/123.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Module/log/acList.json" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nuitka-crash-report.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/resources/de041fd6509353490f5d2244a2079e94135bc1ee/bgv.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/iOSAI.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/iOSAI.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/LogManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/LogManager.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Entity/Variables.py" beforeDir="false" afterPath="$PROJECT_DIR$/Entity/Variables.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/ControlUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ControlUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/Requester.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/Requester.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build.bat" beforeDir="false" afterPath="$PROJECT_DIR$/build.bat" 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" />
@@ -86,7 +79,7 @@
<recent name="E:\Code\python\iOSAI" />
</key>
</component>
<component name="RunManager" selected="Python.Main">
<component name="RunManager" selected="Python.123">
<configuration name="123" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="iOSAI" />
<option name="ENV_FILES" value="" />
@@ -203,7 +196,8 @@
<workItem from="1757401525466" duration="46000" />
<workItem from="1757401583931" duration="29000" />
<workItem from="1757401717530" duration="4191000" />
<workItem from="1757411020282" duration="6895000" />
<workItem from="1757411020282" duration="11755000" />
<workItem from="1757480739367" duration="13433000" />
</task>
<task id="LOCAL-00001" summary="ai 开始测试">
<option name="closed" value="true" />
@@ -213,7 +207,15 @@
<option name="project" value="LOCAL" />
<updated>1756303135240</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="20250904-初步功能已完成">
<option name="closed" value="true" />
<created>1757421902950</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1757421902950</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -236,7 +238,8 @@
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="ai 开始测试" />
<option name="LAST_COMMIT_MESSAGE" value="ai 开始测试" />
<MESSAGE value="20250904-初步功能已完成" />
<option name="LAST_COMMIT_MESSAGE" value="20250904-初步功能已完成" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/iOSAI$LogManager.coverage" NAME="LogManager 覆盖结果" MODIFIED="1756711414832" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/Utils" />
@@ -247,8 +250,8 @@
<SUITE FILE_PATH="coverage/iOSAI$tidevice_entry.coverage" NAME="tidevice_entry 覆盖结果" MODIFIED="1757061969626" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/iOSAI$mac_wda_agent.coverage" NAME="mac_wda_agent Coverage Results" MODIFIED="1756473148639" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/script" />
<SUITE FILE_PATH="coverage/iOSAI$ScriptManager.coverage" NAME="ScriptManager 覆盖结果" MODIFIED="1756896057801" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/script" />
<SUITE FILE_PATH="coverage/iOSAI$Main.coverage" NAME="Main 覆盖结果" MODIFIED="1757421681940" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
<SUITE FILE_PATH="coverage/iOSAI$123.coverage" NAME="123 覆盖结果" MODIFIED="1757418859123" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/iOSAI$Main.coverage" NAME="Main 覆盖结果" MODIFIED="1757492700191" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
<SUITE FILE_PATH="coverage/iOSAI$123.coverage" NAME="123 覆盖结果" MODIFIED="1757494013218" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/iOSAI$2111.coverage" NAME="2111 覆盖结果" MODIFIED="1757330714370" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

View File

@@ -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, Im a supporter. Can we have a chat?",
"Hi 👋 Im 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. Id 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 👋 Im a livestream team manager. I recently watched your livestream—its 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. Ill reward you with more gifts based on your performance.",
"Hello, Id 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
prologueList = data

View File

@@ -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

View File

@@ -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聊天接口异常")

View File

@@ -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 Im one of the most engaging streamers youve 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: