forked from zhaoqingpu/WX_XiaoTianTian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios.py
64 lines (56 loc) · 1.5 KB
/
ios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: UTF-8 -*-
import wda
import aircv as ac
import subprocess
import os
import json
import time
import random
driver = wda.Client()
session = driver.session()
scale = 2
init = False
def matchImg(imgsrc,imgobj,confidence=0.7):
imsrc = ac.imread(imgsrc)
imobj = ac.imread(imgobj)
if(init==False):
global init
init = True
width =imsrc.shape[1]
scale = width/session.window_size()[0]
match_result = ac.find_template(imsrc,imobj,confidence)
if match_result is not None:
match_result['shape']=(imsrc.shape[1],imsrc.shape[0])
return match_result
def screenshot():
driver.screenshot("ios.png")
def tab(x, y):
x = x+rdm(6)
y = y+rdm(8)
print(str(x)+"_"+str(y))
session.tap(x/scale, y/scale)
def rdm(x):
return int(random.random()*x-x/2)
def start_run():
time.sleep(3)
st = time.time()
screenshot()
et = time.time()
print("截图耗时:"+ str(et - st) )
st = time.time()
result = matchImg("ios.png","c.png")
et = time.time()
print("找图耗时:"+str((et - st)))
if result is not None:
print(result)
print(str(result['result'][0])+"-"+str(result['result'][1]))
print(str(result['confidence']))
if result['confidence']>0.8 :
tab(result['result'][0],result['result'][1])
time.sleep(40)
else :
print(str(result['confidence'])+"- small fail")
else:
print("not found")
while True:
start_run()