第一个微信小项目

用Python来玩微信跳一跳

1.在电脑上安装python

2.安装此次程序所用到的模块(根据自己安装的Windows版本和python版本进行下载)。

numpy-1.14.0rc1-cp36-none-win_amd64.whl

Pillow-5.0.0-cp36-cp36m-win_amd64.whl

matplotlib-2.1.1-cp36-cp36m-win_amd64.whl

使用cmd进入下载好的文件的目录,安装指令:(opencv是最后安装的),最好按照下面顺序安装:

pip3.6 install C:python36Scripts umpy-1.14.0rc1-cp36-none-win_amd64.whl

pip3.6 install C:python36ScriptsPillow-5.0.0-cp36-cp36m-win_amd64.whl

pip3.6 install C:python36Scriptsmatplotlib-2.1.1-cp36-cp36m-win_amd64.wh

3.下面是用到的代码,可以复制下来,保存为main.py。

# !/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'wechat'
import os
import PIL,numpy
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import time

need_update = True

def get_screen_image():
os.system('adb shell screencap -p /sdcard/screen.png')#获取当前界面的手机截图
os.system('adb pull /sdcard/screen.png')#下载当前这个截图到当前电脑当前文件夹下
return numpy.array(PIL.Image.open('screen.png'))

def jump_to_next(point1, point2):#计算炫的长度
x1, y1 = point1; x2, y2 = point2
distance = ((x2-x1)**2 + (y2-y1)**2)**0.5
os.system('adb shell input swipe 320 410 320 410 {}'.format(int(distance*1.35)))

def on_calck(event, coor=[]):#绑定的鼠标单击事件
global need_update
coor.append((event.xdata, event.ydata))
if len(coor) == 2:
jump_to_next(coor.pop(), coor.pop())
need_update = True

def update_screen(frame):#更新图片 /从画图片
global need_update
if need_update:
time.sleep(1)
axes_image.set_array(get_screen_image())
need_update = False
return axes_image,

figure = plt.figure()#创建一个空白的图片对象/创建一张图片
axes_image = plt.imshow(get_screen_image(), animated=True)#把获取的图片话在坐标轴上面
figure.canvas.mpl_connect('button_press_event', on_calck)
ani = FuncAnimation(figure, update_screen, interval=50, blit=True)
plt.show()

4.将下载好的adb驱动,和编写好的jump.py代码,放到同一个文件夹jump_demo中,方便调用。

然后在jump_demo这个文件夹中直接打开powershell(在文件中shift+鼠标右键,选择在此处打开power shell窗口)了,

或者在cmd里面,找到相对应的文件夹,然后,运行C:UsersdellDesktopjump_demo> python main.py

原文地址:https://www.cnblogs.com/wjxk/p/13067987.html