您的位置:首页 > 编程语言 > Python开发

利用Python玩微信跳一跳

2018-04-07 12:24 337 查看
1.首先下载adb工具安装到Windows或linux系统下,将手机开发者模式打开,将手机成功连接到电脑
2.在命令行中输入adb devices,出现如图所示状态说明连接成功!



3.将手机打开到微信点一点画面中



4.运行如下python 2.7代码
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
import math
import time
import os

def pull_screenshot():
os.system('adb shell screencap -p /sdcard/1.png')
os.system('adb pull /sdcard/1.png .')

def jump(distance):
press_time = distance * 2.15
press_time = int(press_time)
cmd = 'adb shell input swipe 320 410 320 410 ' + str(press_time)
print cmd
os.system(cmd)

fig = plt.figure()
index = 0
cor = [0, 0]

pull_screenshot()
img = np.array(Image.open('1.png'))

update = True
click_count = 0
cor = []

def update_data():
return np.array(Image.open('1.png'))

im = plt.imshow(img, animated=True)

def updatefig(*args):
global update
if update:
time.sleep(1.5)
pull_screenshot()
im.set_array(update_data())
update = False
return im,

def onClick(event):
global update
global ix, iy
global click_count
global cor

# next screenshot

ix, iy = event.xdata, event.ydata
coords = []
coords.append((ix, iy))
print 'now = ', coords
cor.append(coords)

click_count += 1
if click_count > 1:
click_count = 0

cor1 = cor.pop()
cor2 = cor.pop()

distance = (cor1[0][0] - cor2[0][0])**2 + (cor1[0][1] - cor2[0][1])**2
distance = distance ** 0.5
print 'distance = ', distance
jump(distance)
update = True

fig.canvas.mpl_connect('button_press_event', onClick)
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()
5.运行后先点击站立位置,再点击要移动到的位置
6.点击后图片自动刷新,重复步骤5
7.在此期间,在代码中找到2.15,是跳数的时间倍数,依情况进行调整
press_time = distance * 2.15

 
代码来源知乎,如侵权请联系我
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: