Exemplo n.º 1
0
Arquivo: main.py Projeto: xwwd9/useful
def click_subscribe():
    """
    点击点阅按钮,成功返回True,失败返回False
    """
    ret = exists(Template(CLICK_SUBSCRIBE, threshold=0.80))
    if ret:
        touch(Template(CLICK_SUBSCRIBE, threshold=0.80))
        return True
    return False
 def match_img(self,screen, image):
     """
     :param screen:判断的屏幕截图
     :param image:查找到控件定位图
     :return:返回匹配结果
     """
     # Logger(LOG_STATUS=self.LOG_STATUS).setlog('screen:  '+str(screen))
     # Logger(LOG_STATUS=self.LOG_STATUS).setlog('image:  ' + str(image))
     img = Template( filename=image,threshold=self.confidence)
     screen_image = self.read_img(screen)
     match_result = img._cv_match(screen_image)
     if match_result is not None:
         match_result['shape'] = (screen_image.shape[1], screen_image.shape[0])  # 0为高,1为宽
     return match_result
Exemplo n.º 3
0
Arquivo: main.py Projeto: xwwd9/useful
def is_in_detail():
    ret = exists(Template(CLICK_BACK))
    # 直接返回False
    if not ret:
        return ret
    if ret[1] > 70 and ret[0] > X_MIDDLE:
        return False
    pos = ret
    ret = exists(Template(MORE_TEXT))
    if not ret:
        return ret
    if ret[1] > 70 and ret[0] < X_MIDDLE:
        return False
    return pos
Exemplo n.º 4
0
def find_tag(file_path):
    print('finding tag...')
    file_path_online = file_path
    #     file_path_offline = file_path
    files_online = os.listdir(file_path_online)
    #     files_online.sort()
    files_online.sort(key=lambda x: int(x.split('_')[0][5:]))
    print(files_online)
    for i in range(len(files_online) - 2):
        #         print(files_online[i])
        if "jpg" not in files_online[i]:
            continue
        print(file_path_online + files_online[i])
        loop_find3_result = loop_find3(file_path_online + files_online[i],
                                       Template(r"tpl1605064959952.png",
                                                record_pos=(0.239, -0.426),
                                                resolution=(828, 1792)),
                                       posi=(426, 577),
                                       tag="精选",
                                       timeout=1,
                                       threshold=0.99)
        #         loop_find3_result = loop_find3('./picSplitOnline/frame246_4668.jpg',Template(r"tpl1605064959952.png", record_pos=(0.239, -0.426), resolution=(828, 1792)),posi=(426, 577),tag="精选",timeout=1, threshold=0.90)

        # if loop_find3_result:
        #     print(pics)
        if loop_find3_result:
            print("success")
            return files_online[i]
Exemplo n.º 5
0
def home():
    """
    返回家
    :return: None
    """
    while True:
        pos = Template(r"../item/home-tower.png").match_in(dev.snapshot())
        if pos is not None:
            dev.touch(pos)
            sleep(1)
            break

        pos = Template(r"../item/home-map.png").match_in(dev.snapshot())
        if pos is not None:
            dev.touch(pos)
            sleep(1)
            dev.touch(pos)
            sleep(1)
            break

        keyevent('BACK')
Exemplo n.º 6
0
Arquivo: main.py Projeto: xwwd9/useful
def find_news():
    ret_news = find_all(Template(PIC_NEW))
    # ret_am = find_all(Template(PIC_AM))
    # ret_pm = find_all(Template(PIC_PM))

    if ret_news:
        print(ret_news)

        print(len(ret_news))
    else:
        ret_news = []

    return ret_news
Exemplo n.º 7
0
 def temp(cls, img_name: str, rgb: bool = True, record_pos: tuple = (0.5, -0.5),
          resolution: tuple = airDev.screen, target_pos=TargetPos.MID):
     """CV识别主函数
     :param rgb: 灰度识别还是色彩识别
     :param record_pos: 图片坐标
     :param img_name: 图片名称
     :param target_pos:
     :param resolution: 设备分辨率
     :return:
     """
     temp = Template(
         r"%s" % img_name, target_pos=target_pos, record_pos=record_pos, resolution=resolution, rgb=rgb)
     return temp
Exemplo n.º 8
0
def scout():
    home()
    info = dev.get_display_info()
    w = info['width']
    h = info['height']
    while True:
        dev.touch([int(w / 2), int(h / 2)])
        sleep(1)
        pos = Template("../item/scout.png").match_in(dev.snapshot())
        if pos:
            dev.touch(pos)
            sleep(1)

        pos = Template("../item/scout-manage-string.png").match_in(
            dev.snapshot())
        if pos:
            flag = False
            while True:

                pos = Template("../item/explore-string.png").match_in(
                    dev.snapshot())
                if pos:
                    dev.touch(pos)
                    sleep(1)

                pos = Template("../item/send-string.png").match_in(
                    dev.snapshot())
                if pos:
                    if not flag:
                        flag = True
                        screen = dev.snapshot()
                        pos = Template("../item/sleep.png").match_in(screen) \
                              or Template("../item/station.png").match_in(screen) \
                              or Template("../item/go-back.png").match_in(screen)

                        if pos:
                            dev.touch(pos)
                            sleep(1)
                    else:
                        dev.touch(pos)
                        sleep(1)
                        break

                sleep(1)
                print("循环监听《探索》按钮中....")

        dev.touch(Template("../item/home-tower.png").match_in(dev.snapshot()))
        sleep(1)
Exemplo n.º 9
0
 def template_object(self, filename, target_pos=5, record_pos=None):
     pro_path = get_project_path()
     clickpic_path = os.path.join(pro_path, 'clickPicture_EN')
     # 图像识别阈值:threshold
     # 图像识别新增参数:target_pos 图像点击位置
     # 是否灰度:rgb
     # 图片位置:record_pos  优先在录制时的位置附近查找,如果找不到符合条件的图片,再扩大寻找范围到整个画面
     t = Template(os.path.join(clickpic_path, filename),
                  resolution=(1080, 1920),
                  rgb=True,
                  target_pos=target_pos,
                  threshold=0.8,
                  record_pos=record_pos)
     time.sleep(0.5)
     return t
Exemplo n.º 10
0
    def do_click_by_template(img_file, record_pos, resolution):
        """
        根据截图来确定按钮的点击
        oppo的设备执行到点击安装的步骤时,会将后台运行中的PocoService进程中断,无法通过poco获取对象,只能截图

        :param img_file: 手机屏幕的分辨率
        :param record_pos: 截图时对于手机屏幕的相对位置
        :param resolution: 手机屏幕的分辨率
        :return:
        """
        try:
            tmp = Template(img_file,
                           record_pos=tuple(record_pos),
                           resolution=tuple(resolution))
            touch(tmp)
        except Exception as e:
            print("error: %s" % (str(e)))
Exemplo n.º 11
0
from airtest.core.cv import Template

import os


THISDIR = os.path.dirname(__file__)
DIR = lambda x: os.path.join(THISDIR, x)
APK = DIR("../playground/test_blackjack.owl/blackjack-release-signed.apk")
PKG = "org.cocos2d.blackjack"
OWL = DIR("../playground/test_blackjack.owl")
IMG = os.path.join(OWL, "tpl1499240443959.png")
TPL = Template(IMG, record_pos=(0.22, -0.165), resolution=(2560, 1536))
TPL2 = Template(os.path.join(OWL, "tpl1499240472304.png"), record_pos=(0.0, -0.094), resolution=(2560, 1536))


def try_remove(filepath):
    if os.path.exists(filepath):
        os.remove(filepath)
Exemplo n.º 12
0
 def template(self, name):
     """被识别的图片Template对象"""
     return Template(name, record_pos=self.size_half, resolution=self.size)
Exemplo n.º 13
0
 def template(self, name):
     """被识别的图片Template对象"""
     return Template(name,
                     record_pos=(self.width / 2, self.height / 2),
                     resolution=(self.width, self.height))
Exemplo n.º 14
0
 def getTemplate(self):
     if self.__template is None:
         self.__template = Template(self.__path)
     return self.__template
Exemplo n.º 15
0

cuntom_offsets = {
    OffsetMode.skill: [[197, 592], [292, 591], [381, 589]],
    OffsetMode.spell: [[230, 407], [416, 328], [614, 266], [805, 225],
                       [1007, 207]],
    OffsetMode.level: [[876, 506], [876, 354], [876, 206]],
    OffsetMode.event: [[885, 546], [870, 392], [863, 250], [886, 144]],
    OffsetMode.chapter: [[876, 506], [876, 354], [876, 206]],
    OffsetMode.explore: [[669, 652], [895, 649], [1111, 655]],
}

templates = {
    TemplateMode.spread_shoot:
    Template(image=li(r"spread_shoot.png"),
             target_pos=TargetPos.RANDOMINLINE,
             record_pos=(-0.346, 0.15),
             resolution=(1280, 720)),
    TemplateMode.focus_shoot:
    Template(image=li(r"focus_shoot.png"),
             target_pos=TargetPos.RANDOMINLINE,
             record_pos=(-0.02, 0.149),
             resolution=(1280, 720)),
    #auto_timeout使用,timeout->msg_box_title
    TemplateMode.msg_box_title:
    Template(image=li(r"msg_box_title.png"),
             target_pos=TargetPos.RANDOMINLINE,
             record_pos=(-0.001, -0.125),
             resolution=(1280, 720)),
    #新增msg_box_confirm,msg_box_fail,msg_box_confirm_noborder
    TemplateMode.msg_box_confirm:
    Template(image=li(r"msg_box_confirm.png"),
Exemplo n.º 16
0
 def test_1(self):
     touch(
         Template(r"tpl1606792128602.png",
                  record_pos=(-0.12, 0.412),
                  resolution=(1080, 1920)))
Exemplo n.º 17
0
# SERIALNO = 'XPU4C16B15005800'
SERIALNO = 'RKKDU18517006681'
# SERIALNO = '229380bc0304'

# 活动日历名称
ACTIVITY_NAME = '夏新势力X'

# 测试机相册路径:
ADB_PIC_URL = '/sdcard/Pictures'

# adb命令,扫描:
ADB_SCAN_FILE = 'am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Pictures/test.png'

# 标题优化页面,更新到淘宝按钮,testphone
TEMPLATE_UPDATE_TITLE = Template(r'C:\mitem_ui_test\mitem_ui_test\pic_data\tpl1588927244635.png',
                                 record_pos=(0.323, -0.147), resolution=(1080, 2160), threshold=0.95)

# 标题优化页面,一键优化按钮,testphone
TEMPLATE_ONE_CLICK_IMPOVR = Template(r'mobile/mitem_ui_test/mitem_ui_test/pic_data/tpl1592412091894.png',
                                     record_pos=(-0.156, 0.074), resolution=(1080, 2160))

# # 标题优化页面,一键优化后的更新到淘宝按钮,testphone
TEMPLATE_UPDATE_TITLE_AFTER_IMPROVE = Template(r"C:\mitem_ui_test\mitem_ui_test\pic_data\tpl1588927425322.png",
                                               record_pos=(0.317, -0.152), resolution=(1080, 2160))
# 出售中的宝贝,有sku,带长图
ITEM_ONSALE = 'http://item.taobao.com/item.htm?id=615055673244'
ITEM_ONSALE_TITLE = '自动化专用sku宝贝'

# 仓库中的宝贝,无sku,无长图
ITEM_INVENTORY = 'http://item.taobao.com/item.htm?id=615305354200'
ITEM_INVENTORY_TITLE = '自动化专用无sku宝贝'
Exemplo n.º 18
0
import os

import allure
from airtest.core.cv import Template

from case import templateDir
from case.common import airtest_touch_wait_tv

GOBACKTP = os.path.join(templateDir, "tpl1588752941545.png")
GOBACK_V = Template(GOBACKTP,
                    record_pos=(-0.437, -0.897),
                    resolution=(1080, 2280))


@allure.step("点击返回上一页图标:<")
def click_go_back():
    airtest_touch_wait_tv(GOBACK_V)
Exemplo n.º 19
0
def air_init(uuid='000F0A5A'):
    init_device(platform='Windows', uuid=int(uuid, 16))
    touch(Template("../my_pywinauto/imgs/subscription.png"))
Exemplo n.º 20
0
# ST.CVSTRATEGY = ["surf", "tpl"]
dev = Android()
while True:

    s = dev.snapshot()
    # pos = Template('../item/jin-sum.png').match_in(s)

    # info = dev.get_display_info()
    # x = int(info['width'] / 2)
    # y = int(info['height'] / 2)
    # dx = random.randint(-500, 500)
    # dy = random.randint(-500, 500)
    # # print('%d,%d %d,%d' % (x, y, x + dx, y + dy))
    # dev.swipe([x, y], [x + dx, y + dy])

    pos = Template('../item/res-sum.png').match_in(s)
    if pos:
        plt.text(pos[0], pos[1], 'x')
        s = s[pos[1] - 25:pos[1] + 150, pos[0] + 300:pos[0] + 550]
        # s =s[pos[1]:,pos[0]:]
        # s = s[pos[1]-25:pos[1]+25, pos[0]+300:pos[0]+550]
        # s = s[pos[1]-25:pos[1]+15, pos[0]+60:pos[0]+130]
        # s = s[pos[1] - 30:pos[1] + 30, pos[0] - 320:pos[0] - 100]
        # s = s[15:65, 530:850]
        plt.imshow(s)
        plt.show()

        result = img_to_str(np.array(cv2.imencode('.jpg', s)[1]).tobytes())

        print(result)
Exemplo n.º 21
0
Arquivo: main.py Projeto: xwwd9/useful
def do_action(action):
    touch(Template(action))
Exemplo n.º 22
0
# -*- encoding=utf8 -*-
#广告位素材
import inspect
import os
from airtest.core.cv import Template

_parentPath = os.path.abspath(
    os.path.dirname(inspect.getfile(inspect.currentframe())) + os.path.sep +
    ".")
_rootPath = os.path.abspath(os.path.dirname(_parentPath) + os.path.sep + ".")

heathHomePageBoothMaterial = {
    "APP启动页广告": Template(_rootPath + "\BoothMaterial\SP002.jpg"),
    "顶通健康面": Template(_rootPath + "\BoothMaterial\SP001.jpg"),
    "健康首页悬浮球广告": Template(_rootPath + "\BoothMaterial\MP007.jpg"),
    "健康首页顶部Banner": Template(_rootPath + "\BoothMaterial\MP009.jpg"),
    "首页公共营销Banner": Template(_rootPath + "\BoothMaterial\MP006.jpg"),
    "健康首页中部轮播广告": Template(_rootPath + "\BoothMaterial\MP001.jpg"),
    "健康首页头条信息流": Template(_rootPath + "\BoothMaterial\MP013.jpg")
}

MedicalHomePage = {
    "顶通医疗面": Template(_rootPath + "\BoothMaterial\SP005.jpg"),
    "医疗首页悬浮球广告": Template(_rootPath + "\BoothMaterial\MP014.jpg"),
    "医疗免费版首页顶部Banner": Template(_rootPath + "\BoothMaterial\MP011.jpg")
}

heathHeadlinesPageBoothMaterial = {
    "健康头条信息流": Template(_rootPath + "\BoothMaterial\TT001.jpg"),
    "头条信息流列表页悬浮球": Template(_rootPath + "\BoothMaterial\TT030.jpg"),
    "头条焦点图": Template(_rootPath + "\BoothMaterial\TT006.jpg"),
Exemplo n.º 23
0
def farm():
    img_list = ("farm-string.png", "wood-string.png", "stone-string.png")
    while True:
        pos = Template("../item/search.png").match_in(dev.snapshot())
        if pos:
            dev.touch(pos)

        pos = Template("../item/search-string.png").match_in(dev.snapshot())
        if pos:
            pos = Template("../jia.png").match_in(dev.snapshot())
            if pos:
                for i in range(6):
                    dev.touch(pos)
                    sleep(0.2)

            pos = Template('../item/' +
                           img_list[random.randint(0,
                                                   len(img_list) -
                                                   1)]).match_in(
                                                       dev.snapshot())
            if pos:
                dev.touch(pos)
                sleep(1)

            while True:
                pos = Template('../item/search-string.png').match_in(
                    dev.snapshot())
                if pos is None:
                    break
                else:
                    dev.touch(pos)
                    sleep(1)

                pos = Template("../jian.png").match_in(dev.snapshot())
                if pos:
                    dev.touch(pos)

            flag = False
            while True:
                info = dev.get_display_info()
                w = info['width']
                h = info['height']
                dev.touch([int(w / 2), int(h / 2)])
                plt.imshow(dev.snapshot())
                plt.text(int(w / 2), int(h / 2), 'x')
                plt.show()

                pos = Template('../item/gather-string.png').match_in(
                    dev.snapshot())
                if pos:
                    dev.touch(pos)
                    break

                pos = Template('../attack.png').match_in(dev.snapshot())
                if pos:
                    flag = True
                    break

            if flag:
                break

            while True:
                pos = Template('../item/create-troop-string.png').match_in(
                    dev.snapshot())
                if pos:
                    dev.touch(pos)
                    break

                pos = Template('../item/march-string.png').match_in(
                    dev.snapshot())
                if pos:
                    dev.touch([500, 500])
                    return

            while True:
                pos = Template('../item/march-string.png').match_in(
                    dev.snapshot())
                if pos:
                    dev.touch(pos)
                    break