波点音乐
import uiautomator2 as u2
import time
import sys
import os# 动态点击时间,打印剩余时间
def dynamic_sleep(seconds):wait_time = secondsfor i in range(wait_time):print(f"Waiting... {wait_time - i} seconds remaining")sys.stdout.flush()time.sleep(1)
# 连接设备
d = u2.connect()def open_Polka_Music():d.app_stop("cn.wenyu.bodian")d.app_start("cn.wenyu.bodian")# dynamic_sleep(7)time.sleep(7)d.click(1042, 2634) # 使用bounds的中心点或一个适当的坐标dynamic_sleep(2)d.click(723, 224) # 使用计算出来的中心点坐标点击dynamic_sleep(2)def polka_music_click_free_music():open_Polka_Music()print("点击获取更多时间")# 点击并点击“获取更多时间”d.click(0.476, 0.431)dynamic_sleep(2)# if d(description="获取更多时间").wait(True):# d(description="获取更多时间").click()# print("点击获取更多时间成功")# else:# print("获取更多时间布局元素未找到")print("点击点击一下,立即免费听歌")d.click(0.5, 0.5)# # 点击并点击“点击一下,立即免费听歌”# if d(text="点击一下,立即免费听歌").wait(True):# d(text="点击一下,立即免费听歌").click()# print("点击点击一下,立即免费听歌成功")# else:# print("点击一下,立即免费听歌布局元素未找到")dynamic_sleep(1)os.system("adb shell input keyevent KEYCODE_BACK")dynamic_sleep(2)d.click(0.337, 0.087)dynamic_sleep(2)# 获取屏幕尺寸screen_width = d.info['displayWidth']screen_height = d.info['displayHeight']# 定义比例坐标并转换为像素start_x, start_y = 0.457, 0.998end_x, end_y = 0.457, 0.7 start_px, start_py = int(screen_width * start_x), int(screen_height * start_y)end_px, end_py = int(screen_width * end_x), int(screen_height * end_y)# 执行滑动操作d.swipe(start_px, start_py, end_px, end_py, duration=0.5)dynamic_sleep(2)d.click(0.5, 0.5)# d.click(0.5, 0.5)dynamic_sleep(3)d.click(0.337, 0.087)dynamic_sleep(3)# 启动循环
while True:polka_music_click_free_music()