Beispiel #1
0
def app_restart():
    os.system('adb shell am force-stop com.eg.android.AlipayGphone')
    time.sleep(1)
    log_tools.log('info', "启动app")
    os.system(
        'adb shell am start -n com.eg.android.AlipayGphone/com.eg.android.AlipayGphone.AlipayLogin activity'
    )
Beispiel #2
0
def keyevent_by_num(num):
    try:
        log_tools.log('info', "开始模拟按键{}".format(num))
        os.system('adb shell input keyevent {}'.format(num))
        time.sleep(1)
    except Exception:
        log_tools.log('warning', "keyevent_by_num error")
        traceback.print_exc()
        exit(-1)
Beispiel #3
0
def swipe_by_2point(x1, y1, x2, y2):
    try:
        log_tools.log('info', "开始滑动{} {} {} {} 300".format(x1, y1, x2, y2))
        os.system('adb shell input swipe {} {} {} {} 300'.format(x1, y1, x2, y2))
        time.sleep(1)
    except Exception:
        log_tools.log('warning', "swipe_by_2point error")
        traceback.print_exc()
        exit(-1)
Beispiel #4
0
def tap_by_xy(x, y):
    try:
        log_tools.log('info',"开始点击{} {}".format(x, y))
        os.system('adb shell input tap {} {}'.format(x, y))
        time.sleep(1)
    except Exception:
        log_tools.log('info', "tap_by_xy error")
        traceback.print_exc()
        exit(-1)
def get_color_count(img_name):
    """
    查找出图像中对应RGB像素
    """
    im_self = Image.open(img_name)
    self_energy_point_count = 0
    self_energy_point_boolean = False
    self_energy_position_handx = 0
    self_energy_position_handy = 0
    self_energy_w, self_energy_h = im_self.size
    self_operator_energy_point_list = []
    for self_energy_i in range(0, self_energy_w):
        self_energy_point_boolean = False
        for self_energy_j in range(0, int(self_energy_h)):
            pixel = im_self.getpixel((self_energy_i, self_energy_j))

            if pixel[0] == 132 and pixel[1] == 75 and pixel[2] == 40:
                # print(pixel)
                self_energy_point_count += 1
                self_energy_position_handx += self_energy_i
                self_energy_position_handy += self_energy_j
                self_energy_point_boolean = True

        if (
                not self_energy_point_boolean
        ) and self_energy_point_count != 0 and self_energy_point_count > 200:
            log_tools.log(
                'info', "current self_energy_point_count {}".format(
                    self_energy_point_count))
            log_tools.log('info', "--Found self_energy points")
            self_energy_position_handx = round(
                self_energy_position_handx / self_energy_point_count, 0)
            self_energy_position_handy = round(
                self_energy_position_handy / self_energy_point_count, 0)
            self_operator_energy_point_list.append(self_energy_position_handx)
            self_operator_energy_point_list.append(self_energy_position_handy)
            self_energy_position_handx = 0
            self_energy_position_handy = 0
            self_energy_point_count = 0
            self_energy_point_boolean = False

    for self_energy_ii in range(0,
                                len(self_operator_energy_point_list) - 1, 2):
        print(self_operator_energy_point_list[self_energy_ii],
              self_operator_energy_point_list[self_energy_ii + 1])
        time.sleep(1)
Beispiel #6
0
def recognition_img_txt(img_name):
    """
    将图片中文件识别出来

    """
    img_path = '..\\file\\{}'.format(img_name)
    # print(img_path)
    if os.path.isfile(img_path):
        recognition_str = 'tesseract {} out -l chi_sim makebox'.format(
            img_path)
        os.system(recognition_str)
        log_tools.log('info', recognition_str)
        log_tools.log('info', "输出坐标文件 out.box")
    else:
        log_tools.log('info', "{} not found.".format(img_name))
def main():
    """
    主函数
    """

    log_tools.log('info', '程序版本号:{}'.format(VERSION))

    # 唤醒屏幕-输入密码并进入到对应app
    wake_up.screenshot_prepare()
    try:
        # 获取森林两个字后进入到对应应用模块
        time.sleep(3)
        # 开始截图
        now_times = datetime.datetime.now().strftime('%H-%M-%S')
        screenshot.check_screenshot('{}screen.png'.format(now_times))
        # 查找图片中坐标位置,截图后的原点在左下角
        positions = baiOcr.get_position(
            "森林", "..\\file\\{}screen.png".format(now_times))

        position_x = int(positions[0])
        position_y = int(positions[1])

        adb_tools.tap_by_xy(position_x, position_y)
    except IndexError:
        # 如果已经启动了APP,且没有在首页就重启APP
        wake_up.app_restart()
        try:
            time.sleep(3)
            # 开始截图
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.check_screenshot('{}screen.png'.format(now_times))

            # 查找图片中坐标位置,截图后的原点在左下角
            positions = baiOcr.get_position(
                "森林", "..\\file\\{}screen.png".format(now_times))

            position_x = int(positions[0])
            position_y = int(positions[1])

            adb_tools.tap_by_xy(position_x, position_y)
        except IndexError:
            time.sleep(3)
            # 开始截图
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.check_screenshot('{}screen.png'.format(now_times))

            # 查找图片中坐标位置,截图后的原点在左下角
            positions = baiOcr.get_position(
                "森林", "..\\file\\{}screen.png".format(now_times))

            position_x = int(positions[0])
            position_y = int(positions[1])

            adb_tools.tap_by_xy(position_x, position_y)

    # 进入到森林后循环收取能量
    # 截取当前屏幕并查出可收取手型坐标
    green_point_count = 0
    green_point_boolean = False
    position_handx = 0
    position_handy = 0
    circulation = True
    count_self = 0
    count_detail = True

    while circulation:
        now_time = datetime.datetime.now().strftime('%H:%M')
        log_tools.log('info', now_time)
        #time.sleep(2)

        # 时间是17分到19分就一直截取自己准备进行收取
        if now_time == '07:17' or now_time == '07:18' or now_time == '07:19':
            #if now_time == '20:05' or now_time == '07:18':
            count_detail = True
            # 如果count_self为0代表为第一次收取自己,如果不是第一次就直接截图不用判断是否在好友列表
            if count_self == 0:
                ## time.sleep(2)
                now_times = datetime.datetime.now().strftime('%H-%M-%S')
                screenshot.check_screenshot(
                    "{}screen-more.png".format(now_times))
                positions = baiOcr.get_position(
                    "排行", "..\\file\\{}screen-more.png".format(now_times))
                if len(positions) != 0:
                    log_tools.log('info', "返回上一级,准备收取自己")
                    adb_tools.keyevent_by_num(4)
                    time.sleep(2)
                log_tools.log('info', "--------------------进入自己界面")
                adb_tools.swipe_by_2point(100, 400, 100, 2000)
                time.sleep(1)
                adb_tools.swipe_by_2point(100, 400, 100, 2000)
                time.sleep(1)
                #经常有提示合种浇水,所以先点击一次关闭
                adb_tools.tap_by_xy(138, 688)
                time.sleep(1)
                #经常有提示合种浇水,所以先点击一次关闭
                adb_tools.tap_by_xy(137, 731)

            ## time.sleep(2)
            adb_tools.swipe_by_2point(100, 400, 100, 2000)
            log_tools.log('info', "开始截自己图")
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.pull_screenshot("{}screen-self.png".format(now_times))
            # im_self = Image.open('..\\file\\{}screen-self.png'.format(now_times))
            # self_energy_point_count = 0
            # self_energy_point_boolean = False
            # self_energy_position_handx = 0
            # self_energy_position_handy = 0
            # self_energy_w, self_energy_h = im_self.size
            # self_operator_energy_point_list = []
            # for self_energy_i in range(0, self_energy_w):
            #     self_energy_point_boolean = False
            #     for self_energy_j in range(0, int(self_energy_h / 2)):
            #         pixel = im_self.getpixel((self_energy_i, self_energy_j))
            #
            #         if pixel[0] == 180 and pixel[1] == 240 and pixel[2] == 32:
            #             # print(pixel)
            #             self_energy_point_count += 1
            #             self_energy_position_handx += self_energy_i
            #             self_energy_position_handy += self_energy_j
            #             self_energy_point_boolean = True
            #
            #     if (not self_energy_point_boolean) and self_energy_point_count != 0 and self_energy_point_count > 200:
            #         log_tools.log('info', "current self_energy_point_count {}".format(self_energy_point_count))
            #         log_tools.log('info', "--Found self_energy points")
            #         self_energy_position_handx = round(self_energy_position_handx / self_energy_point_count, 0)
            #         self_energy_position_handy = round(self_energy_position_handy / self_energy_point_count, 0)
            #         self_operator_energy_point_list.append(self_energy_position_handx)
            #         self_operator_energy_point_list.append(self_energy_position_handy)
            #         self_energy_position_handx = 0
            #         self_energy_position_handy = 0
            #         self_energy_point_count = 0
            #         self_energy_point_boolean = False

            # for self_energy_ii in range(0, len(self_operator_energy_point_list) - 1, 2):
            #     log_tools.log('info', "进行收取")
            #     adb_tools.tap_by_xy(self_operator_energy_point_list[self_energy_ii],
            #                         self_operator_energy_point_list[self_energy_ii + 1])
            #     time.sleep(1)
            log_tools.log('info', "判断自己的行走是否有能量可取")
            positions = baiOcr.get_position(
                "行走", "..\\file\\{}screen-self.png".format(now_times))
            if len(positions) != 0:
                log_tools.log('info', "进行收取")
                position_x = int(positions[0])
                position_y = int(positions[1]) - 80
                adb_tools.tap_by_xy(position_x, position_y)
            log_tools.log('info', "--------第{}检查完自己的能量".format(count_self))
            count_self += 1

        # 不在指定时间内就执行以下代码
        else:
            # count_detail第一次进入到森林,所以需要往下滑动。且滑动后需要将count_detail置为false代表已经进入到过森林
            if count_detail:
                time.sleep(10)
                adb_tools.swipe_by_2point(100, 1300, 100, 100)
                time.sleep(1)
                adb_tools.swipe_by_2point(100, 1300, 100, 100)

                # 进入森林后开始向下滑动
                try:
                    time.sleep(2)
                    now_times = datetime.datetime.now().strftime('%H-%M-%S')
                    screenshot.check_screenshot(
                        "{}screen-more.png".format(now_times))
                    positions = baiOcr.get_position(
                        "查看更多好友",
                        "..\\file\\{}screen-more.png".format(now_times))

                    query_number = len(positions)
                    position_x = int(positions[0])
                    position_y = int(positions[1])
                    adb_tools.tap_by_xy(position_x, position_y)
                except IndexError:
                    wake_up.app_restart()
                    try:
                        time.sleep(3)
                        # 开始截图
                        now_times = datetime.datetime.now().strftime(
                            '%H-%M-%S')
                        screenshot.check_screenshot(
                            '{}screen.png'.format(now_times))

                        # 查找图片中坐标位置,截图后的原点在左下角
                        positions = baiOcr.get_position(
                            "森林", "..\\file\\{}screen.png".format(now_times))

                        position_x = int(positions[0])
                        position_y = int(positions[1])

                        adb_tools.tap_by_xy(position_x, position_y)
                    except IndexError:
                        time.sleep(3)
                        # 开始截图
                        now_times = datetime.datetime.now().strftime(
                            '%H-%M-%S')
                        screenshot.check_screenshot(
                            '{}screen.png'.format(now_times))

                        # 查找图片中坐标位置,截图后的原点在左下角
                        positions = baiOcr.get_position(
                            "森林", "..\\file\\{}screen.png".format(now_times))

                        position_x = int(positions[0])
                        position_y = int(positions[1])

                        adb_tools.tap_by_xy(position_x, position_y)

                    # 重启app后需要重置变量
                    green_point_count = 0
                    green_point_boolean = False
                    position_handx = 0
                    position_handy = 0
                    circulation = True
                    count_self = 0
                    count_detail = True
                    continue

                count_detail = False

                log_tools.log('info', "--------------------进入好友列表")

            # 不是第一次进入到森林(说明是在好友列表)或已经进入好友列表,此时行判定是不是好友列表最后一页

            time.sleep(2)
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.pull_screenshot("{}screen-list.png".format(now_times))
            # 查找图片中坐标位置是否有多了两个字
            positions = baiOcr.get_position(
                "多了", "..\\file\\{}screen-list.png".format(now_times))
            if len(positions) != 0:
                log_tools.log('info', "当前页为最后一页")
                log_tools.log('info', "返回上一级,准备重新进入好友列表")
                adb_tools.keyevent_by_num(4)
                try:
                    time.sleep(2)
                    adb_tools.swipe_by_2point(100, 1300, 100, 100)
                    time.sleep(1)
                    adb_tools.swipe_by_2point(100, 1300, 100, 100)
                    now_times = datetime.datetime.now().strftime('%H-%M-%S')
                    screenshot.check_screenshot(
                        "{}screen-more.png".format(now_times))
                    positions = baiOcr.get_position(
                        "查看更多好友",
                        "..\\file\\{}screen-more.png".format(now_times))

                    position_x = int(positions[0])
                    position_y = int(positions[1])

                    log_tools.log('info', "--------------------再次进入好友列表")
                    adb_tools.tap_by_xy(position_x, position_y)
                    time.sleep(2)
                    now_times = datetime.datetime.now().strftime('%H-%M-%S')
                    screenshot.pull_screenshot(
                        "{}screen-list.png".format(now_times))
                except IndexError:
                    wake_up.app_restart()
                    try:
                        time.sleep(3)
                        # 开始截图
                        now_times = datetime.datetime.now().strftime(
                            '%H-%M-%S')
                        screenshot.check_screenshot(
                            '{}screen.png'.format(now_times))

                        # 查找图片中坐标位置,截图后的原点在左下角
                        positions = baiOcr.get_position(
                            "森林", "..\\file\\{}screen.png".format(now_times))

                        position_x = int(positions[0])
                        position_y = int(positions[1])

                        adb_tools.tap_by_xy(position_x, position_y)
                        time.sleep(2)
                        now_times = datetime.datetime.now().strftime(
                            '%H-%M-%S')
                        screenshot.pull_screenshot(
                            "{}screen-list.png".format(now_times))
                    except IndexError:
                        time.sleep(3)
                        # 开始截图
                        now_times = datetime.datetime.now().strftime(
                            '%H-%M-%S')
                        screenshot.check_screenshot(
                            '{}screen.png'.format(now_times))

                        # 查找图片中坐标位置,截图后的原点在左下角
                        positions = baiOcr.get_position(
                            "森林", "..\\file\\{}screen.png".format(now_times))

                        position_x = int(positions[0])
                        position_y = int(positions[1])

                        adb_tools.tap_by_xy(position_x, position_y)
                        time.sleep(2)
                        now_times = datetime.datetime.now().strftime(
                            '%H-%M-%S')
                        screenshot.pull_screenshot(
                            "{}screen-list.png".format(now_times))

                    # 截取当前屏幕并查出可收取手型坐标
                    green_point_count = 0
                    green_point_boolean = False
                    position_handx = 0
                    position_handy = 0
                    circulation = True
                    count_self = 0
                    count_detail = True
                    continue
            else:
                log_tools.log('info', "当前页不是最后一页,继续执行")

            # 在好友列表进行截图判定有没有可收取手型
            # 没有多了两个字就不需要重新截图

            # now_times = datetime.datetime.now().strftime('%H-%M-%S')
            # screenshot.pull_screenshot("{}screen-list.png".format(now_times))
            im = Image.open('..\\file\\{}screen-list.png'.format(now_times))
            w, h = im.size
            operator_point_list = []
            for i in range(0, h):
                green_point_boolean = False
                for j in range(800, w):
                    pixel = im.getpixel((j, i))

                    # if (pixel[0] == 48) and (pixel[1] == 191) and (pixel[2] == 108):
                    if (pixel[0] == 29) and (pixel[1] == 160) and (pixel[2]
                                                                   == 109):
                        green_point_count += 1
                        position_handx += j
                        position_handy += i
                        green_point_boolean = True

                # 不添加大于1200会有误差判断

                if (not green_point_boolean) and (green_point_count != 0):
                    log_tools.log(
                        'info', "current green_point_count {}".format(
                            green_point_count))
                    # print('{} {} {}'.format(position_handx, position_handy, i))
                    log_tools.log('info', "--Found green points")
                    if green_point_count < 2000 and green_point_count > 1300:
                        log_tools.log('info', "----Found green hand")
                        position_handx = round(
                            position_handx / green_point_count, 0)
                        position_handy = round(
                            position_handy / green_point_count, 0)
                        operator_point_list.append(position_handx)
                        operator_point_list.append(position_handy)
                    else:
                        log_tools.log('info', "----Not found green hand")
                    position_handx = 0
                    position_handy = 0
                    green_point_count = 0
                    green_point_boolean = False

            log_tools.log('info', "检查完一张截屏,判断是否需要进入到好友森林界面")

            # 有手型就需要进入到对应好友森林详细界面
            if len(operator_point_list) != 0:
                # 开始点击需要点击的点,并在点击后进行截图
                for i in range(0, len(operator_point_list) - 1, 2):
                    log_tools.log('info', "进入到好友森林详情界面")
                    adb_tools.tap_by_xy(operator_point_list[i],
                                        operator_point_list[i + 1])

                    log_tools.log('info', "判断是否有能量可取")
                    # 在详情界面进行截图并判断是否可获取
                    time.sleep(2)
                    now_times = datetime.datetime.now().strftime('%H-%M-%S')
                    screenshot.pull_screenshot(
                        "{}screen-other.png".format(now_times))
                    positions = baiOcr.get_position(
                        "可收取",
                        "..\\file\\{}screen-other.png".format(now_times))
                    if len(positions) != 0:
                        for energy_ii in range(0, len(positions) - 1, 2):
                            log_tools.log('info', "进行收取")
                            position_x = int(positions[energy_ii])
                            position_y = int(positions[energy_ii + 1]) - 80
                            adb_tools.tap_by_xy(position_x, position_y)
                        # 收取完能量后返回到列表中
                        ## time.sleep(1)
                        log_tools.log('info', "返回好友列表")
                        adb_tools.keyevent_by_num(4)
                        time.sleep(1)
                        continue

                    # 通过可收取 三个字未找到能量时,采用对比颜色进行收取
                    im_other = Image.open(
                        '..\\file\\{}screen-other.png'.format(now_times))
                    energy_point_count = 0
                    energy_point_boolean = False
                    energy_position_handx = 0
                    energy_position_handy = 0
                    energy_w, energy_h = im_other.size
                    operator_energy_point_list = []
                    for energy_i in range(0, energy_w):
                        energy_point_boolean = False
                        for energy_j in range(0, int(energy_h / 2)):
                            pixel = im_other.getpixel((energy_i, energy_j))

                            if pixel[0] == 180 and pixel[1] == 240 and pixel[
                                    2] == 32:
                                energy_point_count += 1
                                energy_position_handx += energy_i
                                energy_position_handy += energy_j
                                energy_point_boolean = True
                            # print('{} {} {} 是energy'.format(energy_i, energy_j, pixel))

                        if (
                                not energy_point_boolean
                        ) and energy_point_count != 0 and energy_point_count > 200:
                            log_tools.log(
                                'info', "current energy_point_count {}".format(
                                    energy_point_count))
                            log_tools.log('info', "--Found energy points")
                            energy_position_handx = round(
                                energy_position_handx / energy_point_count, 0)
                            energy_position_handy = round(
                                energy_position_handy / energy_point_count, 0)
                            operator_energy_point_list.append(
                                energy_position_handx)
                            operator_energy_point_list.append(
                                energy_position_handy)
                            energy_position_handx = 0
                            energy_position_handy = 0
                            energy_point_count = 0
                            energy_point_boolean = False
                        # if green_point_count

                    for energy_ii in range(0,
                                           len(operator_energy_point_list) - 1,
                                           2):
                        log_tools.log('info', "进行收取")
                        adb_tools.tap_by_xy(
                            operator_energy_point_list[energy_ii],
                            operator_energy_point_list[energy_ii + 1])

                    # 收取完能量后返回到列表中
                    ## time.sleep(1)
                    log_tools.log('info', "返回好友列表")
                    adb_tools.keyevent_by_num(4)
                    time.sleep(1)
            else:
                log_tools.log('info', "不需要进入好友森林详情")
            log_tools.log('info', "好友列表向下滑动")
            adb_tools.swipe_by_2point(100, 900, 100, 100)
Beispiel #8
0
def main():
    """
    主函数
    """

    log_tools.log('info', '程序版本号:{}'.format(VERSION))

    # 唤醒屏幕-输入密码并进入到对应app
    wake_up.screenshot_prepare()
    try:
        # 获取庄园两个字后进入到对应应用模块
        time.sleep(3)
        # 开始截图
        now_times = datetime.datetime.now().strftime('%H-%M-%S')
        screenshot.check_screenshot('{}screen.png'.format(now_times))
        # 查找图片中坐标位置,截图后的原点在左下角
        positions = baiOcr.get_position(
            "庄园", "..\\file\\{}screen.png".format(now_times))

        position_x = int(positions[0])
        position_y = int(positions[1])

        adb_tools.tap_by_xy(position_x, position_y)
    except IndexError:
        # 如果已经启动了APP,且没有在首页就重启APP
        wake_up.app_restart()
        try:
            time.sleep(3)
            # 开始截图
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.check_screenshot('{}screen.png'.format(now_times))

            # 查找图片中坐标位置,截图后的原点在左下角
            positions = baiOcr.get_position(
                "庄园", "..\\file\\{}screen.png".format(now_times))

            position_x = int(positions[0])
            position_y = int(positions[1])

            adb_tools.tap_by_xy(position_x, position_y)
        except IndexError:
            time.sleep(3)
            # 开始截图
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.check_screenshot('{}screen.png'.format(now_times))

            # 查找图片中坐标位置,截图后的原点在左下角
            positions = baiOcr.get_position(
                "庄园", "..\\file\\{}screen.png".format(now_times))

            position_x = int(positions[0])
            position_y = int(positions[1])

            adb_tools.tap_by_xy(position_x, position_y)

    # 进入我的界面
    time.sleep(1)
    now_time = datetime.datetime.now().strftime('%H:%M')
    log_tools.log('info', now_time)

    now_times = datetime.datetime.now().strftime('%H-%M-%S')
    screenshot.check_screenshot("{}screen-more.png".format(now_times))
    positions = baiOcr.get_position(
        "我的", "..\\file\\{}screen-more.png".format(now_times))

    position_x = int(positions[0])
    position_y = int(positions[1])
    adb_tools.tap_by_xy(position_x, position_y)
    log_tools.log('info', "进入我的界面")
    time.sleep(2)

    # 进入会员界面
    now_times = datetime.datetime.now().strftime('%H-%M-%S')
    screenshot.check_screenshot("{}screen-more.png".format(now_times))
    positions = baiOcr.get_position(
        "蚂蚁会员", "..\\file\\{}screen-more.png".format(now_times))

    position_x = int(positions[0])
    position_y = int(positions[1])
    adb_tools.tap_by_xy(position_x, position_y)
    log_tools.log('info', "……进入到会员界面")
    time.sleep(2)

    # 进入领取积分界面
    now_times = datetime.datetime.now().strftime('%H-%M-%S')
    screenshot.check_screenshot("{}screen-more.png".format(now_times))
    positions = baiOcr.get_position(
        "赚积分", "..\\file\\{}screen-more.png".format(now_times))

    position_x = int(positions[0])
    position_y = int(positions[1])
    adb_tools.tap_by_xy(position_x, position_y)
    log_tools.log('info', "…………进入到领取积分界面")
    time.sleep(2)

    # 收到积分界面
    now_times = datetime.datetime.now().strftime('%H-%M-%S')
    screenshot.check_screenshot("{}screen-more.png".format(now_times))
    positions = baiOcr.get_position(
        "赚积分", "..\\file\\{}screen-more.png".format(now_times))

    position_x = int(positions[0])
    position_y = int(positions[1])
    adb_tools.tap_by_xy(position_x, position_y)
    log_tools.log('info', "…………进入到领取积分界面")
    time.sleep(2)
def wake_up_only():
    """
    打开app
    """
    try:
        display_power_tate = "".join(
            re.findall(
                r'Display Power: state=\w+',
                os.popen(
                    # 'adb shell dumpsys power | findstr "Display/C Power: state=" ').read()
                    'adb shell dumpsys power').read())).split("=")[1]
        log_tools.log('info', display_power_tate)
        if display_power_tate == 'OFF':
            log_tools.log('info', "唤醒屏幕")
            os.system('adb shell input keyevent 26')
        else:
            log_tools.log('info', "屏幕已开启不需要唤醒")
        is_status_bar_keyguard = "".join(
            re.findall(
                r'isStatusBarKeyguard=\w+',
                os.popen("adb shell dumpsys window policy").read())).split(
                    "=")[1]
        log_tools.log('info', is_status_bar_keyguard)
        if is_status_bar_keyguard == 'true':
            time.sleep(2)
            log_tools.log('info', "解锁屏保")
            # 左右滑动才好解锁,并且延迟100ms启动
            os.system('adb shell input swipe 200 400 800 400 100')
            time.sleep(1)
            os.system('adb shell input swipe 200 400 800 400 100')
            time.sleep(1)
            log_tools.log('info', "输入密码")
            os.system('adb shell input text 95729')
        else:
            log_tools.log('info', "屏幕已解锁不需要再次解锁")
        time.sleep(1)
    except Exception:
        log_tools.log('warning', "screenshot_prepare error")
        traceback.print_exc()
        exit(-1)
def main():
    """
    主函数
    """

    log_tools.log('info', '程序版本号:{}'.format(VERSION))

    # 唤醒屏幕-输入密码并进入到对应app
    wake_up.screenshot_prepare()
    try:
        # 获取庄园两个字后进入到对应应用模块
        time.sleep(3)
        # 开始截图
        now_times = datetime.datetime.now().strftime('%H-%M-%S')
        screenshot.check_screenshot('{}screen.png'.format(now_times))
        # 查找图片中坐标位置,截图后的原点在左下角
        positions = baiOcr.get_position(
            "庄园", "..\\file\\{}screen.png".format(now_times))

        position_x = int(positions[0])
        position_y = int(positions[1])

        adb_tools.tap_by_xy(position_x, position_y)
    except IndexError:
        # 如果已经启动了APP,且没有在首页就重启APP
        wake_up.app_restart()
        try:
            time.sleep(3)
            # 开始截图
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.check_screenshot('{}screen.png'.format(now_times))

            # 查找图片中坐标位置,截图后的原点在左下角
            positions = baiOcr.get_position(
                "庄园", "..\\file\\{}screen.png".format(now_times))

            position_x = int(positions[0])
            position_y = int(positions[1])

            adb_tools.tap_by_xy(position_x, position_y)
        except IndexError:
            time.sleep(3)
            # 开始截图
            now_times = datetime.datetime.now().strftime('%H-%M-%S')
            screenshot.check_screenshot('{}screen.png'.format(now_times))

            # 查找图片中坐标位置,截图后的原点在左下角
            positions = baiOcr.get_position(
                "庄园", "..\\file\\{}screen.png".format(now_times))

            position_x = int(positions[0])
            position_y = int(positions[1])

            adb_tools.tap_by_xy(position_x, position_y)

    # 判断当前是否在进行进食
    time.sleep(3)
    now_time = datetime.datetime.now().strftime('%H:%M')
    log_tools.log('info', now_time)

    now_times = datetime.datetime.now().strftime('%H-%M-%S')
    screenshot.check_screenshot("{}screen-more.png".format(now_times))
    positions = baiOcr.get_position(
        "出去散心", "..\\file\\{}screen-more.png".format(now_times))
    if len(positions) != 0:
        log_tools.log('info', "小鸡不在了,请人工找回")
        exit(-1)

    else:
        positions = baiOcr.get_position(
            "进食剩余", "..\\file\\{}screen-more.png".format(now_times))

        if len(positions) != 0:
            log_tools.log('info', "当前还有吃的不需要喂食!")

        # 找到粮食进行喂养
        else:
            # now_times = datetime.datetime.now().strftime('%H-%M-%S')
            # screenshot.check_screenshot("{}screen-more.png".format(now_times))
            positions = baiOcr.get_position(
                "g", "..\\file\\{}screen-more.png".format(now_times))
            if len(positions) == 0:
                log_tools.log('info', "…当前没有食物喂养")
            else:
                position_x = int(positions[0])
                position_y = int(positions[1]) - 60
                adb_tools.tap_by_xy(position_x, position_y)
                log_tools.log('info', "…已尝试进行喂养")
                time.sleep(2)

                # 喂养后点击道具
                now_times = datetime.datetime.now().strftime('%H-%M-%S')
                screenshot.check_screenshot(
                    "{}screen-more.png".format(now_times))
                positions = baiOcr.get_position(
                    "道具", "..\\file\\{}screen-more.png".format(now_times))
                if len(positions) == 0:
                    log_tools.log('info', "……未找到道具按钮")
                else:
                    position_x = int(positions[0])
                    position_y = int(positions[1]) - 50
                    adb_tools.tap_by_xy(position_x, position_y)
                    log_tools.log('info', "……已进入道具道具")
                    time.sleep(2)

                    # 在道具界面使用道具
                    now_times = datetime.datetime.now().strftime('%H-%M-%S')
                    screenshot.check_screenshot(
                        "{}screen-more.png".format(now_times))
                    positions = baiOcr.get_position(
                        "使用道具",
                        "..\\file\\{}screen-more.png".format(now_times))

                    if len(positions) == 0:
                        log_tools.log('info', "…………在道具界面未找到道具")
                    else:
                        position_x = int(positions[0])
                        position_y = int(positions[1])
                        adb_tools.tap_by_xy(position_x, position_y)
                        log_tools.log('info', "…………已使用加速道具")
Beispiel #11
0
def screenshot_prepare():
    """
    打开app
    """
    try:
        display_power_tate = "".join(
            re.findall(
                r'Display Power: state=\w+',
                os.popen(
                    # 'adb shell dumpsys power | findstr "Display/C Power: state=" ').read()
                    'adb shell dumpsys power').read())).split("=")[1]
        log_tools.log('info', display_power_tate)
        if display_power_tate == 'OFF':
            log_tools.log('info', "唤醒屏幕")
            os.system('adb shell input keyevent 26')
        else:
            log_tools.log('info', "屏幕已开启不需要唤醒")
        is_status_bar_keyguard = "".join(
            re.findall(
                r'isStatusBarKeyguard=\w+',
                os.popen("adb shell dumpsys window policy").read())).split(
                    "=")[1]
        log_tools.log('info', is_status_bar_keyguard)
        if is_status_bar_keyguard == 'true':
            time.sleep(2)
            log_tools.log('info', "解锁屏保")
            # 左右滑动才好解锁,并且延迟100ms启动
            os.system('adb shell input swipe 200 400 800 400 100')
            time.sleep(1)
            os.system('adb shell input swipe 200 400 800 400 100')
            time.sleep(1)
            log_tools.log('info', "输入密码")
            os.system('adb shell input text 95729')
        else:
            log_tools.log('info', "屏幕已解锁不需要再次解锁")
        time.sleep(1)
        cmdStr = "adb shell dumpsys activity"
        p = subprocess.Popen(cmdStr,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             shell=True)
        result = p.stdout.read().decode('utf-8')
        regex = re.findall(r'mFocusedActivity:\s\S+\s\S+\s\S+', result)
        # m_focused_activity = "".join(re.findall(r'mFocusedActivity:\s\S+\s\S+\s\S+', os.popen(
        #"adb shell dumpsys activity").read().decode('utf-8'))).split()[3].split("/")[0]
        m_focused_activity = "".join(regex).split()[3].split("/")[0]

        log_tools.log('info', m_focused_activity)
        if m_focused_activity == 'com.eg.android.AlipayGphone':
            log_tools.log('info', "APP已启动,停止APP,等待重新启动")
            os.system('adb shell am force-stop com.eg.android.AlipayGphone')
        time.sleep(1)
        log_tools.log('info', "启动app")
        os.system(
            'adb shell am start -n com.eg.android.AlipayGphone/com.eg.android.AlipayGphone.AlipayLogin activity'
        )
    except Exception:
        traceback.print_exc()
        log_tools.log('warning', "screenshot_prepare error")
        time.sleep(5)
        exit(-1)