合并代码
This commit is contained in:
2
.idea/iOSAI.iml
generated
2
.idea/iOSAI.iml
generated
@@ -4,7 +4,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.12 (IOS-AI)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (IOS-AI)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -2,15 +2,15 @@ import json
|
||||
|
||||
# 返回数据模型
|
||||
class ResultData(object):
|
||||
def __init__(self, code=200, data=None, msg="获取成功"):
|
||||
def __init__(self, code=200, data=None, massage="获取成功"):
|
||||
super(ResultData, self).__init__()
|
||||
self.code = code
|
||||
self.data = data
|
||||
self.msg = msg
|
||||
self.massage = massage
|
||||
|
||||
def toJson(self):
|
||||
return json.dumps({
|
||||
"code": self.code,
|
||||
"data": self.data,
|
||||
"msg": self.msg
|
||||
"massage": self.massage
|
||||
}, ensure_ascii=False) # ensure_ascii=False 确保中文不会被转义
|
||||
@@ -266,8 +266,8 @@ def watchLiveForGrowth():
|
||||
def stopScript():
|
||||
body = request.get_json()
|
||||
udid = body.get("udid")
|
||||
code, msg = ThreadManager.stop(udid)
|
||||
return ResultData(code=code, data="", msg=msg).toJson()
|
||||
code, massage = ThreadManager.stop(udid)
|
||||
return ResultData(code=code, data="", massage=massage).toJson()
|
||||
|
||||
|
||||
# 关注打招呼
|
||||
@@ -320,7 +320,7 @@ def addTempAnchorData():
|
||||
"""
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return ResultData(code=400, msg="请求数据为空").toJson()
|
||||
return ResultData(code=400, massage="请求数据为空").toJson()
|
||||
# 追加到 JSON 文件
|
||||
AiUtils.save_aclist_flat_append(data, "log/acList.json")
|
||||
return ResultData(data="ok").toJson()
|
||||
@@ -344,17 +344,17 @@ def getChatTextInfo():
|
||||
|
||||
data = [
|
||||
{
|
||||
'type': 'msg',
|
||||
'type': 'massage',
|
||||
'dir': 'in',
|
||||
'text': '当前页面无法获取聊天记录,请在tiktok聊天页面进行获取!!!'
|
||||
},
|
||||
{
|
||||
'type': 'msg',
|
||||
'type': 'massage',
|
||||
'dir': 'in',
|
||||
'text': 'Unable to retrieve chat messages on the current screen. Please navigate to the TikTok chat page and try again!!!'
|
||||
}
|
||||
]
|
||||
return ResultData(data=data, msg="解析失败").toJson()
|
||||
return ResultData(data=data, massage="解析失败").toJson()
|
||||
|
||||
|
||||
# 监控消息
|
||||
@@ -381,7 +381,7 @@ def upLoadLogLogs():
|
||||
if ok:
|
||||
return ResultData(data="日志上传成功").toJson()
|
||||
else:
|
||||
return ResultData(data="", msg="日志上传失败").toJson()
|
||||
return ResultData(data="", massage="日志上传失败").toJson()
|
||||
|
||||
|
||||
# 获取当前的主播列表数据
|
||||
@@ -449,8 +449,8 @@ def update_last_message():
|
||||
multi=False # 只改第一条匹配的
|
||||
)
|
||||
if updated_count > 0:
|
||||
return ResultData(data=updated_count, msg="修改成功").toJson()
|
||||
return ResultData(data=updated_count, msg="修改失败").toJson()
|
||||
return ResultData(data=updated_count, massage="修改成功").toJson()
|
||||
return ResultData(data=updated_count, massage="修改失败").toJson()
|
||||
|
||||
|
||||
@app.route("/delete_last_message", methods=['POST'])
|
||||
@@ -466,8 +466,8 @@ def delete_last_message():
|
||||
multi=False # 只改第一条匹配的
|
||||
)
|
||||
if updated_count > 0:
|
||||
return ResultData(data=updated_count, msg="修改成功").toJson()
|
||||
return ResultData(data=updated_count, msg="修改失败").toJson()
|
||||
return ResultData(data=updated_count, massage="修改成功").toJson()
|
||||
return ResultData(data=updated_count, massage="修改失败").toJson()
|
||||
|
||||
|
||||
# @app.route("/killWda", methods=['POST'])
|
||||
|
||||
@@ -406,6 +406,7 @@ class AiUtils(object):
|
||||
'分享发布内容', '视频贴纸标签页', '双击发送表情', '贴纸',
|
||||
}
|
||||
SYSTEM_PATTERNS = [
|
||||
r"(消息请求已被接受|你开始了和.*的聊天|你打开了这个与.*的聊天).*"
|
||||
r"回复时接收通知", r"开启(私信)?通知", r"开启通知",
|
||||
r"你打开了这个与 .* 的聊天。.*隐私",
|
||||
r"在此用户接受你的消息请求之前,你最多只能发送 ?\d+ 条消息。?",
|
||||
|
||||
@@ -150,6 +150,8 @@ class ControlUtils(object):
|
||||
print("没有找到主页的第一个视频")
|
||||
return False, num
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def clickFollow(cls, session, aid):
|
||||
# 1) 含“关注/已关注/Follow/Following”的首个 cell
|
||||
@@ -177,6 +179,33 @@ class ControlUtils(object):
|
||||
left_x = max(1, rect.x - 20)
|
||||
center_y = rect.y + rect.height // 2
|
||||
session.tap(left_x, center_y)
|
||||
@classmethod
|
||||
def userClickProfile(cls, session, aid):
|
||||
try:
|
||||
user_btn = session.xpath("(//XCUIElementTypeButton[@name='用户' and @visible='true'])[1]")
|
||||
if user_btn:
|
||||
user_btn.click()
|
||||
time.sleep(3)
|
||||
follow_btn = session.xpath(
|
||||
"(//XCUIElementTypeTable//XCUIElementTypeButton[@name='关注' or @name='已关注'])[1]"
|
||||
).get(timeout=5)
|
||||
if follow_btn:
|
||||
x, y, w, h = follow_btn.bounds
|
||||
# 垂直方向中心 + 随机 3~8 像素偏移
|
||||
cy = int(y + h / 2 + random.randint(-8, 8))
|
||||
# 横向往左偏移 80~120 像素之间的随机值
|
||||
cx = int(x - random.randint(80, 120))
|
||||
# 点击
|
||||
session.tap(cx, cy)
|
||||
return True
|
||||
|
||||
return False
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 随机滑动一点点距离
|
||||
|
||||
@@ -17,7 +17,7 @@ class Requester():
|
||||
"vvtoken": token,
|
||||
}
|
||||
url = BaseUrl + cls.prologue
|
||||
result = requests.get(headers=headers, url=url)
|
||||
result = requests.get(headers=headers, url=url, verify=False)
|
||||
json = result.json()
|
||||
data = json.get("data")
|
||||
for i in data:
|
||||
@@ -29,14 +29,18 @@ class Requester():
|
||||
@classmethod
|
||||
def translation(cls, msg, country="英国"):
|
||||
try:
|
||||
if country == "":
|
||||
country = "英国"
|
||||
|
||||
param = {
|
||||
"msg": msg,
|
||||
"country": country,
|
||||
}
|
||||
url = "https://ai.yolozs.com/translation"
|
||||
result = requests.post(url=url, json=param)
|
||||
result = requests.post(url=url, json=param, verify=False)
|
||||
|
||||
LogManager.info(f"翻译,状态码:{result.status_code},服务器返回的内容:{result.text}")
|
||||
LogManager.info(f"翻译 请求的参数:{param}", "翻译")
|
||||
LogManager.info(f"翻译,状态码:{result.status_code},服务器返回的内容:{result.text}", "翻译")
|
||||
|
||||
if result.status_code != 200:
|
||||
LogManager.error(f"翻译失败,状态码:{result.status_code},服务器返回的内容:{result.text}")
|
||||
@@ -66,11 +70,9 @@ class Requester():
|
||||
|
||||
param["inputs"] = inputs
|
||||
|
||||
print(param)
|
||||
|
||||
try:
|
||||
url = "https://ai.yolozs.com/chat"
|
||||
result = requests.post(url=url, json=param)
|
||||
result = requests.post(url=url, json=param, verify=False)
|
||||
json = result.json()
|
||||
data = json.get("answer", {})
|
||||
session_id = json.get("conversation_id", {})
|
||||
|
||||
@@ -368,18 +368,19 @@ class ScriptManager():
|
||||
|
||||
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
|
||||
|
||||
session.appium_settings({"snapshotMaxDepth": 23})
|
||||
session.appium_settings({"snapshotMaxDepth": 25})
|
||||
|
||||
try:
|
||||
# 点击进入首页
|
||||
ControlUtils.clickFollow(session, aid)
|
||||
LogManager.method_info("点击进入主播首页", "关注打招呼", udid)
|
||||
except wda.WDAElementNotFoundError:
|
||||
LogManager.method_info("未找到进入主播首页的按钮,跳过点击。", "关注打招呼", udid)
|
||||
goBack(2)
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
continue
|
||||
|
||||
LogManager.method_info("未找到进入主播首页的按钮,使用第二个方案。", "关注打招呼", udid)
|
||||
enter_room = ControlUtils.userClickProfile(session, aid)
|
||||
if not enter_room:
|
||||
goBack(2)
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
continue
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
@@ -481,7 +482,8 @@ class ScriptManager():
|
||||
|
||||
if isContainChniese:
|
||||
# 翻译成主播国家的语言
|
||||
LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译", "关注打招呼", udid)
|
||||
LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译",
|
||||
"关注打招呼", udid)
|
||||
|
||||
msg = Requester.translation(text, anchorCountry)
|
||||
|
||||
@@ -510,10 +512,19 @@ class ScriptManager():
|
||||
goBack(1)
|
||||
|
||||
# 点击关注按钮
|
||||
# followButton = AiUtils.getFollowButton(session)
|
||||
# followButton = AiUtils.getFollowButton(session).get(timeout=5)
|
||||
# if followButton is not None:
|
||||
# LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
|
||||
# followButton.click()
|
||||
# # 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)
|
||||
@@ -734,7 +745,8 @@ class ScriptManager():
|
||||
|
||||
last_msg_text = last_msg
|
||||
else:
|
||||
LogManager.method_info(f"对方发送的消息不是语言,随机挑选作为最后一条进行回复:{last_msg}", "检测消息", udid)
|
||||
LogManager.method_info(f"对方发送的消息不是语言,随机挑选作为最后一条进行回复:{last_msg}",
|
||||
"检测消息", udid)
|
||||
last_msg_text = random.choice(text_list)
|
||||
|
||||
if AiUtils.contains_chinese(last_msg_text):
|
||||
|
||||
Reference in New Issue
Block a user