python开发之30行代码实现微信跳一跳(Uiautomator2项目)

import uiautomator2 as u2
import matplotlib.pyplot as plt
import numpy as np
import math
import time
from PIL import Image
#d=u2.connect('172.21.236.66')
def get_position(d):
    d.screenshot("a.jpg")
    imgc = np.array(Image.open('a.jpg')) 
    img=Image.open('a.jpg')
    fig1 = plt.figure(figsize=(10,20))
    im = plt.imshow(img, animated=True)
    plt.show()
    next_=[]
    for i in range(500,800):
        first_=imgc[i]
        first_one=first_[0]
        for k in range(1,719):
            if(first_one[0]!=first_[k][0] or first_one[1]!=first_[k][1] or first_one[2]!=first_[k][2]):
                next_.append(i)
                next_.append(k)
                break
            else:
                pass
    now=[]
    for j in range(600,1000):
        first_=imgc[j]
        for k in range(0,719):
            first_one=int(first_[k][0])
            first_two=int(first_[k][1])
            first_three=int(first_[k][2])
            #print(first_one,first_two,first_three)
            if(49<first_one<60 and 50<first_two<62 and 89<first_three<110):
                now.append(j)
                now.append(k)
                break
            else:
                pass
    x1=int(next_[0])+20
    y1=int(next_[1])+20
    x2=int(now[len(now)-2])
    y2=int(now[len(now)-1])
    distance=math.sqrt(((x1-x2)**2)+((y1-y2)**2))
    return distance
while(True):
    d=u2.connect('172.21.236.66')
    dis=get_position(d)
    A=648
    t=dis/A
    print(dis/A)
    d.long_click(0.5,0.5,t)
    rt=random.uniform(3,4)#这样可以防止被腾讯的反作弊系统检测到
    print('您要等待的时间为',rt)
    time.sleep(rt)

猜你喜欢

转载自blog.csdn.net/u012865864/article/details/86086777
今日推荐