183 lines
5.0 KiB
Python
183 lines
5.0 KiB
Python
import random
|
|
import threading
|
|
import time
|
|
|
|
from process.tools import get_device_ids, get_element, start_simulator, clone_simulator
|
|
import uiautomator2 as u2
|
|
|
|
|
|
def get_key():
|
|
# 打开文件并读取每一行
|
|
with open('1.txt', 'r', encoding='utf-8') as file:
|
|
lines = file.readlines()
|
|
|
|
# 去掉每行的换行符并存储到列表中
|
|
lines_list = [line.strip() for line in lines]
|
|
|
|
return lines_list
|
|
|
|
|
|
def get_keys():
|
|
# 打开文件并读取每一行
|
|
with open('2.txt', 'r', encoding='utf-8') as file:
|
|
lines = file.readlines()
|
|
|
|
# 去掉每行的换行符并存储到列表中
|
|
lines_list = [line.strip() for line in lines]
|
|
|
|
return lines_list
|
|
|
|
|
|
def swipe_up1(d, duration=0.1):
|
|
"""
|
|
向上滑动屏幕的函数。
|
|
|
|
:param d: uiautomator2 的设备实例
|
|
:param duration: 滑动持续时间(秒)
|
|
"""
|
|
# 获取屏幕的宽度和高度
|
|
width, height = d.window_size()
|
|
|
|
# 定义滑动的起始和结束位置
|
|
start_x = width / 2
|
|
start_y = height * 0.8 # 从屏幕下方 80% 的位置开始滑动
|
|
end_x = width / 2
|
|
end_y = height * 0.2 # 滑动到屏幕上方 20% 的位置
|
|
|
|
# 执行滑动操作
|
|
d.swipe(start_x, start_y, end_x, end_y, duration)
|
|
|
|
|
|
def swipe_up(d, duration=0.1):
|
|
"""
|
|
向上滑动屏幕的函数。
|
|
|
|
:param d: uiautomator2 的设备实例
|
|
:param duration: 滑动持续时间(秒)
|
|
"""
|
|
# 获取屏幕的宽度和高度
|
|
width, height = d.window_size()
|
|
|
|
# 定义滑动的起始和结束位置
|
|
start_x = width / 2
|
|
start_y = height * 0.5 # 从屏幕下方 80% 的位置开始滑动
|
|
end_x = width / 2
|
|
end_y = height * 0.8 # 滑动到屏幕上方 20% 的位置
|
|
|
|
# 执行滑动操作
|
|
d.swipe(start_x, start_y, end_x, end_y, duration)
|
|
|
|
|
|
ids = []
|
|
|
|
|
|
class SJ:
|
|
|
|
def __init__(self, index, ):
|
|
self.d = None # u2原生对象
|
|
self.id = None # 连接的ip
|
|
self.index = index # 索引
|
|
|
|
self.n = random.randint(5, 10)
|
|
|
|
def sj(self, ):
|
|
|
|
type1, ele = get_element(self.d, type1="text", grammar='Warpcast', timeout=1)
|
|
if type1: # 点开过
|
|
ele.click()
|
|
|
|
type1, ele = get_element(self.d, type1="xpath", grammar='//*[@text="Skip for now"]', timeout=5)
|
|
if type1: # 点开过
|
|
ele.click()
|
|
|
|
type1, ele = get_element(self.d, type1="xpath", grammar='//*[@text="Home"]', timeout=50)
|
|
swipe_up(d=self.d, duration=0.1)
|
|
|
|
time.sleep(5)
|
|
|
|
a = 0
|
|
print(self.n)
|
|
while a < self.n:
|
|
swipe_up1(d=self.d, duration=0.1)
|
|
swipe_up1(d=self.d, duration=0.1)
|
|
# 点进详情页
|
|
self.d.xpath(
|
|
"//android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.TextView[4]").click()
|
|
# 点赞操作
|
|
time.sleep(5)
|
|
for _, i in enumerate(self.d.xpath('//com.horcrux.svg.SvgView').all()):
|
|
if _ == 0: # 评论
|
|
self.d.xpath(i.get_xpath()).click()
|
|
key = random.choice(get_key())
|
|
self.d.xpath('//*[@text="What\'s happening?"]').set_text(key)
|
|
time.sleep(2)
|
|
self.d.xpath('//*[@content-desc="Cast"]').click()
|
|
time.sleep(2)
|
|
self.d.xpath('//*[@text="Cast now"]').click()
|
|
elif _ == 1: # 转发
|
|
time.sleep(1)
|
|
self.d.xpath(i.get_xpath()).click()
|
|
time.sleep(2)
|
|
self.d.xpath('//*[@text="Recast"]').click()
|
|
elif _ == 2: # 点赞
|
|
time.sleep(2)
|
|
self.d.xpath(i.get_xpath()).click()
|
|
|
|
# 点击详情页中的退出
|
|
self.d.xpath('//android.view.ViewGroup/android.widget.ImageButton').click()
|
|
|
|
a += 1
|
|
time.sleep(2)
|
|
|
|
self.d.xpath('//*[@text=""]').click()
|
|
time.sleep(2)
|
|
self.d.xpath('//*[@text="What\'s happening?"]').set_text(random.choice(get_keys()))
|
|
time.sleep(2)
|
|
self.d.xpath('//*[@text="Cast"]').click()
|
|
time.sleep(2)
|
|
self.d.xpath('//*[@text="Cast now"]').click()
|
|
time.sleep(2)
|
|
|
|
def action(self):
|
|
start_simulator(n=self.index)
|
|
|
|
time.sleep(35)
|
|
|
|
for i in get_device_ids():
|
|
print(i)
|
|
if i not in ids:
|
|
ids.append(i)
|
|
self.id = i
|
|
break
|
|
|
|
print(ids)
|
|
self.d = u2.connect(self.id)
|
|
|
|
# 程序中操作
|
|
try:
|
|
self.sj()
|
|
except Exception as e:
|
|
pass
|
|
|
|
time.sleep(10)
|
|
clone_simulator(n=self.index)
|
|
|
|
# ids.remove(self.id)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
for i in range(1, 62):
|
|
if len(ids) == 50:
|
|
ids.clear()
|
|
|
|
print(i)
|
|
sj = SJ(index=i)
|
|
# sj.action()
|
|
threading.Thread(target=sj.action, ).start()
|
|
|
|
time.sleep(65)
|
|
|
|
# start_simulator(n=1)
|
|
# clone_simulator(n=1)
|