def in_article(self, i): self._reader.in_article(self._article_list_res, i) sleep() self._operator.click_resource_if_exist(self._article_read_res) sleep() self._operator.click_resource_if_exist( self._article_advertise_close_res)
def watch_adv(self): sleep(35) while not self._operator.is_resource_exists( 'com.jm.video:id/tt_video_ad_close'): sleep(1) self._operator.click_resource_if_exist( 'com.jm.video:id/tt_video_ad_close')
def click_position(self, x, y): try: print('Click position: ', x, y) self._d.click(x, y) sleep() return True except Exception as e: print('Click position failed' + str(e)) return False
def out_article(self): print( self._operator.get_resource_text( 'com.martian.ttbook:id/duration_bonus')) self._operator.go_back() sleep() # self._operator.click_resource_if_exist(self._article_save_to_shell_res) # time.sleep(3) while 0 == self.get_article_list_length(): self._operator.go_back() sleep()
def click_xpath_if_exist(self, xpath, timeout=2): if self._d.xpath(xpath).exists: try: print('Click xpath: ', xpath) self._d.xpath(xpath).click(timeout=timeout) sleep() return True except Exception as e: print('Click xpath failed' + str(e)) return False else: print('XPath %s not exist' % xpath) return False
def click_resource_if_exist(self, resource_id, timeout=2): if self.is_resource_exists(resource_id): try: print('Click resource: ', resource_id) self._d(resourceId=resource_id).click(timeout=timeout) sleep() return True except Exception as e: print('Click resource failed' + str(e)) return False else: print('Resource %s not exist' % resource_id) return False
def sign(self): self._operator.click_resource_if_exist(self._btn_me) # self._operator.click_xpath_if_exist( # '//*[@resource-id="com.yyk.whenchat:id/vInvite"]/android.widget.ImageView[1]') self._operator.click_xpath_if_exist('//*[@text="邀请赚钱"]') self._operator.click_position(0.500, 0.880) # self._operator.click_xpath_if_exist('//*[@text="立即邀请"]') while not self._operator.is_resource_exists('com.tencent.mm:id/ln'): self._operator.click_xpath_if_exist( '//*[@resource-id="com.yyk.whenchat:id/gvBody"]/android.widget.LinearLayout[1]/android.widget.ImageView[1]' ) sleep(30) self._operator.go_back() return True
def watch_adv(self): while True: try: self._d.xpath('//*[@text="看视频赚海量金币"]').click() break except Exception as e: print('Click resource failed' + str(e)) count = 0 while not self._operator.is_resource_exists( 'com.ss.android.ugc.livelite:id/rk'): sleep(5) count += 1 if count > 8: self._operator.click_xpath_if_exist('//*[@text="关闭广告"]') return self._operator.click_resource_if_exist( 'com.ss.android.ugc.livelite:id/rk')
def start_app(self, app_id): print("Starting app %s ..." % app_id) self._d.app_start(app_id) sleep(60) print("App %s ... is started." % app_id)
def close_all_app(self): print("Closing all apps...") self._d.app_stop_all(excludes=['com.github.uiautomator']) self._d.app_stop_all(excludes=['com.github.uiautomator']) sleep() print("All apps are closed.")
def go_back(self): self._d.press("back") sleep()
def in_article(self, i): if self._reader.in_article(self._article_list_res, i): sleep() return True else: return False
def watch_adv(self): while not self._operator.is_xpath_exist('//*[@text="关闭广告"]'): sleep() if self._operator.is_resource_exists(self._btn_continue_adv): self._operator.click_resource_if_exist(self._btn_continue_adv) self._operator.click_xpath_if_exist('//*[@text="关闭广告"]')
self._wanqia_success = self._wanqia.wanqia() def stop_all_apps(self): self._operator.close_all_app() if __name__ == '__main__': device_id = 'JGB9K17A18908832' d = u2.connect_usb(device_id) task = Task(d) wanqia_success = False while True: if 0 < get_hour() < 7: if get_minute() < 20: task.exec_wanqia() sleep(60) continue if get_minute() < 10: task.exec_douyin() elif get_minute() < 20: task.exec_shuabao() if get_minute() < 40: task.exec_douyin() elif get_minute() < 50: task.exec_shuabao() # elif get_minute() < 30: # task.exec_qutoutiao() else: task.stop_all_apps() sleep(100) continue
def next_article_list(self): self.page_up() sleep()