diff --git a/Entity/Variables.py b/Entity/Variables.py index c02f801..d3afcf8 100644 --- a/Entity/Variables.py +++ b/Entity/Variables.py @@ -11,7 +11,13 @@ anchorList: list[AnchorModel] = [] # 线程锁 anchorListLock = threading.Lock() # 账号token -accountToken = None +accountToken = "xHtil6YiAH2QxDgAYVwCfVafx7xkOoeHVfiVgfqfdwe88KZW5jbRsjDS9ZGFILJSGuXTu4V29MgHaYnO3jy2dxpqs77DtAQGnW6AlJ7NItSWSmSaoKRXtCYEng9KlCft" +# 打招呼数据 +prologueList = [] +# 评论列表 +commentsList = [] + + # 安全删除数据 def removeModelFromAnchorList(model: AnchorModel): @@ -24,3 +30,4 @@ def addModelToAnchorList(models: list[Dict[str, Any]]): for dic in models: obj = AnchorModel.dictToModel(dic) anchorList.append(obj) + diff --git a/Utils/ControlUtils.py b/Utils/ControlUtils.py index 751faaa..c5313ea 100644 --- a/Utils/ControlUtils.py +++ b/Utils/ControlUtils.py @@ -124,7 +124,7 @@ class ControlUtils(object): # 获取关注按钮 @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]') + 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() diff --git a/Utils/Requester.py b/Utils/Requester.py index 9be95be..bb569e5 100644 --- a/Utils/Requester.py +++ b/Utils/Requester.py @@ -1,7 +1,45 @@ -from Entity.Variables import accountToken +import requests +from Entity.Variables import accountToken, prologueList + +# BaseUrl = "https://crawlclient.api.yolozs.com/api/common/" +BaseUrl = "http://192.168.1.174:8101/api/common/" + class Requester(): - + comment = "comment" + prologue = "prologue" @classmethod - def printToken(cls): - print(accountToken) + def requestComments(cls): + headers = { + "vvtoken": accountToken, + } + 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) + + + # 翻译 + @classmethod + def translation(cla, msg, country="英国"): + parame = { + "msg":msg, + "country":country, + } + url = "http://ai.zhukeping.com/translation" + result = requests.request(url=url, json=parame, method="POST") + json = result.json() + data = json.get("data") + print(data) + return data + + # 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 \ No newline at end of file diff --git a/resources/eca000fcb6f55d7ed9b4c524055214c26a7de7aa/bgv.png b/resources/eca000fcb6f55d7ed9b4c524055214c26a7de7aa/bgv.png index f6c50dc..c78af6b 100644 Binary files a/resources/eca000fcb6f55d7ed9b4c524055214c26a7de7aa/bgv.png and b/resources/eca000fcb6f55d7ed9b4c524055214c26a7de7aa/bgv.png differ diff --git a/script/ScriptManager.py b/script/ScriptManager.py index 43085f6..c97e78a 100644 --- a/script/ScriptManager.py +++ b/script/ScriptManager.py @@ -7,7 +7,8 @@ import os from Utils.AiUtils import AiUtils from Utils.ControlUtils import ControlUtils from Utils.LogManager import LogManager -from Entity.Variables import anchorList, removeModelFromAnchorList +from Entity.Variables import anchorList, removeModelFromAnchorList, prologueList +from Utils.Requester import Requester # 脚本管理类 @@ -182,7 +183,6 @@ class ScriptManager(): def greetNewFollowers(self, udid, needReply, event): client = wda.USBClient(udid) session = client.session() - session.appium_settings({"snapshotMaxDepth": 15}) # 先关闭Tik Tok ControlUtils.closeTikTok(session, udid) @@ -192,9 +192,11 @@ class ScriptManager(): ControlUtils.openTikTok(session, udid) time.sleep(3) + # 设置查找深度 + session.appium_settings({"snapshotMaxDepth": 15}) # 点击搜索按钮 ControlUtils.clickSearch(session) - # 搜索框 + # 查找输入框 input = session.xpath('//XCUIElementTypeSearchField') # 如果找到了输入框,就点击并且输入内容 input.click() @@ -203,28 +205,22 @@ class ScriptManager(): # 返回上一步 def goBack(): - ControlUtils.clickBack(session) - # 搜索框 - input = session.xpath('//XCUIElementTypeSearchField') - # 如果找到了输入框,就点击并且输入内容 - input.click() - # 稍作停顿 - time.sleep(1) + # 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] aid = anchor.anchorId + anchorCountry = anchor.country - try: - input.clear_text() - except Exception as e: - print(e) - + input.clear_text() time.sleep(2) # 输入主播id input.set_text(aid + "\n") @@ -251,8 +247,8 @@ class ScriptManager(): # 观看主播视频 def viewAnchorVideo(): print("开始查看视频") - count = 5 - while count > 1: + count = 2 + while count > 0: print("条件满足,继续查看") img = client.screenshot() time.sleep(1) @@ -277,6 +273,7 @@ class ScriptManager(): time.sleep(10) client.swipe_up() if count == 1: + client.swipe_right() break # 点击第一个视频后的逻辑 @@ -285,32 +282,61 @@ class ScriptManager(): session.appium_settings({"snapshotMaxDepth": 5}) print("重新设置了匹配深度") viewAnchorVideo() - + time.sleep(2) + print("视频看完了") + session.appium_settings({"snapshotMaxDepth": 25}) # 视频看完需要点关注。 - ControlUtils.clickFollowButton(session) - time.sleep(1) - ControlUtils.clickFollowButton(session) + r = ControlUtils.clickFollowButton(session) + if r == False: + print("执行失败了") - # 发送一条信息 + + + time.sleep(2) + ControlUtils.clickFollowButton(session) + time.sleep(2) + + # 查找聊天界面中的输入框节点 chatInput = session.xpath("//*[className='XCUIElementTypeTextView']") if chatInput.exists: print("找到了") + # 准备发送一条信息 + chatInput.click() + time.sleep(2) + # text = random.choice(prologueList) + # msg = Requester.translation(text, anchorCountry) + chatInput.set_text("哈哈哈" + "\n") + time.sleep(1) + + client.swipe_right() + time.sleep(1) + client.swipe_right() + time.sleep(2) else: print("没找到") + client.swipe_right() + time.sleep(1) + client.swipe_right() + time.sleep(2) + break # 清除数据 removeModelFromAnchorList(anchor) # 流程结束 - client.swipe_left() - time.sleep(1) + # client.swipe_right() + # time.sleep(1) else: print("获取该主播第一个视频失败") goBack() + def test(self, udid): + client = wda.USBClient(udid) + client.swipe_right() -# manager = ScriptManager() +manager = ScriptManager() +manager.test("eca000fcb6f55d7ed9b4c524055214c26a7de7aa") # manager.growAccount("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")