186 lines
5.6 KiB
Python
186 lines
5.6 KiB
Python
import random
|
|
import threading
|
|
import time
|
|
from enum import Enum
|
|
import wda
|
|
import os
|
|
from Utils.AiUtils import AiUtils
|
|
from Utils.ControlUtils import ControlUtils
|
|
from Utils.LogManager import LogManager
|
|
from Entity.Variables import anchorList, removeModelFromAnchorList
|
|
|
|
|
|
# 脚本管理类
|
|
class ScriptManager():
|
|
|
|
# 单利对象
|
|
_instance = None # 类变量,用于存储单例实例
|
|
|
|
def __new__(cls):
|
|
# 如果实例不存在,则创建一个新实例
|
|
if cls._instance is None:
|
|
cls._instance = super(ScriptManager, cls).__new__(cls)
|
|
# 返回已存在的实例
|
|
return cls._instance
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.initialized = True # 标记已初始化
|
|
|
|
# 养号
|
|
def growAccount(self, udid, event):
|
|
client = wda.USBClient(udid)
|
|
session = client.session()
|
|
session.appium_settings({"snapshotMaxDepth": 0})
|
|
|
|
# 先关闭Tik Tok
|
|
ControlUtils.closeTikTok(session, udid)
|
|
time.sleep(1)
|
|
|
|
# 重新打开Tik Tok
|
|
ControlUtils.openTikTok(session, udid)
|
|
time.sleep(3)
|
|
|
|
# 创建udid名称的目录
|
|
AiUtils.makeUdidDir(udid)
|
|
|
|
# 假设此时有个开关
|
|
while not event.is_set():
|
|
try:
|
|
img = client.screenshot()
|
|
filePath = f"resources/{udid}/bgv.png"
|
|
img.save(filePath)
|
|
LogManager.info("保存屏幕图像成功", udid)
|
|
print("保存了背景图")
|
|
time.sleep(1)
|
|
except Exception as e:
|
|
LogManager.error(e, udid)
|
|
print(e)
|
|
|
|
try:
|
|
# 判断视频类型
|
|
addX, addY = AiUtils.findImageInScreen("add", udid)
|
|
isSame = False
|
|
for i in range(2):
|
|
tx, ty = AiUtils.findImageInScreen("add", udid)
|
|
if addX == tx and addY == ty:
|
|
isSame = True
|
|
time.sleep(1)
|
|
else:
|
|
isSame = False
|
|
break
|
|
|
|
# 如果找到普通视频
|
|
if addX > 0 and isSame:
|
|
needLike = random.randint(0, 10)
|
|
# 查找首页按钮
|
|
homeButton = AiUtils.findHomeButton(udid)
|
|
if homeButton:
|
|
print("有首页按钮,查看视频")
|
|
videoTime = random.randint(5, 15)
|
|
time.sleep(videoTime)
|
|
|
|
# 百分之三的概率点赞
|
|
if needLike < 3:
|
|
print("点赞")
|
|
ControlUtils.clickLike(session, udid)
|
|
|
|
print("继续观看视频")
|
|
videoTime = random.randint(10, 30)
|
|
time.sleep(videoTime)
|
|
print("准备划到下一个视频")
|
|
client.swipe_up()
|
|
else:
|
|
print("找不到首页按钮。出错了")
|
|
else:
|
|
nextTime = random.randint(1, 5)
|
|
time.sleep(nextTime)
|
|
client.swipe_up()
|
|
except Exception as e:
|
|
print(f"发生异常:{e}")
|
|
client.swipe_up()
|
|
|
|
|
|
# 观看直播
|
|
def viewLive(self):
|
|
pass
|
|
|
|
# 关注打招呼
|
|
def greetNewFollowers(self, udid, needReply, event):
|
|
client = wda.USBClient(udid)
|
|
session = client.session()
|
|
session.appium_settings({"snapshotMaxDepth": 15})
|
|
|
|
# 先关闭Tik Tok
|
|
ControlUtils.closeTikTok(session, udid)
|
|
time.sleep(1)
|
|
|
|
# 重新打开Tik Tok
|
|
ControlUtils.openTikTok(session, udid)
|
|
time.sleep(3)
|
|
|
|
# 点击搜索按钮
|
|
searchButton = ControlUtils.clickSearch(session)
|
|
if searchButton is not None:
|
|
searchButton.click()
|
|
else:
|
|
print("没找到搜索按钮")
|
|
return
|
|
|
|
# 搜索框
|
|
input = session.xpath('//XCUIElementTypeSearchField')
|
|
|
|
# 获取一个主播
|
|
anchor = anchorList[0]
|
|
aid = anchor.anchorId
|
|
|
|
# 如果找到了输入框,就点击并且输入内容
|
|
if input.exists:
|
|
input.click()
|
|
time.sleep(1)
|
|
input.set_text(aid + "\n")
|
|
|
|
# 切换UI查找深度
|
|
session.appium_settings({"snapshotMaxDepth": 25})
|
|
|
|
# 点击进入主播首页
|
|
session.xpath(
|
|
'(//XCUIElementTypeCollectionView[@name="TTKSearchCollectionComponent"]'
|
|
'//XCUIElementTypeCell'
|
|
'//XCUIElementTypeButton[following-sibling::XCUIElementTypeButton[@name="关注" or @label="关注"]])[1]'
|
|
).get(timeout=5).tap()
|
|
|
|
time.sleep(3)
|
|
|
|
# 向上划一点
|
|
r = client.swipe_up()
|
|
print(r)
|
|
|
|
# 分析页面节点
|
|
# print(session.source())
|
|
|
|
# 观看主播视频
|
|
def viewAnchorVideo():
|
|
pass
|
|
|
|
viewAnchorVideo()
|
|
else:
|
|
pass
|
|
# 功能待完善
|
|
|
|
|
|
|
|
# while not event.is_set() and len(anchorList) > 0:
|
|
# anchor = anchorList[0]
|
|
# aid = anchor.anchorId
|
|
#
|
|
# ControlUtils.clickSearch(session, udid)
|
|
#
|
|
# # 删除数据
|
|
# removeModelFromAnchorList(anchor)
|
|
# print(len(anchorList))
|
|
|
|
# manager = ScriptManager()
|
|
# manager.growAccount("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")
|
|
|