Esempio n. 1
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform  #接码平台
        self.code_user = fm_uname  #接码平台帐号
        self.code_pwd = fm_pwd  #接码平台密码
        self.appname = "图加"  #app名字
        self.appname_en = "tujia"  #记录文件用缩写英文名
        self.imei = None
        self.runnum = None  #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0  #初始化出错尝试次数
        self.readnum = random.randint(1, 1)  #初始化阅读次数
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        self.ismenu4 = True
        self.ismenu5 = True
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, 29529)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        elif self.code_platform == "shenhua":
            self.code = Shenhua(self.code_user, self.code_pwd, 86806)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 8500:
            removefile("/sdcard/2/*.jpg")
            removefile("/sdcard/*.jpg")
            time.sleep(1)
            copyfile(
                "/sdcard/1/\.1touxiang/PIC\ \(%s\).jpg" %
                random.randint(1, 1400), "/sdcard/")
            time.sleep(0.5)
            for _ in range(5):
                copyfile(
                    "/sdcard/1/\.1xiangce/PIC\ \(%s\).jpg" %
                    random.randint(1, 1400), "/sdcard/2/")
                time.sleep(0.5)
            WebDriverWait(
                dr,
                30).until(lambda d: d.find_element_by_name("文件管理")).click()
            time.sleep(1)
            try:
                WebDriverWait(
                    dr,
                    30).until(lambda d: d.find_element_by_name("手机")).click()
                time.sleep(1)
            except TimeoutException:
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
                return self.begin
            WebDriverWait(
                dr, 30).until(lambda d: d.find_element_by_name("2")).click()
            time.sleep(1)
            dr.swipe(600, 400, 590, 400, 50)
            time.sleep(1)
            try:
                WebDriverWait(
                    dr,
                    5).until(lambda d: d.find_element_by_name("剪切")).click()
                time.sleep(1)
            except TimeoutException:
                WebDriverWait(
                    dr,
                    30).until(lambda d: d.find_element_by_name("更多")).click()
                time.sleep(2)
                WebDriverWait(
                    dr,
                    30).until(lambda d: d.find_element_by_name("剪切")).click()
                time.sleep(1)
            WebDriverWait(
                dr, 30).until(lambda d: d.find_element_by_name("粘贴")).click()
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            WebDriverWait(
                dr,
                30).until(lambda d: d.find_element_by_name("文件管理")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 30).until(lambda d: d.find_element_by_name("图片")).click()
            time.sleep(5)
            dr.press_keycode(4)
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            #加速器
            WebDriverWait(dr, 10).until(
                lambda d: d.find_element_by_name("GMD Speed Time")).click()
            time.sleep(1)
            try:
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                    "com.gmd.speedtime:id/buttonStop")).click()
                time.sleep(1)
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                    "com.gmd.speedtime:id/buttonStart")).click()
                time.sleep(1)
            except TimeoutException:
                WebDriverWait(dr, 5).until(
                    lambda d: d.find_element_by_name("No, thanks")).click()
                time.sleep(1)
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                    "com.gmd.speedtime:id/buttonStop")).click()
                time.sleep(1)
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                    "com.gmd.speedtime:id/buttonStart")).click()
                time.sleep(1)
            dr.press_keycode(3)
            time.sleep(1)
            WebDriverWait(dr, 30).until(
                lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(5)
            #检测已进入app
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/btn_register"))
            self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                              time.localtime().tm_min,
                                              time.localtime().tm_sec)
            time.sleep(1)
            return self.login_code_platform
        #加速器
        WebDriverWait(dr, 10).until(
            lambda d: d.find_element_by_name("GMD Speed Time")).click()
        time.sleep(1)
        WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
            "com.gmd.speedtime:id/buttonStop")).click()
        time.sleep(1)
        WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
            "com.gmd.speedtime:id/buttonStart")).click()
        time.sleep(1)
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(5)
        #检测已进入app
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
            "com.tujiaapp.tujia:id/btn_register"))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                          time.localtime().tm_min,
                                          time.localtime().tm_sec)
        time.sleep(random.randint(30, 60))
        return self.ends

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" %
                  self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                time.sleep(random.randint(180, 200))
                self.try_count = 0
                print("on try_count,exit")
                try:
                    with open('/sdcard/1/logerror.log', 'a') as f:
                        f.write("\nerror:%s" % self.begintime)
                except:
                    pass
                return self.ends
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z"
        ]
        self.pwd = ""
        for _ in range(random.randint(6, 8)):
            self.pwd += choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/btn_register")).click()
            time.sleep(1)
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/register_service_agree_holder")).click(
                )
            time.sleep(1)
            #选择接码平台获取手机号码
            # self.phone = self.code.getPhone()
            self.phone = self.code.getPhone(vno='0')
            edts = WebDriverWait(
                dr, 15).until(lambda d: d.find_elements_by_class_name(
                    "android.widget.EditText"))
            #输入手机号码
            edts[1].send_keys(self.phone)
            time.sleep(1)
            #点击获取验证码按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/send_code")).click()
            time.sleep(5)
            # try:
            #     dr.find_element_by_name("60s")
            #     print("getMessage failed,try_count:%s" % self.try_count)
            #     #释放号码
            #     self.code.releasePhone(self.phone)
            #     dr.press_keycode(4)
            #     time.sleep(1)
            #     return self.signup
            # except NoSuchElementException:
            #     pass
            #选择接码平台获取验证码
            #图加的验证码:6668【图加科技】
            regrex = r'验证码:(\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #输入验证码
            edts[2].send_keys(captcha)
            time.sleep(1)
            #输入密码
            edts[3].send_keys(self.pwd)
            time.sleep(1)
            edts[0].send_keys(self.get_filemessage("name.txt"))
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/register")).click()
            time.sleep(1)
            #检测注册成功进入下一步
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/control_panel_camera"))
            return self.after_signup
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def after_signup(self):
        dr = self.driver
        #选择头像
        if not random.randint(0, 9):
            WebDriverWait(dr, 20).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/control_panel_me")).click()
            time.sleep(1)
            WebDriverWait(dr, 20).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/me_avatar")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 5).until(lambda d: d.find_element_by_name("相册")).click()
            time.sleep(5)
            self.swipes(300, random.randint(800, 1000), 300,
                        random.randint(400, 600), random.randint(0, 2), 2, 2)
            self.select_one_by_id("com.tujiaapp.tujia:id/grid_image")
            time.sleep(1)
            WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_name("保存")).click()
            time.sleep(5)
            #检测信息保存完毕跳转页面
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.tujiaapp.tujia:id/control_panel_camera"))
        #记录帐号密码
        try:
            with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                f.write(
                    '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                    (self.imei, self.phone, self.pwd, time.localtime().tm_mon,
                     time.localtime().tm_mday, time.localtime().tm_hour,
                     time.localtime().tm_min, time.localtime().tm_sec))
        except:
            with open(
                    'D:/brush/slave/scripts/doc/user%s.log' % self.appname_en,
                    'a') as f:
                f.write(
                    '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                    (self.imei, self.phone, self.pwd, time.localtime().tm_mon,
                     time.localtime().tm_mday, time.localtime().tm_hour,
                     time.localtime().tm_min, time.localtime().tm_sec))
        time.sleep(1)
        return self.do

    def do(self):
        dr = self.driver
        try:
            while self.readnum:
                print("剩下阅读次数:%s" % self.readnum)
                random_read = random.randint(0, 4)
                if random_read == 0:
                    if self.ismenu1:
                        print("goto menu1")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/control_panel_home")
                                          ).click()
                        time.sleep(5)
                        return self.menu1
                    return self.do
                elif random_read == 1:
                    if self.ismenu2:
                        print("goto menu2")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/control_panel_location")
                                          ).click()
                        time.sleep(5)
                        return self.menu2
                    return self.do
                elif random_read == 2:
                    if self.ismenu3:
                        print("goto menu3")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/control_panel_camera")
                                          ).click()
                        time.sleep(5)
                        return self.menu3
                    return self.do
                elif random_read == 3:
                    if self.ismenu4:
                        print("goto menu4")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/control_panel_feed")
                                          ).click()
                        time.sleep(5)
                        return self.menu4
                    return self.do
                else:
                    if self.ismenu5:
                        print("goto menu5")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/control_panel_me")
                                          ).click()
                        time.sleep(5)
                        return self.menu5
                    return self.do
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        return self.ends

    def menu1(self):
        dr = self.driver
        try:
            try:
                WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/tv_info")).click()
                time.sleep(1)
            except TimeoutException:
                pass
            looknum = random.randint(2, 10)
            for _ in range(looknum):
                for i in range(random.randint(0, 2)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(300, 600))
                    time.sleep(random.randint(2, 5))
                self.select_one_by_id("com.tujiaapp.tujia:id/item_tv_title")
                time.sleep(random.randint(5, 10))
                if looknum <= 4:
                    for i in range(random.randint(4, 6)):
                        dr.swipe(300, random.randint(800, 1000), 300,
                                 random.randint(300, 600))
                        time.sleep(random.randint(2, 4))
                elif 4 < looknum <= 8:
                    for i in range(random.randint(2, 4)):
                        dr.swipe(300, random.randint(800, 1000), 300,
                                 random.randint(300, 600))
                        time.sleep(random.randint(2, 4))
                else:
                    for i in range(random.randint(1, 2)):
                        dr.swipe(300, random.randint(800, 1000), 300,
                                 random.randint(300, 600))
                        time.sleep(random.randint(2, 4))
                #点赞
                if not random.randint(0, 4):
                    try:
                        WebDriverWait(
                            dr, 5).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/ll_heart")).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                #收藏
                if not random.randint(0, 4):
                    try:
                        WebDriverWait(
                            dr, 5).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/iv_like")).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                #评论
                if not random.randint(0, 19):
                    try:
                        content = WebDriverWait(
                            dr, 5).until(lambda d: d.find_element_by_id(
                                "com.tujiaapp.tujia:id/tv_comment_count"))
                        match = re.search(r'(\d+)评论', content.text)
                        contentnum = match.group(1)
                        if int(contentnum) > 5:
                            content.click()
                            time.sleep(5)
                            self.swipes(300, random.randint(800, 1000), 300,
                                        random.randint(400, 600),
                                        random.randint(2, 10), 2, 2)
                            time.sleep(2)
                            contenttext = WebDriverWait(
                                dr, 30).until(lambda d: d.find_elements_by_id(
                                    "com.tujiaapp.tujia:id/tv_content"))
                            comtext = contenttext[random.randint(
                                0,
                                contenttext.__len__() - 1)].text
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.tujiaapp.tujia:id/tv_to_comment")
                                              ).click()
                            time.sleep(1)
                            edit = WebDriverWait(dr, 30).until(
                                lambda d: d.find_element_by_class_name(
                                    "android.widget.EditText"))
                            edit.send_keys(comtext)
                            time.sleep(1)
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.tujiaapp.tujia:id/view_comment_sure")
                                              ).click()
                            time.sleep(1)
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.tujiaapp.tujia:id/iv_close_fragment")
                                              ).click()
                            time.sleep(1)
                    except TimeoutException:
                        pass
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
            self.readnum -= 1
            self.ismenu1 = False
        except Exception as e:
            print("error in menu1")
            return self.exception_returnapp()
        return self.do

    def menu2(self):
        dr = self.driver
        try:

            self.ismenu2 = False
        except Exception as e:
            print("error in menu2")
            return self.exception_returnapp()
        return self.do

    def menu3(self):
        dr = self.driver
        try:
            if random.randint(0, 4):
                WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/iv_close_dialog")).click()
                time.sleep(1)
            else:
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/ll_atlas")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/row_rescope_holder")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/upload_media_upload")).click()
                time.sleep(5)
                for _ in range(5):
                    # self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(0, 2), 2, 2)
                    self.select_one_by_id("com.tujiaapp.tujia:id/grid_image")
                    time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/tv_next")).click()
                time.sleep(1)
                tags = WebDriverWait(
                    dr, 10
                ).until(lambda d: d.find_elements_by_xpath(
                    "//android.view.View[@resource-id='com.tujiaapp.tujia:id/flow_tags']/android.widget.TextView"
                ))
                tags[random.randint(0, tags.__len__() - 1)].click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/tv_next")).click()
                time.sleep(1)
                WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                    "com.tujiaapp.tujia:id/iv_scope_back")).click()
                time.sleep(5)
            self.ismenu3 = False
        except Exception as e:
            print("error in menu3")
            return self.exception_returnapp()
        return self.do

    def menu4(self):
        dr = self.driver
        try:
            # try:
            #     WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id("com.tujiaapp.tujia:id/tv_scope_bottom_name"))
            # except TimeoutException:
            #     self.readnum -= 1
            #     self.ismenu4 = False
            #     return self.do
            # for i in range(random.randint(1, 3)):
            #     dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600))
            #     time.sleep(random.randint(2, 5))
            # self.select_one_by_id("com.tujiaapp.tujia:id/tv_scope_bottom_name")
            # time.sleep(random.randint(5, 15))
            # for i in range(random.randint(1, 5)):
            #     dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600))
            #     time.sleep(random.randint(5, 10))
            # #收藏
            # if not random.randint(0, 4):
            #     try:
            #         WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id("com.tujiaapp.tujia:id/iv_like")).click()
            #         time.sleep(5)
            #     except TimeoutException:
            #         pass
            # self.select_one_by_id("com.tujiaapp.tujia:id/staggered_image")
            # time.sleep(random.randint(5, 15))
            # for i in range(random.randint(3, 5)):
            #     dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600))
            #     time.sleep(random.randint(5, 10))
            # #收藏
            # if not random.randint(0, 4):
            #     try:
            #         WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id("com.tujiaapp.tujia:id/single_media_like_holder")).click()
            #         time.sleep(5)
            #     except TimeoutException:
            #         pass
            # dr.press_keycode(4)
            # time.sleep(1)
            # dr.press_keycode(4)
            # time.sleep(1)
            # self.readnum -= 1
            self.ismenu4 = False
        except Exception as e:
            print("error in menu4")
            return self.exception_returnapp()
        return self.do

    def menu5(self):
        dr = self.driver
        try:
            self.ismenu5 = False
        except Exception as e:
            print("error in menu5")
            return self.exception_returnapp()
        return self.do

    def ends(self):
        dr = self.driver
        #二次打开
        for x in range(random.randint(0, 1)):
            dr.press_keycode(3)
            time.sleep(1)
            dr.press_keycode(3)
            time.sleep(30)
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour,
                                         time.localtime().tm_min,
                                         time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' %
                        (time.localtime().tm_mon, time.localtime().tm_mday,
                         self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #加速器
        dr.press_keycode(3)
        time.sleep(1)
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(dr, 10).until(
            lambda d: d.find_element_by_name("GMD Speed Time")).click()
        time.sleep(1)
        try:
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.gmd.speedtime:id/buttonStop")).click()
            time.sleep(1)
        except TimeoutException:
            WebDriverWait(dr, 5).until(
                lambda d: d.find_element_by_name("No, thanks")).click()
            time.sleep(1)
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.gmd.speedtime:id/buttonStop")).click()
            time.sleep(1)
        dr.press_keycode(3)
        time.sleep(1)
        #效率控制
        # st = [1200, 1200, 1200, 1200, 1200, 1200, 180, 120, 40, 20, 10, 10,
        #       10, 20, 20, 20, 10, 10, 5, 0, 0, 0, 0, 0]
        #
        # print("现在时间是%s:%s,脚本将在%s秒后继续执行" % (time.localtime().tm_hour, time.localtime().tm_min, st[time.localtime().tm_hour-1]))
        # time.sleep(st[time.localtime().tm_hour-1])

        return self.exit

    #指定文档中随机获取数据
    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename,
                      'r',
                      encoding='utf-8') as f:
                strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__() - 1)].strip()

    #随机滑动
    def swipes(self,
               x1,
               y1,
               x2,
               y2,
               swipe_num=1,
               swipe_time_min=1,
               swipe_time_max=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_min, swipe_time_max))

    #随机选择
    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(
            self.driver,
            find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            find_max = selectone.__len__() - 1
        selectone[random.randint(find_min, find_max)].click()

    #出错处理
    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        try:
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
        except TimeoutException:
            dr.press_keycode(4)
        time.sleep(5)
        return self.do
Esempio n. 2
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform  #接码平台
        self.code_user = fm_uname  #接码平台帐号
        self.code_pwd = fm_pwd  #接码平台密码
        self.appname = "泡单词"  #app名字
        self.appname_en = "paodanci"  #记录文件用缩写英文名
        self.imei = None
        self.runnum = None  #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0  #初始化出错尝试次数
        self.readnum = random.randint(1, 1)  #初始化阅读次数
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        self.issign = False
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, 25314)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        elif self.code_platform == "shenhua":
            self.code = Shenhua(self.code_user, self.code_pwd, None)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(10)
        #检测更新
        try:
            WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/negative")).click()
            time.sleep(1)
        except TimeoutException:
            pass
        #检测已进入app
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/btn_login_enter"))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                          time.localtime().tm_min,
                                          time.localtime().tm_sec)
        time.sleep(1)
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 8500:
            return self.login_code_platform
        WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/btn_login_enter")).click()
        time.sleep(1)
        WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/btn_visitor_login")).click()
        time.sleep(1)
        #检查广告
        try:
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/ivClose")).click()
            time.sleep(1)
        except TimeoutException:
            pass
        return self.do

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" %
                  self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                print("on try_count,exit")
                return self.exit
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z"
        ]
        self.pwd = choice(pwd_li) + choice(pwd_li) + choice(pwd_li) + choice(
            pwd_li) + choice(pwd_li) + choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/btn_login_enter")).click()
            time.sleep(1)
            #选择接码平台获取手机号码
            self.phone = self.code.getPhone()
            edts = WebDriverWait(
                dr, 15).until(lambda d: d.find_elements_by_class_name(
                    "android.widget.EditText"))
            #输入手机号码
            edts[0].send_keys(self.phone)
            time.sleep(1)
            #点击获取验证码按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/btn_getChecked")).click()
            time.sleep(5)
            #选择接码平台获取验证码
            #【泡单词】你的验证码为:575715,10分钟内有效,请勿泄露给他人。
            regrex = r'验证码为:(\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #输入验证码
            edts[1].send_keys(captcha)
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/login")).click()
            time.sleep(1)
            #检查广告
            try:
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/ivClose")).click()
                time.sleep(1)
            except TimeoutException:
                pass
            #检测注册成功进入下一步
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/rbtn_personal_center")).click()
            time.sleep(1)
            return self.after_signup
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def after_signup(self):
        dr = self.driver
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/tv_user_nickname")).click()
        time.sleep(1)
        #输入昵称
        name = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/et_nickname"))
        name.click()
        time.sleep(0.5)
        dr.press_keycode(123)
        time.sleep(0.5)
        for i in range(10):
            dr.press_keycode(67)
        name.send_keys(self.get_filemessage("name.txt"))
        time.sleep(1)
        #选择性别
        if random.randint(0, 1):
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/tv_gender")).click()
            time.sleep(1)
            dr.swipe(300, 1180, 300, 1100)
            WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_name("确定")).click()
            time.sleep(1)
        #选择年龄
        if not random.randint(0, 4):
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/tv_age")).click()
            time.sleep(1)
            self.swipes(300, 1180, 300, 1100, random.randint(17, 30), 1, 1)
            WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_name("确定")).click()
            time.sleep(1)
        #保存信息按钮
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/ibtn_right")).click()
        time.sleep(10)
        #检测信息保存完毕跳转页面
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
            "com.paoword.www.paoword:id/rbtn_personal_center"))
        #选择头像
        if not random.randint(0, 9):
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/chiv_user_header")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 5).until(lambda d: d.find_element_by_name("相册")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 5).until(lambda d: d.find_element_by_name("文件管理")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_name("1")).click()
            time.sleep(1)
            WebDriverWait(dr, 15).until(
                lambda d: d.find_element_by_name("1touxiang")).click()
            time.sleep(1)
            for i in range(random.randint(0, 80)):
                dr.swipe(300, random.randint(800, 1000), 300,
                         random.randint(300, 600))
                time.sleep(1)
            time.sleep(5)
            self.select_one_by_id("com.android.fileexplorer:id/file_image")
            time.sleep(1)
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/btn_done")).click()
            time.sleep(1)
            #检测信息保存完毕跳转页面
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/rbtn_personal_center"))
        self.issign = True
        #记录帐号密码
        try:
            with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                f.write(
                    '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                    (self.imei, self.phone, self.pwd, time.localtime().tm_mon,
                     time.localtime().tm_mday, time.localtime().tm_hour,
                     time.localtime().tm_min, time.localtime().tm_sec))
        except:
            with open(
                    'D:/brush/slave/scripts/doc/user%s.log' % self.appname_en,
                    'a') as f:
                f.write(
                    '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                    (self.imei, self.phone, self.pwd, time.localtime().tm_mon,
                     time.localtime().tm_mday, time.localtime().tm_hour,
                     time.localtime().tm_min, time.localtime().tm_sec))
        time.sleep(1)
        return self.do

    def do(self):
        dr = self.driver
        try:
            if self.ismenu1:
                print("goto menu1")
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/rbtn_index")).click()
                time.sleep(5)
                return self.menu1
            if self.ismenu2 and self.issign and random.randint(0, 2):
                print("goto menu2")
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/rbtn_arena")).click()
                time.sleep(5)
                return self.menu2
            if self.ismenu3 and self.issign and random.randint(0, 1):
                print("goto menu3")
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/rbtn_personal_center")).click(
                    )
                time.sleep(5)
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        return self.ends

    def menu1(self):
        dr = self.driver
        try:
            #添加计划
            try:
                WebDriverWait(
                    dr,
                    5).until(lambda d: d.find_element_by_name("添加计划")).click()
                time.sleep(1)
                WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/tv_title"))
                #选择词汇
                self.swipes(100, random.randint(800, 1000), 100,
                            random.randint(400, 600), random.randint(0, 1), 1,
                            1)
                self.select_one_by_id("com.paoword.www.paoword:id/tv_title")
                time.sleep(1)
                self.select_one_by_id("com.paoword.www.paoword:id/typeName2")
                time.sleep(5)
                #每天词量/完成天数
                for i in range(random.randint(0, 5)):
                    dr.swipe(200, 1160, 200, 1060)
                    time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/btn_ok")).click()
                time.sleep(5)
            except TimeoutException:
                pass
            #学习
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/begin")).click()
            time.sleep(1)
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.paoword.www.paoword:id/layout_expand")).click()
            time.sleep(1)
            for x in range(random.randint(10, 20)):
                try:
                    #拆分单词
                    if random.randint(0, 4):
                        try:
                            WebDriverWait(
                                dr, 5).until(lambda d: d.find_element_by_id(
                                    "com.paoword.www.paoword:id/layout_expand")
                                             ).click()
                            time.sleep(random.randint(2, 5))
                        except TimeoutException:
                            pass
                    #查看视频
                    if not random.randint(0, 19):
                        try:
                            WebDriverWait(
                                dr, 5).until(lambda d: d.find_element_by_id(
                                    "com.paoword.www.paoword:id/tv_btn_connect"
                                )).click()
                            time.sleep(random.randint(5, 15))
                        except TimeoutException:
                            pass
                    #收藏
                    if not random.randint(0, 4):
                        try:
                            WebDriverWait(
                                dr, 5).until(lambda d: d.find_element_by_id(
                                    "com.paoword.www.paoword:id/actionAddWord")
                                             ).click()
                            time.sleep(1)
                        except TimeoutException:
                            pass
                    #笔记
                    if not random.randint(0, 19) and self.issign:
                        # note = WebDriverWait(dr, 20).until(lambda d: d.find_element_by_id(choice(["com.paoword.www.paoword:id/memory_dec", "com.paoword.www.paoword:id/memory_assistance"]))).text
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/note")).click()
                        time.sleep(1)
                        self.swipes(300, random.randint(800, 1000), 300,
                                    random.randint(400, 600),
                                    random.randint(0, 2), 1, 2)
                        time.sleep(1)
                        try:
                            contenttext = WebDriverWait(
                                dr, 10
                            ).until(lambda d: d.find_elements_by_id(
                                "com.paoword.www.paoword:id/tv_expandable_text"
                            ))
                            note = contenttext[random.randint(
                                0,
                                contenttext.__len__() - 1)].text
                            WebDriverWait(
                                dr, 15
                            ).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/tv_btn_write_note")
                                    ).click()
                            time.sleep(1)
                            edts = WebDriverWait(
                                dr, 15
                            ).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/et_note_content"))
                            edts.send_keys(note)
                            time.sleep(1)
                            WebDriverWait(
                                dr, 15).until(lambda d: d.find_element_by_id(
                                    "com.paoword.www.paoword:id/btn_right")
                                              ).click()
                            time.sleep(1)
                            WebDriverWait(
                                dr, 15).until(lambda d: d.find_element_by_id(
                                    "com.paoword.www.paoword:id/actionBack")
                                              ).click()
                            time.sleep(1)
                        except TimeoutException:
                            dr.press_keycode(4)
                            time.sleep(1)
                    time.sleep(random.randint(2, 5))
                    #检测学习完成
                    try:
                        WebDriverWait(
                            dr, 2).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/img_btn_back"))
                        time.sleep(1)
                        break
                    except TimeoutException:
                        pass
                    #泡/爆
                    if random.randint(0, 4):
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/next")).click()
                        time.sleep(1)
                    else:
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/ignore")).click()
                        time.sleep(1)
                except TimeoutException:
                    break
            dr.press_keycode(4)
            time.sleep(5)
            dr.press_keycode(4)
            time.sleep(1)
            #复习
            if random.randint(0, 1):
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.paoword.www.paoword:id/redo")).click()
                time.sleep(1)
                for x in range(random.randint(2, 5)):
                    time.sleep(random.randint(2, 5))
                    #提示
                    if not random.randint(0, 4):
                        try:
                            WebDriverWait(
                                dr, 5).until(lambda d: d.find_element_by_id(
                                    "com.paoword.www.paoword:id/reminder_image"
                                )).click()
                            time.sleep(2)
                        except TimeoutException:
                            pass
                    try:
                        ans = WebDriverWait(
                            dr, 5).until(lambda d: d.find_element_by_id(
                                choice([
                                    "com.paoword.www.paoword:id/item1_margin",
                                    "com.paoword.www.paoword:id/item2_margin",
                                    "com.paoword.www.paoword:id/item3_margin",
                                    "com.paoword.www.paoword:id/item4_margin"
                                ])))
                        dr.tap(ans.location['x'] + 5, ans.location['y'] + 5)
                        time.sleep(1)
                    except TimeoutException:
                        dr.press_keycode(4)
                        time.sleep(5)
                        break
                dr.press_keycode(4)
                time.sleep(1)
            self.ismenu1 = False
        except Exception as e:
            print("error in menu1")
            return self.exception_returnapp()
        return self.do

    def menu2(self):
        dr = self.driver
        try:
            WebDriverWait(
                dr,
                15).until(lambda d: d.find_element_by_name("双人竞技")).click()
            time.sleep(5)
            for x in range(15):
                try:
                    WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                        choice([
                            "com.paoword.www.paoword:id/option_view_1",
                            "com.paoword.www.paoword:id/option_view_2",
                            "com.paoword.www.paoword:id/option_view_3",
                            "com.paoword.www.paoword:id/option_view_4"
                        ]))).click()
                    WebDriverWait(
                        dr, 10).until_not(lambda d: d.find_element_by_id(
                            "com.paoword.www.paoword:id/option_view_1"))
                    time.sleep(random.randint(1, 3))
                except TimeoutException:
                    try:
                        WebDriverWait(
                            dr, 5).until(lambda d: d.find_element_by_id(
                                "com.paoword.www.paoword:id/ibtn_back")).click(
                                )
                        time.sleep(1)
                        break
                    except TimeoutException:
                        pass
                    try:
                        dr.find_element_by_name("双人竞技")
                        time.sleep(1)
                        break
                    except NoSuchElementException:
                        pass
                    try:
                        dr.find_element_by_id(
                            "com.paoword.www.paoword:id/positive").click()
                        time.sleep(1)
                        break
                    except NoSuchElementException:
                        pass
                time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            self.ismenu2 = False
        except Exception as e:
            print("error in menu2")
            return self.exception_returnapp()
        return self.do

    def ends(self):
        dr = self.driver
        #二次打开
        for x in range(random.randint(0, 1)):
            dr.press_keycode(3)
            time.sleep(1)
            dr.press_keycode(3)
            time.sleep(30)
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour,
                                         time.localtime().tm_min,
                                         time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' %
                        (time.localtime().tm_mon, time.localtime().tm_mday,
                         self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #效率控制
        st = [
            1200, 2000, 2500, 3000, 3000, 1200, 180, 120, 40, 20, 10, 10, 10,
            5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
        ]

        print("现在时间是%s:%s,脚本将在%s秒后继续执行" %
              (time.localtime().tm_hour, time.localtime().tm_min,
               st[time.localtime().tm_hour - 1]))
        time.sleep(st[time.localtime().tm_hour - 1])

        return self.exit

    #指定文档中随机获取数据
    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename,
                      'r',
                      encoding='utf-8') as f:
                strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__() - 1)].strip()

    #随机滑动
    def swipes(self,
               x1,
               y1,
               x2,
               y2,
               swipe_num=1,
               swipe_time_min=1,
               swipe_time_max=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_min, swipe_time_max))

    #随机选择
    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(
            self.driver,
            find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            find_max = selectone.__len__() - 1
        selectone[random.randint(find_min, find_max)].click()

    #出错处理
    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        try:
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
        except TimeoutException:
            dr.press_keycode(4)
        time.sleep(5)
        return self.do
Esempio n. 3
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform  #接码平台
        self.code_user = fm_uname  #接码平台帐号
        self.code_pwd = fm_pwd  #接码平台密码
        self.appname = "直销银行"  #app名字
        self.appname_en = "zijin"  #记录文件用缩写英文名
        self.imei = None
        self.runnum = None  #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0  #初始化出错尝试次数
        self.readnum = random.randint(2, 2)  #初始化阅读次数
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        elif self.code_platform == "shenhua":
            self.code = Shenhua(self.code_user, self.code_pwd, 44739)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(10)
        #检测已进入app
        WebDriverWait(dr, 60).until(
            lambda d: d.find_element_by_class_name("android.widget.ImageView"))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                          time.localtime().tm_min,
                                          time.localtime().tm_sec)
        time.sleep(1)
        #新开软件翻页
        self.swipes(600, 300, 300, 300, 1, 2, 2)
        WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.zijinbank:id/head_icon"))
        dr.tap(80, 1250)
        time.sleep(1)
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 10000:
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.zijinbank:id/head_image")).click()
            time.sleep(1)
            return self.login_code_platform

        return self.do

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" %
                  self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                print("on try_count,exit")
                return self.exit
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z"
        ]
        self.pwd = ""
        for _ in range(random.randint(8, 10)):
            self.pwd += choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.zijinbank:id/login_btn_register_account")
                                        ).click()
            time.sleep(1)
            #选择接码平台获取手机号码
            self.phone = self.code.getPhone()
            edts = WebDriverWait(
                dr, 60).until(lambda d: d.find_elements_by_class_name(
                    "android.widget.EditText"))
            #输入手机号码
            edts[0].send_keys(self.phone)
            time.sleep(1)
            #输入密码
            edts[1].send_keys(self.pwd)
            time.sleep(1)
            edts[2].send_keys(self.pwd)
            time.sleep(1)
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_class_name(
                "android.widget.CheckBox")).click()
            time.sleep(1)
            dr.swipe(300, 1000, 300, 900)
            time.sleep(1)
            #点击获取验证码按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.zijinbank:id/register_btn_register")
                                        ).click()
            time.sleep(5)
            try:
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.pafinancialtech.zijinbank:id/tv_sms")).click()
                time.sleep(5)
            except TimeoutException:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #选择接码平台获取验证码
            #验证码:799971。尊敬的客户您好:您于2016年12月21日14时36分使用紫金农商银行平台用户注册服务(5分钟内有效),切勿泄漏并妥善保管。【江苏农信】
            regrex = r'验证码:(\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            edts = WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_class_name(
                    "android.widget.EditText"))
            #输入验证码
            edts.send_keys(captcha)
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(
                dr, 10).until(lambda d: d.find_element_by_name("确定")).click()
            time.sleep(5)
            #检测注册成功进入下一步
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.zijinbank:id/iv_title_right_image")
                                        ).click()
            time.sleep(1)
            try:
                WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                    "com.pafinancialtech.zijinbank:id/btn_center")).click()
                time.sleep(1)
            except TimeoutException:
                pass
            #记录帐号密码
            try:
                with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                    f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                            (self.imei, self.phone, self.pwd,
                             time.localtime().tm_mon, time.localtime().tm_mday,
                             time.localtime().tm_hour, time.localtime().tm_min,
                             time.localtime().tm_sec))
            except:
                with open(
                        'D:/brush/slave/scripts/doc/user%s.log' %
                        self.appname_en, 'a') as f:
                    f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                            (self.imei, self.phone, self.pwd,
                             time.localtime().tm_mon, time.localtime().tm_mday,
                             time.localtime().tm_hour, time.localtime().tm_min,
                             time.localtime().tm_sec))
            time.sleep(1)
            return self.do
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def do(self):
        dr = self.driver
        try:
            while self.readnum:
                print("剩下阅读次数:%s" % self.readnum)
                random_read = random.randint(0, 2)
                if random_read == 0:
                    if self.ismenu1:
                        print("goto menu1")
                        try:
                            WebDriverWait(dr, 15).until(
                                lambda d: d.find_elements_by_class_name(
                                    "android.widget.ImageButton"))[3].click()
                            time.sleep(5)
                            time.sleep(random.randint(15, 30))
                        except TimeoutException:
                            pass
                        self.readnum -= 1
                        self.ismenu1 = False
                    return self.do
                elif random_read == 1:
                    if self.ismenu2:
                        print("goto menu2")
                        try:
                            WebDriverWait(dr, 15).until(
                                lambda d: d.find_elements_by_class_name(
                                    "android.widget.ImageButton"))[1].click()
                            time.sleep(5)
                            time.sleep(random.randint(15, 30))
                        except TimeoutException:
                            pass
                        self.readnum -= 1
                        self.ismenu2 = False
                    return self.do
                else:
                    if self.ismenu3:
                        print("goto menu3")
                        try:
                            WebDriverWait(dr, 15).until(
                                lambda d: d.find_elements_by_class_name(
                                    "android.widget.ImageButton"))[2].click()
                            time.sleep(5)
                            time.sleep(random.randint(15, 30))
                        except TimeoutException:
                            pass
                        self.readnum -= 1
                        self.ismenu3 = False
                    return self.do
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        dr.press_keycode(4)
        time.sleep(1)
        WebDriverWait(dr,
                      15).until(lambda d: d.find_element_by_name("确定要退出程序吗?"))
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_elements_by_class_name(
            "android.widget.TextView"))[1].click()
        time.sleep(5)
        return self.ends

    def ends(self):
        dr = self.driver
        #二次打开
        for x in range(random.randint(0, 0)):
            dr.press_keycode(3)
            time.sleep(1)
            dr.press_keycode(3)
            time.sleep(30)
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour,
                                         time.localtime().tm_min,
                                         time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' %
                        (time.localtime().tm_mon, time.localtime().tm_mday,
                         self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #效率控制
        # st = [1200, 1200, 1200, 1200, 1200, 1200, 180, 120, 40, 20, 10, 10,
        #       10, 20, 20, 20, 10, 10, 5, 0, 0, 0, 0, 0]
        #
        # print("现在时间是%s:%s,脚本将在%s秒后继续执行" % (time.localtime().tm_hour, time.localtime().tm_min, st[time.localtime().tm_hour-1]))
        # time.sleep(st[time.localtime().tm_hour-1])

        return self.exit

    #指定文档中随机获取数据
    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename,
                      'r',
                      encoding='utf-8') as f:
                strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__() - 1)].strip()

    #随机滑动
    def swipes(self,
               x1,
               y1,
               x2,
               y2,
               swipe_num=1,
               swipe_time_min=1,
               swipe_time_max=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_min, swipe_time_max))

    #随机选择
    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(
            self.driver,
            find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            find_max = selectone.__len__() - 1
        selectone[random.randint(find_min, find_max)].click()

    #出错处理
    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        try:
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
        except TimeoutException:
            dr.press_keycode(4)
        time.sleep(5)
        return self.do
Esempio n. 4
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform  #接码平台
        self.code_user = fm_uname  #接码平台帐号
        self.code_pwd = fm_pwd  #接码平台密码
        self.appname = "e帆风顺"  #app名字
        self.appname_en = "efanfengshun"  #记录文件用缩写英文名
        self.imei = None
        self.runnum = None  #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0  #初始化出错尝试次数
        self.readnum = random.randint(2, 2)  #初始化阅读次数
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        elif self.code_platform == "shenhua":
            self.code = Shenhua(self.code_user, self.code_pwd, 96321)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(10)
        #检测已进入app
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/headImg"))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                          time.localtime().tm_min,
                                          time.localtime().tm_sec)
        time.sleep(1)
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 10000:
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.shundebank:id/headImg")).click()
            time.sleep(1)
            return self.login_code_platform

        return self.do

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" %
                  self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                print("on try_count,exit")
                return self.exit
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z"
        ]
        self.pwd = ""
        for _ in range(random.randint(8, 10)):
            self.pwd += choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.shundebank:id/login_btn_register_account")
                                        ).click()
            time.sleep(1)
            #选择接码平台获取手机号码
            self.phone = self.code.getPhone()
            edts = WebDriverWait(
                dr, 15).until(lambda d: d.find_elements_by_class_name(
                    "android.widget.EditText"))
            #输入手机号码
            edts[0].send_keys(self.phone)
            time.sleep(1)
            #输入密码
            edts[1].send_keys(self.pwd)
            time.sleep(1)
            edts[2].send_keys(self.pwd)
            time.sleep(1)
            #点击获取验证码按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.shundebank:id/register_btn_register")
                                        ).click()
            time.sleep(5)
            try:
                WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                    "com.pafinancialtech.shundebank:id/login_dialog_right")
                                            ).click()
                time.sleep(5)
            except TimeoutException:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            edts = WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_class_name(
                    "android.widget.EditText"))
            #选择接码平台获取验证码
            #动态验证码:882371(90秒有效)。您正在进行e帆风顺直销银行用户注册,验证码打死也不能告诉别人哦!【顺德农商银行】
            regrex = r'验证码:(\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #输入验证码
            edts.send_keys(captcha)
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.shundebank:id/verify_btn_commit")).click(
                )
            time.sleep(1)
            #检测注册成功进入下一步
            WebDriverWait(
                dr,
                60).until(lambda d: d.find_element_by_name("回到首页")).click()
            time.sleep(1)
            return self.after_signup
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def after_signup(self):
        dr = self.driver
        WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/settingImg")).click()
        time.sleep(1)
        WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/userBasicInfoLinearLayout")
                                    ).click()
        time.sleep(1)
        WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/rl_user_nick_layout")).click()
        time.sleep(1)
        #输入昵称
        edts = WebDriverWait(dr, 15).until(
            lambda d: d.find_element_by_class_name("android.widget.EditText"))
        edts.send_keys(self.get_filemessage("name.txt"))
        time.sleep(1)
        WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/btn_title_right_button")).click(
            )
        time.sleep(1)
        #选择头像
        if not random.randint(0, 9):
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.shundebank:id/userThumbnail")).click()
            time.sleep(1)
            WebDriverWait(
                dr,
                5).until(lambda d: d.find_element_by_name("从相册中选取")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 5).until(lambda d: d.find_element_by_name("文件管理")).click()
            time.sleep(1)
            WebDriverWait(
                dr, 15).until(lambda d: d.find_element_by_name("1")).click()
            time.sleep(1)
            WebDriverWait(dr, 15).until(
                lambda d: d.find_element_by_name("1touxiang")).click()
            time.sleep(1)
            for i in range(random.randint(0, 80)):
                dr.swipe(300, random.randint(800, 1000), 300,
                         random.randint(300, 600))
                time.sleep(1)
            time.sleep(5)
            self.select_one_by_id("com.android.fileexplorer:id/file_image")
            time.sleep(1)
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.pafinancialtech.shundebank:id/ok")).click()
            time.sleep(5)
        #保存信息按钮
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/editInfoConfrimBtn")).click()
        time.sleep(10)
        #检测信息保存完毕跳转页面
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
            "com.pafinancialtech.shundebank:id/tv_title_back_text")).click()
        time.sleep(1)
        #记录帐号密码
        try:
            with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                f.write(
                    '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                    (self.imei, self.phone, self.pwd, time.localtime().tm_mon,
                     time.localtime().tm_mday, time.localtime().tm_hour,
                     time.localtime().tm_min, time.localtime().tm_sec))
        except:
            with open(
                    'D:/brush/slave/scripts/doc/user%s.log' % self.appname_en,
                    'a') as f:
                f.write(
                    '\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                    (self.imei, self.phone, self.pwd, time.localtime().tm_mon,
                     time.localtime().tm_mday, time.localtime().tm_hour,
                     time.localtime().tm_min, time.localtime().tm_sec))
        time.sleep(1)
        return self.do

    def do(self):
        dr = self.driver
        try:
            while self.readnum:
                print("剩下阅读次数:%s" % self.readnum)
                random_read = random.randint(0, 2)
                if random_read == 0:
                    if self.ismenu1:
                        print("goto menu1")
                        try:
                            WebDriverWait(
                                dr, 15).until(lambda d: d.find_elements_by_id(
                                    "android.widget.ImageButton"))[0].click()
                            time.sleep(5)
                            time.sleep(random.randint(15, 30))
                        except TimeoutException:
                            pass
                        self.readnum -= 1
                        self.ismenu1 = False
                    return self.do
                elif random_read == 1:
                    if self.ismenu2:
                        print("goto menu2")
                        try:
                            WebDriverWait(
                                dr, 15).until(lambda d: d.find_elements_by_id(
                                    "android.widget.ImageButton"))[1].click()
                            time.sleep(5)
                            time.sleep(random.randint(15, 30))
                        except TimeoutException:
                            pass
                        self.readnum -= 1
                        self.ismenu2 = False
                    return self.do
                else:
                    if self.ismenu3:
                        print("goto menu3")
                        try:
                            WebDriverWait(
                                dr, 15).until(lambda d: d.find_elements_by_id(
                                    "android.widget.ImageButton"))[2].click()
                            time.sleep(5)
                            time.sleep(random.randint(15, 30))
                        except TimeoutException:
                            pass
                        self.readnum -= 1
                        self.ismenu3 = False
                    return self.do
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        return self.ends

    def ends(self):
        dr = self.driver
        #二次打开
        for x in range(random.randint(0, 1)):
            dr.press_keycode(3)
            time.sleep(1)
            dr.press_keycode(3)
            time.sleep(30)
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour,
                                         time.localtime().tm_min,
                                         time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' %
                        (time.localtime().tm_mon, time.localtime().tm_mday,
                         self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #效率控制
        # st = [1200, 1200, 1200, 1200, 1200, 1200, 180, 120, 40, 20, 10, 10,
        #       10, 20, 20, 20, 10, 10, 5, 0, 0, 0, 0, 0]
        #
        # print("现在时间是%s:%s,脚本将在%s秒后继续执行" % (time.localtime().tm_hour, time.localtime().tm_min, st[time.localtime().tm_hour-1]))
        # time.sleep(st[time.localtime().tm_hour-1])

        return self.exit

    #指定文档中随机获取数据
    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename,
                      'r',
                      encoding='utf-8') as f:
                strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__() - 1)].strip()

    #随机滑动
    def swipes(self,
               x1,
               y1,
               x2,
               y2,
               swipe_num=1,
               swipe_time_min=1,
               swipe_time_max=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_min, swipe_time_max))

    #随机选择
    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(
            self.driver,
            find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            find_max = selectone.__len__() - 1
        selectone[random.randint(find_min, find_max)].click()

    #出错处理
    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        try:
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
        except TimeoutException:
            dr.press_keycode(4)
        time.sleep(5)
        return self.do
Esempio n. 5
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform  #接码平台
        self.code_user = fm_uname  #接码平台帐号
        self.code_pwd = fm_pwd  #接码平台密码
        self.appname = "上海观察"  #app名字
        self.appname_en = "shanghai"  #记录文件用缩写英文名
        self.imei = None
        self.runnum = None  #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0  #初始化出错尝试次数
        self.readnum = random.randint(2, 2)  #初始化阅读次数
        self.issign = False
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, 24394)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, 26320)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        else:
            self.code = Shenhua(self.code_user, self.code_pwd, 82914)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(10)
        try:
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/sdl__content"))
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
        except TimeoutException:
            pass
        #检测已进入app
        WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
            "com.shwatch.news:id/slideMenu_homepage"))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                          time.localtime().tm_min,
                                          time.localtime().tm_sec)
        time.sleep(1)
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 1000:
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/user_btn")).click()
            time.sleep(1)
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/login_btn")).click()
            time.sleep(1)
            return self.login_code_platform

        return self.do

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" %
                  self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                print("on try_count,exit")
                return self.exit
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z"
        ]
        self.pwd = choice(pwd_li) + choice(pwd_li) + choice(pwd_li) + choice(
            pwd_li) + choice(pwd_li) + choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/btn_login_regist")).click()
            time.sleep(1)
            #选择接码平台获取手机号码
            self.phone = self.code.getPhone()
            edts = WebDriverWait(
                dr, 15).until(lambda d: d.find_elements_by_class_name(
                    "android.widget.EditText"))
            #输入手机号码
            edts[0].send_keys(self.phone)
            time.sleep(1)
            #点击获取验证码按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/get_identified_code_layout")).click()
            time.sleep(1)
            #输入密码
            edts[2].send_keys(self.pwd)
            time.sleep(1)
            edts[3].send_keys(self.pwd)
            time.sleep(1)
            #选择接码平台获取验证码
            #感谢您注册上海观察,验证码:[8596],有效期为5分钟
            #感谢您注册上观,验证码:[4438],有效期为5分钟【上观新闻】
            regrex = r'验证码:[\[\(](\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #输入验证码
            edts[1].send_keys(captcha)
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/btn_regist_next")).click()
            time.sleep(1)
            #检测注册成功进入下一步
            WebDriverWait(dr, 60).until(
                lambda d: d.find_element_by_id("android:id/button1")).click()
            time.sleep(1)
            #记录帐号密码
            try:
                with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                    f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                            (self.imei, self.phone, self.pwd,
                             time.localtime().tm_mon, time.localtime().tm_mday,
                             time.localtime().tm_hour, time.localtime().tm_min,
                             time.localtime().tm_sec))
            except:
                with open(
                        'D:/brush/slave/scripts/doc/user%s.log' %
                        self.appname_en, 'a') as f:
                    f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                            (self.imei, self.phone, self.pwd,
                             time.localtime().tm_mon, time.localtime().tm_mday,
                             time.localtime().tm_hour, time.localtime().tm_min,
                             time.localtime().tm_sec))
            time.sleep(1)
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/login_btn")).click()
            time.sleep(5)
            #登录
            for x in range(5):
                try:
                    WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                        "com.shwatch.news:id/login_btn")).click()
                    time.sleep(1)
                except TimeoutException:
                    break
            #登录完成
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/user_info"))
            self.issign = True
            return self.after_signup
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def after_signup(self):
        dr = self.driver
        try:
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/user_info")).click()
            time.sleep(1)
            #修改名字
            if random.randint(0, 1):
                WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                    "com.shwatch.news:id/nickname_layout")).click()
                time.sleep(1)
                #输入昵称
                edts = WebDriverWait(
                    dr, 15).until(lambda d: d.find_element_by_class_name(
                        "android.widget.EditText"))
                edts.send_keys(self.get_filemessage("name.txt"))
                time.sleep(1)
                WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                    "com.shwatch.news:id/comfirmed_change")).click()
                time.sleep(1)
            #修改头像
            if random.randint(0, 9) == 0:
                copyfile(
                    "/sdcard/1/1touxiang/PIC\ \(%s\).jpg" %
                    random.randint(1, 1000), "/sdcard/2/")
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.shwatch.news:id/mainpage_user_headimg")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.shwatch.news:id/mainpage_btn_picgroup")).click()
                time.sleep(1)
                WebDriverWait(
                    dr,
                    5).until(lambda d: d.find_element_by_name("文件管理")).click()
                time.sleep(1)
                WebDriverWait(
                    dr,
                    15).until(lambda d: d.find_element_by_name("2")).click()
                time.sleep(1)
                self.select_one_by_id("com.android.fileexplorer:id/file_image")
                time.sleep(1)
                WebDriverWait(
                    dr,
                    15).until(lambda d: d.find_element_by_name("应用")).click()
                time.sleep(5)
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                "com.shwatch.news:id/btn_callback")).click()
            time.sleep(1)
            for x in range(10):
                dr.press_keycode(4)
                time.sleep(1)
                try:
                    WebDriverWait(dr, 2).until(
                        lambda d: d.find_element_by_name("取消")).click()
                    time.sleep(1)
                    try:
                        dr.tap(random.randint(800, 1000),
                               random.randint(100, 1600))
                    except:
                        dr.tap(random.randint(550, 700),
                               random.randint(100, 1000))
                    time.sleep(5)
                    break
                except TimeoutException:
                    pass
        except:
            for x in range(10):
                dr.press_keycode(4)
                time.sleep(1)
                try:
                    WebDriverWait(dr, 2).until(
                        lambda d: d.find_element_by_name("取消")).click()
                    time.sleep(1)
                    try:
                        dr.tap(random.randint(800, 1000),
                               random.randint(100, 1600))
                    except:
                        dr.tap(random.randint(550, 700),
                               random.randint(100, 1000))
                    time.sleep(5)
                    break
                except TimeoutException:
                    pass
        return self.do

    def do(self):
        dr = self.driver
        try:
            while self.readnum:
                print("剩下阅读次数:%s" % self.readnum)
                random_read = random.randint(0, 2)
                if random_read == 0:
                    if self.ismenu1:
                        print("goto menu1")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/homepage_btn")).click()
                        time.sleep(5)
                        return self.menu1
                    return self.do
                elif random_read == 1:
                    if self.ismenu2:
                        print("goto menu2")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/activity_btn")).click()
                        time.sleep(5)
                        return self.menu2
                    return self.do
                elif random_read == 2:
                    if self.ismenu3:
                        print("goto menu3")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/user_btn")).click()
                        time.sleep(5)
                        return self.menu3
                    return self.do
                return self.do
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        return self.ends

    def menu1(self):
        dr = self.driver
        try:
            for _ in range(random.randint(1, 2)):
                #随机滑动
                for x in range(random.randint(1, 3)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(400, 600))
                    time.sleep(random.randint(2, 5))
                #随机选择新闻查看
                selectone = WebDriverWait(
                    dr, 10).until(lambda d: d.find_elements_by_id(
                        choice([
                            "com.shwatch.news:id/news_1smallitem_layout",
                            "com.shwatch.news:id/section_newsitem"
                        ])))
                selectone[random.randint(0, selectone.__len__() - 1)].click()
                time.sleep(random.randint(5, 10))
                #随机滑动
                for x in range(random.randint(2, 4)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(400, 600))
                    time.sleep(random.randint(2, 10))
                #收藏
                if random.randint(0, 4) == 0:
                    try:
                        WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/collection_btn")).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                #喜欢
                if random.randint(0, 4) == 0:
                    try:
                        WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/news_praise")).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                #评论
                if random.randint(0, 9) == 0 and self.issign:
                    try:
                        contentnum = WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/comment_account"))
                        if int(contentnum.text) > 3:
                            contentnum.click()
                            time.sleep(5)
                            self.swipes(300, random.randint(800, 1000), 300,
                                        random.randint(400, 600),
                                        random.randint(0, 3), 2, 5)
                            contenttext = WebDriverWait(
                                dr, 30).until(lambda d: d.find_elements_by_id(
                                    "com.shwatch.news:id/enter_ticket"))
                            time.sleep(1)
                            comtext = contenttext[random.randint(
                                0,
                                contenttext.__len__() - 1)].text
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.shwatch.news:id/write_comment")
                                              ).click()
                            time.sleep(1)
                            edit = WebDriverWait(dr, 30).until(
                                lambda d: d.find_element_by_class_name(
                                    "android.widget.EditText"))
                            edit.send_keys(comtext)
                            time.sleep(1)
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.shwatch.news:id/send_message_btn")
                                              ).click()
                            time.sleep(1)
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.shwatch.news:id/btn_callback")).click(
                                    )
                            time.sleep(1)
                    except TimeoutException:
                        pass
                dr.press_keycode(4)
                time.sleep(1)
            self.readnum -= 1
            self.ismenu1 = False
        except Exception as e:
            print("error in menu1")
            return self.exception_returnapp()
        return self.do

    def menu2(self):
        dr = self.driver
        try:
            for _ in range(random.randint(1, 2)):
                #随机滑动
                for x in range(random.randint(1, 3)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(400, 600))
                    time.sleep(random.randint(2, 5))
                #随机选择新闻查看
                selectone = WebDriverWait(
                    dr, 10).until(lambda d: d.find_elements_by_id(
                        choice([
                            "com.shwatch.news:id/news_1smallitem_layout",
                            "com.shwatch.news:id/section_newsitem"
                        ])))
                selectone[random.randint(0, selectone.__len__() - 1)].click()
                time.sleep(random.randint(5, 10))
                #随机滑动
                for x in range(random.randint(2, 4)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(400, 600))
                    time.sleep(random.randint(2, 10))
                #收藏
                if random.randint(0, 4) == 0:
                    try:
                        WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/collection_btn")).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                #喜欢
                if random.randint(0, 4) == 0:
                    try:
                        WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/news_praise")).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                #评论
                if random.randint(0, 9) == 0 and self.issign:
                    try:
                        contentnum = WebDriverWait(
                            dr, 10).until(lambda d: d.find_element_by_id(
                                "com.shwatch.news:id/comment_account"))
                        if int(contentnum.text) > 3:
                            contentnum.click()
                            time.sleep(5)
                            self.swipes(300, random.randint(800, 1000), 300,
                                        random.randint(400, 600),
                                        random.randint(0, 3), 2, 5)
                            contenttext = WebDriverWait(
                                dr, 30).until(lambda d: d.find_elements_by_id(
                                    "com.shwatch.news:id/enter_ticket"))
                            time.sleep(1)
                            comtext = contenttext[random.randint(
                                0,
                                contenttext.__len__() - 1)].text
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.shwatch.news:id/write_comment")
                                              ).click()
                            time.sleep(1)
                            edit = WebDriverWait(dr, 30).until(
                                lambda d: d.find_element_by_class_name(
                                    "android.widget.EditText"))
                            edit.send_keys(comtext)
                            time.sleep(1)
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.shwatch.news:id/send_message_btn")
                                              ).click()
                            time.sleep(1)
                            WebDriverWait(
                                dr, 30).until(lambda d: d.find_element_by_id(
                                    "com.shwatch.news:id/btn_callback")).click(
                                    )
                            time.sleep(1)
                    except TimeoutException:
                        pass
                dr.press_keycode(4)
                time.sleep(1)
            self.readnum -= 1
            self.ismenu2 = False
        except Exception as e:
            print("error in menu2")
            return self.exception_returnapp()
        return self.do

    def menu3(self):
        dr = self.driver
        try:
            self.ismenu3 = False
        except Exception as e:
            print("error in menu3")
            return self.exception_returnapp()
        return self.do

    def ends(self):
        dr = self.driver
        # if random.randint(0, 1):
        #     dr.press_keycode(3)
        #     time.sleep(1)
        #     dr.press_keycode(3)
        #     time.sleep(30)
        #     WebDriverWait(dr, 2).until(lambda d: d.find_element_by_name(self.appname)).click()
        #     time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour,
                                         time.localtime().tm_min,
                                         time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' %
                        (time.localtime().tm_mon, time.localtime().tm_mday,
                         self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #效率控制
        # st = [1200, 1200, 1200, 1200, 1200, 1200, 180, 120, 40, 20, 10, 10,
        #       10, 20, 20, 20, 10, 10, 5, 0, 0, 0, 0, 0]
        #
        # print("现在时间是%s:%s,脚本将在%s秒后继续执行" % (time.localtime().tm_hour, time.localtime().tm_min, st[time.localtime().tm_hour-1]))
        # time.sleep(st[time.localtime().tm_hour-1])

        return self.exit

    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename,
                      'r',
                      encoding='utf-8') as f:
                strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__() - 1)].strip()

    def swipes(self,
               x1,
               y1,
               x2,
               y2,
               swipe_num=1,
               swipe_time_a=1,
               swipe_time_b=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_a, swipe_time_b))

    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(
            self.driver,
            find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            selectone[random.randint(find_min,
                                     selectone.__len__() - 1)].click()
        else:
            selectone[random.randint(find_min, find_max)].click()

    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        try:
            WebDriverWait(
                dr, 2).until(lambda d: d.find_element_by_name("取消")).click()
        except TimeoutException:
            pass
        time.sleep(1)
        return self.do
Esempio n. 6
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform      #接码平台
        self.code_user = fm_uname       #接码平台帐号
        self.code_pwd = fm_pwd      #接码平台密码
        self.appname = ""       #app名字
        self.appname_en = ""     #记录文件用缩写英文名
        self.imei = None
        self.runnum = None        #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0      #初始化出错尝试次数
        self.readnum = random.randint(2, 2)     #初始化阅读次数
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        self.ismenu4 = True
        self.ismenu5 = True
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        elif self.code_platform == "shenhua":
            self.code = Shenhua(self.code_user, self.code_pwd, None)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(dr, 30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(10)
        #检测已进入app
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(""))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)
        time.sleep(1)
        #新开软件翻页
        self.swipes(600, 300, 300, 300, 4, 2, 2)
        WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id("")).click()
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 10000:
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id("")).click()
            time.sleep(1)
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id("")).click()
            time.sleep(1)
            return self.login_code_platform

        return self.do

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                print("on try_count,exit")
                return self.exit
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
                  "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
                  "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
                  "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
                  "u", "v", "w", "x", "y", "z"]
        self.pwd = ""
        for _ in range(random.randint(6, 8)):
            self.pwd += choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id("")).click()
            time.sleep(1)
            #选择接码平台获取手机号码
            self.phone = self.code.getPhone()
            edts = WebDriverWait(dr, 15).until(lambda d: d.find_elements_by_class_name("android.widget.EditText"))
            #输入手机号码
            edts[0].send_keys(self.phone)
            time.sleep(1)
            #点击获取验证码按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id("")).click()
            time.sleep(5)
            #输入密码
            edts[2].send_keys(self.pwd)
            time.sleep(1)
            #选择接码平台获取验证码
            #【友寻】您的临时验证码为:302855,有效时间为30分钟。
            regrex = r'验证码为:(\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #输入验证码
            edts[1].send_keys(captcha)
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id("")).click()
            time.sleep(1)
            #检测注册成功进入下一步
            WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(""))
            return self.after_signup
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def after_signup(self):
        dr = self.driver
        #选择性别
        WebDriverWait(dr, 20).until(lambda d: d.find_element_by_id(choice(["", ""]))).click()
        time.sleep(1)
        #输入昵称
        edts = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_class_name("android.widget.EditText"))
        edts.send_keys(self.get_filemessage("name.txt"))
        time.sleep(1)
        #选择头像
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
        time.sleep(1)
        WebDriverWait(dr, 5).until(lambda d: d.find_element_by_name("从相册选择")).click()
        time.sleep(1)
        WebDriverWait(dr, 5).until(lambda d: d.find_element_by_name("文件管理")).click()
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("1")).click()
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("1touxiang")).click()
        time.sleep(1)
        for i in range(random.randint(0, 80)):
            dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600))
            time.sleep(1)
        time.sleep(5)
        self.select_one_by_id("com.android.fileexplorer:id/file_image")
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("应用")).click()
        time.sleep(5)
        #保存信息按钮
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
        time.sleep(10)
        #检测信息保存完毕跳转页面
        WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(""))
        #记录帐号密码
        try:
            with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' % (self.imei, self.phone, self.pwd, time.localtime().tm_mon, time.localtime().tm_mday, time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec))
        except:
            with open('D:/brush/slave/scripts/doc/user%s.log' % self.appname_en, 'a') as f:
                f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' % (self.imei, self.phone, self.pwd, time.localtime().tm_mon, time.localtime().tm_mday, time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec))
        time.sleep(1)
        return self.do

    def do(self):
        dr = self.driver
        try:
            while self.readnum:
                print("剩下阅读次数:%s" % self.readnum)
                random_read = random.randint(0, 4)
                if random_read == 0:
                    if self.ismenu1:
                        print("goto menu1")
                        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
                        time.sleep(5)
                        return self.menu1
                    return self.do
                elif random_read == 1:
                    if self.ismenu2:
                        print("goto menu2")
                        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
                        time.sleep(5)
                        return self.menu2
                    return self.do
                elif random_read == 2:
                    if self.ismenu3:
                        print("goto menu3")
                        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
                        time.sleep(5)
                        return self.menu3
                    return self.do
                elif random_read == 3:
                    if self.ismenu4:
                        print("goto menu4")
                        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
                        time.sleep(5)
                        return self.menu4
                    return self.do
                else:
                    if self.ismenu5:
                        print("goto menu5")
                        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("")).click()
                        time.sleep(5)
                        return self.menu5
                    return self.do
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        return self.ends

    def menu1(self):
        dr = self.driver
        try:

            self.readnum -= 1
            self.ismenu1 = False
        except Exception as e:
            print("error in menu1")
            return self.exception_returnapp()
        return self.do

    def menu2(self):
        dr = self.driver
        try:

            self.readnum -= 1
            self.ismenu2 = False
        except Exception as e:
            print("error in menu2")
            return self.exception_returnapp()
        return self.do

    def menu3(self):
        dr = self.driver
        try:

            self.ismenu3 = False
        except Exception as e:
            print("error in menu3")
            return self.exception_returnapp()
        return self.do

    def menu4(self):
        dr = self.driver
        try:
            liread = [""]
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(choice(liread))).click()
            time.sleep(3)
            dr.press_keycode(4)
            time.sleep(2)
            self.ismenu4 = False
        except Exception as e:
            print("error in menu4")
            return self.exception_returnapp()
        return self.do

    def menu5(self):
        dr = self.driver
        try:
            liread = [""]
            WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(choice(liread))).click()
            time.sleep(3)
            dr.press_keycode(4)
            time.sleep(2)
            self.ismenu5 = False
        except Exception as e:
            print("error in menu5")
            return self.exception_returnapp()
        return self.do

    def ends(self):
        dr = self.driver
        #二次打开
        for x in range(random.randint(0, 1)):
            dr.press_keycode(3)
            time.sleep(1)
            dr.press_keycode(3)
            time.sleep(30)
            WebDriverWait(dr, 2).until(lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' % (time.localtime().tm_mon, time.localtime().tm_mday, self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #效率控制
        # st = [1200, 1200, 1200, 1200, 1200, 1200, 180, 120, 40, 20, 10, 10,
        #       10, 20, 20, 20, 10, 10, 5, 0, 0, 0, 0, 0]
        #
        # print("现在时间是%s:%s,脚本将在%s秒后继续执行" % (time.localtime().tm_hour, time.localtime().tm_min, st[time.localtime().tm_hour-1]))
        # time.sleep(st[time.localtime().tm_hour-1])

        return self.exit

    def uuwise(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("UUWiseDemo")).click()
        time.sleep(1)
        try:
            dr.find_element_by_name("查分")
            dr.press_keycode(4)
            time.sleep(1)
        except NoSuchElementException:
            pass
        btlogin = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/btn_login"))
        edtsuser = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/et_loginname"))
        edtspwd = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/et_loginpwd"))
        uuuser = '******'
        uupwd = 'meiriq2014'
        if edtsuser.text == uuuser and edtspwd.text == uupwd:
            pass
        else:
            edtsuser.send_keys(uuuser)
            time.sleep(1)
            edtspwd.send_keys(uupwd)
            time.sleep(1)
        btlogin.click()
        screenshotpath = dr.find_element_by_id("com.example.uuwisedemo:id/et_path")
        for x in range(10):
            screenshotpath.click()
            time.sleep(0.5)
            dr.press_keycode(123)
            time.sleep(0.5)
            for i in range(40):
                dr.press_keycode(67)
            if screenshotpath.text == "路径":
                break
        screenshotpath.send_keys('/sdcard/captcha.png')
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/btn_recognize")).click()
        time.sleep(1)
        captcha = None
        try:
            msg = WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/txt_code"))
            match = re.search(r'验证码:\d+\|([0-9a-zA-Z]+)', msg.text)
            if match:
                captcha = match.group(1)
            else:
                captcha = None
        except:
            pass
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name(self.appname)).click()
        return captcha

    #指定文档中随机获取数据
    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename, 'r', encoding='utf-8') as f:
                 strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                 strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__()-1)].strip()

    #随机滑动
    def swipes(self, x1, y1, x2, y2, swipe_num=1, swipe_time_min=1, swipe_time_max=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_min, swipe_time_max))

    #随机选择
    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(self.driver, find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            find_max = selectone.__len__()-1
        selectone[random.randint(find_min, find_max)].click()

    #出错处理
    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        try:
            WebDriverWait(dr, 2).until(lambda d: d.find_element_by_name(self.appname)).click()
        except TimeoutException:
            dr.press_keycode(4)
        time.sleep(5)
        return self.do
Esempio n. 7
0
class Machinex(Machine):
    def __init__(self, driver, code_platform, fm_uname, fm_pwd):
        super(Machinex, self).__init__(self.initdata)
        self.driver = driver
        self.code_platform = code_platform  #接码平台
        self.code_user = fm_uname  #接码平台帐号
        self.code_pwd = fm_pwd  #接码平台密码
        self.appname = "暴风体育"  #app名字
        self.appname_en = "baofeng"  #记录文件用缩写英文名
        self.imei = None
        self.runnum = None  #记录运行次数

    def initdata(self):
        self.phone = None
        self.pwd = None
        self.begintime = None
        self.endstime = None
        self.try_count = 0  #初始化出错尝试次数
        self.readnum = random.randint(2, 2)  #初始化阅读次数
        #初始化阅读菜单
        self.ismenu1 = True
        self.ismenu2 = True
        self.ismenu3 = True
        self.ismenu4 = True
        self.ismenu5 = True
        #选择初始化接码平台
        if self.code_platform == "feima":
            self.code = Feima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yama":
            self.code = Yama(self.code_user, self.code_pwd, None)
        elif self.code_platform == "yima":
            self.code = Yima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "ailezan":
            self.code = Ailezan(self.code_user, self.code_pwd, 35266)
        elif self.code_platform == "jima":
            self.code = Jima(self.code_user, self.code_pwd, None)
        elif self.code_platform == "jiuma":
            self.code = Jiuma(self.code_user, self.code_pwd, None)
        elif self.code_platform == "shenhua":
            self.code = Shenhua(self.code_user, self.code_pwd, None)

        return self.begin

    def begin(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            30).until(lambda d: d.find_element_by_name(self.appname)).click()
        time.sleep(10)
        #检测已进入app
        WebDriverWait(dr, 60).until(
            lambda d: d.find_element_by_id("com.sports.baofeng:id/tv_me"))
        self.begintime = "开始:%s:%s:%s" % (time.localtime().tm_hour,
                                          time.localtime().tm_min,
                                          time.localtime().tm_sec)
        time.sleep(1)
        #注册率
        sign_rate = random.randint(1, 10000)
        if sign_rate <= 2000:
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.sports.baofeng:id/tv_me")).click()
            time.sleep(1)
            WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id(
                "com.sports.baofeng:id/iv_baofeng_login")).click()
            time.sleep(1)
            return self.login_code_platform

        return self.do

    def login_code_platform(self):
        #登录接码平台
        print("login %s getcode ......" % self.code_platform)
        try:
            self.code.login()
        except Exception as e:
            print("error in login getcodeplatform,try_count:%s" %
                  self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                print("on try_count,exit")
                return self.exit
            return self.login_code_platform
        return self.signup

    def signup(self):
        dr = self.driver
        pwd_li = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z"
        ]
        self.pwd = ""
        for _ in range(random.randint(6, 8)):
            self.pwd += choice(pwd_li)
        try:
            #进入注册页面
            WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id(
                "com.sports.baofeng:id/user_login_reg")).click()
            time.sleep(5)
            #选择接码平台获取手机号码
            edts = WebDriverWait(
                dr, 60).until(lambda d: d.find_elements_by_class_name(
                    "android.widget.EditText"))
            self.phone = self.code.getPhone()
            #输入手机号码
            edts[0].send_keys(self.phone)
            time.sleep(1)
            #输入密码
            edts[1].send_keys(self.pwd)
            time.sleep(1)
            for i in range(3):
                screenshot("/sdcard/screenshot.png")
                # run_qpy2_script("get_captchaimg_baofeng_4c.py")
                time.sleep(1)
                dr.press_keycode(3)
                time.sleep(1)
                WebDriverWait(dr, 15).until(
                    lambda d: d.find_element_by_name("QPython")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.hipipal.qpyplus:id/whip_logo")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(
                    lambda d: d.find_element_by_name("运行脚本")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name(
                    "get_captchaimg_baofeng_4c.py")).click()
                time.sleep(5)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "android:id/action_bar_spinner")).click()
                time.sleep(1)
                WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
                    "com.hipipal.qpyplus:id/window_list_close")).click()
                time.sleep(1)
                dr.press_keycode(3)
                time.sleep(1)
                imgcaptcha = self.uuwise()
                if imgcaptcha is None:
                    print("getimgcaptcha failed")
                    self.try_count += 1
                    if self.try_count > 5:
                        self.try_count = 0
                        return self.exit
                    dr.press_keycode(4)
                    time.sleep(1)
                    return self.signup
                edts[2].send_keys(imgcaptcha)
                time.sleep(1)
                #点击获取验证码按钮
                WebDriverWait(dr, 5).until(lambda d: d.find_element_by_xpath(
                    "//android.view.View[@content-desc='免费获取验证码']")).click()
                time.sleep(1)
                try:
                    #图片验证码是否正确
                    WebDriverWait(
                        dr, 10
                    ).until(lambda d: d.find_element_by_xpath(
                        "//android.view.View[@content-desc='验证码已下发到你手机上,请查收!']"
                    ))
                    time.sleep(1)
                    break
                except TimeoutException:
                    WebDriverWait(
                        dr, 5).until(lambda d: d.find_element_by_xpath(
                            "//android.view.View[@content-desc='换一张']")).click(
                            )
                    time.sleep(5)
            #选择接码平台获取验证码
            #验证码:908511  暴风影音用户您正在进行手机号注册验证操作,请在1小时内完成,请勿泄露,如非本人操作请忽略。【暴风】
            regrex = r'验证码:(\d+)'
            captcha = self.code.waitForMessage(regrex, self.phone)
            if captcha is None:
                print("getMessage failed,try_count:%s" % self.try_count)
                #释放号码
                self.code.releasePhone(self.phone)
                self.try_count += 1
                if self.try_count > 5:
                    return self.exit
                dr.press_keycode(4)
                time.sleep(1)
                return self.signup
            #输入验证码
            edts[3].send_keys(captcha)
            time.sleep(1)
            #点击完成按钮按钮
            WebDriverWait(dr, 5).until(lambda d: d.find_element_by_xpath(
                "//android.view.View[@content-desc='注册']")).click()
            time.sleep(1)
            #检测注册成功进入下一步
            WebDriverWait(dr, 60).until(
                lambda d: d.find_element_by_id("com.sports.baofeng:id/tv_me"))
            time.sleep(1)
            #记录帐号密码
            try:
                with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f:
                    f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                            (self.imei, self.phone, self.pwd,
                             time.localtime().tm_mon, time.localtime().tm_mday,
                             time.localtime().tm_hour, time.localtime().tm_min,
                             time.localtime().tm_sec))
            except:
                with open(
                        'D:/brush/slave/scripts/doc/user%s.log' %
                        self.appname_en, 'a') as f:
                    f.write('\nimei:%s,%s,%s (time %s.%s  %s:%s:%s)' %
                            (self.imei, self.phone, self.pwd,
                             time.localtime().tm_mon, time.localtime().tm_mday,
                             time.localtime().tm_hour, time.localtime().tm_min,
                             time.localtime().tm_sec))
            time.sleep(1)
            return self.do
        except Exception as e:
            print("error in getPhone,try_count:%s" % self.try_count)
            self.try_count += 1
            if self.try_count > 5:
                return self.exit
            dr.press_keycode(4)
            time.sleep(2)
            return self.signup

    def do(self):
        dr = self.driver
        try:
            while self.readnum:
                print("剩下阅读次数:%s" % self.readnum)
                random_read = random.randint(0, 4)
                if random_read == 0:
                    if self.ismenu1:
                        print("goto menu1")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.sports.baofeng:id/tv_home")).click()
                        time.sleep(5)
                        return self.menu1
                    return self.do
                elif random_read == 1:
                    if self.ismenu2:
                        print("goto menu2")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.sports.baofeng:id/tv_live")).click()
                        time.sleep(5)
                        return self.menu2
                    return self.do
                elif random_read == 2:
                    if self.ismenu3:
                        print("goto menu3")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.sports.baofeng:id/tv_video")).click()
                        time.sleep(5)
                        return self.menu3
                    return self.do
                elif random_read == 3:
                    if self.ismenu4:
                        print("goto menu4")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.sports.baofeng:id/tv_topic")).click()
                        time.sleep(5)
                        return self.menu4
                    return self.do
                else:
                    if self.ismenu5:
                        print("goto menu5")
                        WebDriverWait(
                            dr, 15).until(lambda d: d.find_element_by_id(
                                "com.sports.baofeng:id/tv_me")).click()
                        time.sleep(5)
                        return self.menu5
                    return self.do
        except TimeoutException:
            print("查找菜单出错")
            return self.exception_returnapp()
        print("阅览完毕")
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        return self.ends

    def menu1(self):
        dr = self.driver
        try:
            for _ in range(random.randint(1, 2)):
                self.swipes(300, random.randint(800, 1000), 300,
                            random.randint(400, 600), random.randint(1, 3), 2,
                            5)
                self.select_one_by_id("com.sports.baofeng:id/tv_title")
                time.sleep(random.randint(5, 15))
                for i in range(random.randint(3, 5)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(300, 600))
                    time.sleep(random.randint(5, 10))
                #收藏
                if not random.randint(0, 4):
                    try:
                        WebDriverWait(dr,
                                      5).until(lambda d: d.find_element_by_id(
                                          "com.sports.baofeng:id/iv_collection"
                                      )).click()
                        time.sleep(1)
                    except TimeoutException:
                        pass
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
            self.readnum -= 1
            self.ismenu1 = False
        except Exception as e:
            print("error in menu1")
            return self.exception_returnapp()
        return self.do

    def menu2(self):
        dr = self.driver
        try:
            self.swipes(300, random.randint(800, 1000), 300,
                        random.randint(400, 600), random.randint(0, 3), 2, 5)
            self.ismenu2 = False
        except Exception as e:
            print("error in menu2")
            return self.exception_returnapp()
        return self.do

    def menu3(self):
        dr = self.driver
        try:
            self.swipes(300, random.randint(800, 1000), 300,
                        random.randint(400, 600), random.randint(1, 3), 2, 5)
            self.select_one_by_id("com.sports.baofeng:id/tv_title")
            time.sleep(random.randint(60, 150))
            #收藏
            if not random.randint(0, 4):
                try:
                    WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id(
                        "com.sports.baofeng:id/iv_collection")).click()
                    time.sleep(1)
                except TimeoutException:
                    pass
            dr.press_keycode(4)
            time.sleep(1)
            dr.press_keycode(4)
            time.sleep(1)
            self.readnum -= 1
            self.ismenu3 = False
        except Exception as e:
            print("error in menu3")
            return self.exception_returnapp()
        return self.do

    def menu4(self):
        dr = self.driver
        try:
            for _ in range(random.randint(2, 3)):
                self.swipes(300, random.randint(800, 1000), 300,
                            random.randint(400, 600), random.randint(1, 3), 2,
                            5)
                self.select_one_by_id("com.sports.baofeng:id/topic_title_txt")
                time.sleep(random.randint(5, 15))
                for i in range(random.randint(2, 5)):
                    dr.swipe(300, random.randint(800, 1000), 300,
                             random.randint(300, 600))
                    time.sleep(random.randint(2, 5))
                dr.press_keycode(4)
                time.sleep(1)
                dr.press_keycode(4)
                time.sleep(1)
            self.readnum -= 1
            self.ismenu4 = False
        except Exception as e:
            print("error in menu4")
            return self.exception_returnapp()
        return self.do

    def menu5(self):
        dr = self.driver
        try:
            self.ismenu5 = False
        except Exception as e:
            print("error in menu5")
            return self.exception_returnapp()
        return self.do

    def ends(self):
        dr = self.driver
        #二次打开
        for x in range(random.randint(0, 1)):
            dr.press_keycode(3)
            time.sleep(1)
            dr.press_keycode(3)
            time.sleep(30)
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
            time.sleep(1)
        #记录时间
        self.endstime = "结束:%s:%s:%s" % (time.localtime().tm_hour,
                                         time.localtime().tm_min,
                                         time.localtime().tm_sec)
        print(self.begintime)
        print(self.endstime)
        time.sleep(2)
        try:
            with open('/sdcard/1/time%s.log' % self.appname_en, 'a') as f:
                f.write('\n激活 %s.%s, %s, %s, count:%s' %
                        (time.localtime().tm_mon, time.localtime().tm_mday,
                         self.begintime, self.endstime, self.runnum))
        except:
            pass
        time.sleep(3)
        #效率控制
        # st = [1200, 1200, 1200, 1200, 1200, 1200, 180, 120, 40, 20, 10, 10,
        #       10, 20, 20, 20, 10, 10, 5, 0, 0, 0, 0, 0]
        #
        # print("现在时间是%s:%s,脚本将在%s秒后继续执行" % (time.localtime().tm_hour, time.localtime().tm_min, st[time.localtime().tm_hour-1]))
        # time.sleep(st[time.localtime().tm_hour-1])

        return self.exit

    def uuwise(self):
        dr = self.driver
        dr.press_keycode(3)
        time.sleep(1)
        WebDriverWait(
            dr,
            15).until(lambda d: d.find_element_by_name("UUWiseDemo")).click()
        time.sleep(1)
        try:
            dr.find_element_by_name("查分")
            dr.press_keycode(4)
            time.sleep(1)
        except NoSuchElementException:
            pass
        btlogin = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.example.uuwisedemo:id/btn_login"))
        edtsuser = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.example.uuwisedemo:id/et_loginname"))
        edtspwd = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.example.uuwisedemo:id/et_loginpwd"))
        uuuser = '******'
        uupwd = 'meiriq2014'
        if edtsuser.text == uuuser and edtspwd.text == uupwd:
            pass
        else:
            edtsuser.send_keys(uuuser)
            time.sleep(1)
            edtspwd.send_keys(uupwd)
            time.sleep(1)
        btlogin.click()
        time.sleep(1)
        try:
            screenshotpath = WebDriverWait(
                dr, 10).until(lambda d: d.find_element_by_id(
                    "com.example.uuwisedemo:id/et_path"))
        except TimeoutException:
            raise Exception("UU云出错")
        for x in range(10):
            screenshotpath.click()
            time.sleep(0.5)
            dr.press_keycode(123)
            time.sleep(0.5)
            for i in range(40):
                dr.press_keycode(67)
            if screenshotpath.text == "路径":
                break
        screenshotpath.send_keys('/sdcard/captcha.png')
        time.sleep(1)
        WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id(
            "com.example.uuwisedemo:id/btn_recognize")).click()
        time.sleep(1)
        captcha = None
        try:
            msg = WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id(
                "com.example.uuwisedemo:id/txt_code"))
            match = re.search(r'验证码:\d+\|([0-9a-zA-Z]+)', msg.text)
            if match:
                captcha = match.group(1)
            else:
                captcha = None
        except:
            pass
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        WebDriverWait(
            dr,
            15).until(lambda d: d.find_element_by_name(self.appname)).click()
        return captcha

    #指定文档中随机获取数据
    def get_filemessage(self, filename):
        if os.path.exists("D:/brush/slave/scripts/doc/%s" % filename):
            with open("D:/brush/slave/scripts/doc/%s" % filename,
                      'r',
                      encoding='utf-8') as f:
                strname = f.readlines()
        elif os.path.exists("/sdcard/1/%s" % filename):
            with open("/sdcard/1/%s" % filename, 'r', encoding='utf-8') as f:
                strname = f.readlines()
        else:
            strname = ""
        time.sleep(1)
        return strname[random.randint(0, strname.__len__() - 1)].strip()

    #随机滑动
    def swipes(self,
               x1,
               y1,
               x2,
               y2,
               swipe_num=1,
               swipe_time_min=1,
               swipe_time_max=1):
        dr = self.driver
        print("swipenum:%s" % swipe_num)
        for x in range(swipe_num):
            dr.swipe(x1, y1, x2, y2)
            time.sleep(random.randint(swipe_time_min, swipe_time_max))

    #随机选择
    def select_one_by_id(self, find_id, find_time=30, find_min=0, find_max=0):
        selectone = WebDriverWait(
            self.driver,
            find_time).until(lambda d: d.find_elements_by_id(find_id))
        if find_max == 0:
            find_max = selectone.__len__() - 1
        selectone[random.randint(find_min, find_max)].click()

    #出错处理
    def exception_returnapp(self):
        dr = self.driver
        print("try_count:%s" % self.try_count)
        self.try_count += 1
        if self.try_count > 5:
            return self.exit
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(4)
        time.sleep(1)
        dr.press_keycode(82)
        time.sleep(2)
        try:
            WebDriverWait(dr, 2).until(
                lambda d: d.find_element_by_name(self.appname)).click()
        except TimeoutException:
            dr.press_keycode(4)
        time.sleep(5)
        return self.do