def play_audio(self, item, title): print(f'点开了视频《{title}》') get_duration = lambda: utils.get_text(self.driver, item + '/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView') or \ utils.get_text(self.driver, item + '/android.view.ViewGroup/android.widget.LinearLayout[2]/android.widget.TextView') duration_text = get_duration() if not duration_text: utils.swipe_up(self.driver) duration_text = get_duration() duration_text = duration_text.split(':') duration = int(duration_text[0]) * 60 + int(duration_text[1]) print(f'这个视频要看:{duration}秒') utils.click(self.driver, item) while True: start = time.time() time.sleep(1) self.wait(duration) dots = 1 replay = '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout' while not utils.find_element(self.driver, replay): print('再等会' + dots * '.', end='\r', flush=True) dots = max((dots + 1) % 6, 1) time.sleep(1) print('视频放完了') self.audiuo_time -= time.time() - start if self.audio_counter == 1 and self.audiuo_time > 0: print(f'虽然视频看完了,但是还剩下{int(self.audiuo_time)}秒,所以重看一次') time.sleep(random.uniform(0.8, 1.8)) if utils.click(self.driver, replay): self.wait(duration) else: break self.audio_counter -= 1 self.audio.append(title) print(f'看完惹,还有{self.audio_counter}个要看') self.driver.back()
def authorize(self, login, password): self.driver.get('https://www.shasso.com/sso/login?action=login') self.driver.find_element_by_id('loginform-customers_email_address').send_keys(login) self.driver.find_element_by_id('loginform-customers_password').send_keys(password) time.sleep(0.5) click(self.driver, self.driver.find_element_by_xpath("//button[text()='Login']"))
def active_orders(self, region='eu', active_status = True): logging.info(f'[{dt.datetime.now().isoformat()}] Started parsing active orders. Region: {region}') orders = [] try: # create set of files that are currently in the directory current_xls_files = {file for file in os.listdir(DEFAULT_DOWNLOAD_DIRECTORY) if file.endswith('.xls')} if region == 'eu': url = 'https://www.g2g.com/sell/manage?service=1&game=2522&type=1' else: url = 'https://www.g2g.com/sell/manage?service=1&game=2299&type=1' self.driver.get(url) enable_download_headless(self.driver, DEFAULT_DOWNLOAD_DIRECTORY) click(self.driver, self.driver.find_element_by_partial_link_text('Download List')) time.sleep(3) new_file_name = {file for file in os.listdir(DEFAULT_DOWNLOAD_DIRECTORY) if file.endswith('.xls') and file not in current_xls_files}.pop() new_file_path = os.path.join(DEFAULT_DOWNLOAD_DIRECTORY, new_file_name) orders = orders_from_excel(new_file_path, just_active=active_status) os.remove(new_file_path) except Exception as e: logging.info(f'[{dt.datetime.now().isoformat()}] Error parsing active orders: ' + str(e)) logging.info(f'[{dt.datetime.now().isoformat()}] Parsed active orders successfully. Return {len(orders)} orders') return orders
def change_field(text): wait_element(self.driver, '//span[@class="editable-clear-x"]', timeout=2) click(self.driver, self.driver.find_element_by_class_name('editable-clear-x')) random_sleep() self.driver.find_element_by_class_name('input-large').send_keys(str(text)) click(self.driver, self.driver.find_element_by_xpath("//button[@class='btn btn--green editable-submit']")) random_sleep(delay=0.5)
def test_edit_category(self): click(self.browser, '//a[text()="Edit"][1]', '//h3[text()="Edit category"]') cost_input = self.browser.find_element_by_xpath('//input[@name="category_name"]') cost_input.clear() cost_input.send_keys('edited test category') click(self.browser, '//button[text()="Edit"]', '//h3[text()="Edit category"]') time.sleep(2) # No idea why this is necessary. self.assertTrue(exists_by_xpath(self.browser, '//tr[1]//td[text()="Edited test category"]'))
def left_panel(): utils.click(3, 70, 11, 24, 3.0) # open left panel screen = adb.screenshot() Btn.menu_can.click(screen) # tap can Btn.menu_money.click(screen) # tap money send_commission() log("Commissions done")
def subscribe(self): print('开始订阅') utils.click(self.driver, 'cn.xuexi.android:id/comm_head_xuexi_mine') utils.click(self.driver, 'cn.xuexi.android:id/my_subscribe_tv') utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.TextView[2]' ) time.sleep(2) tmp = 'tmp.png' while self.subscription_counter: element = utils.find_element( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v4.view.ViewPager/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.widget.ImageView' ) element.save_screenshot(tmp) if utils.compare_images(tmp, 'checked.png'): utils.swipe_up(self.driver, y_ratio=5 / 9) if utils.find_element( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v4.view.ViewPager/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView' ): print('看到底线了') utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.support.v7.app.ActionBar.Tab[2]/android.widget.TextView' ) else: if utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v4.view.ViewPager/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]' ): self.subscription_counter -= 1 print(f'订阅了:{utils.get_text(self.driver, "")}')
def swap(): for _ in range(8): before = adb.screenshot() if not Btn.switch.on_screen(before): log("ERROR: Failed to switch, button not on screen") return before = utils.screen_face() # get portrait utils.click(497, 334, 34, 7, 1.0) after = utils.screen_face() if img.mean_square(before, after) > 0.001: return time.sleep(1.5) log("ERROR: Failed to switch, more than 8 try's")
def perform(self): perform_buttons = self._driver.find_elements_by_css_selector('.action-bar > .openTask.btn') for button in perform_buttons: task_window = click(self._driver, button) if not task_window: continue self._driver.switch_to.window(task_window) task_url = self._driver.current_url task_performed = self._perform_task() if task_performed: sleep(TaskPagePerformer.after_perform_rollback_delay_s) if self.__is_captcha_required(): self.__solve_captcha() self._driver.close() self._driver.switch_to.window(self.__main_window) sleep(randrange(TaskPagePerformer.before_rollback_delay_min_s, TaskPagePerformer.before_rollback_delay_max_s, 1)) task_window = open_new_window(self._driver, task_url) self._driver.switch_to.window(task_window) self._rollback() if self.__is_captcha_required(): self.__solve_captcha() sleep(TaskPagePerformer.after_perform_rollback_delay_s) self._driver.close() self._driver.switch_to.window(self.__main_window) print(self.__get_scores()) sleep(TaskPagePerformer.perform_interval_s)
def play_video(self, item): title = utils.get_text( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.TextView' ) print(f'点开了视频《{title}》') duration = utils.get_text( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[2]/android.widget.TextView' ) duration_text = duration.split(' / ')[1].split(':') duration = int(duration_text[0]) * 60 + int(duration_text[1]) print(f'这个视频要看:{duration}秒') utils.click(self.driver, item) self.wait(duration) self.audiuo_time -= duration
def send_best_commission(oil: bool, max_time: int) -> bool: if Btn.commission_0.on_screen(utils.screenshot()): # check if we have fleets return False for _ in range(2): # swipe to bottom utils.scroll_down() time.sleep(2.0) screen = utils.screenshot() # make screenshots screen_hd = adb.screenshot_hd_gray() commission_buttons = img.find_zones(utils.screenshot(), Img.commission, 0.9) best_x, best_y, best_time = -1, -1, max_time for x, y, w, h in commission_buttons: # check oil has_oil = Btn.commission_oil.on_screen(screen[y - 30 : y + 20, x + 129 : x + 400]) if oil != has_oil: continue # check time time_img = screen_hd[y * 3 + 2 * 3 : y * 3 + 13 * 3, x * 3 + 66 * 3 : x * 3 + 107 * 3] time_num = parse_time(time_img) if time_num > max_time: continue # remember best commission if time_num < best_time: best_time = time_num best_x, best_y = x, y if best_time >= max_time: return False # start commission utils.click(best_x, best_y, 45, 13, 3.0) send_girl() Btn.commission_recommend.click(adb.screenshot()) Btn.commission_ready.click(adb.screenshot()) Btn.universal_confirm.click(adb.screenshot()) # check if commission started time.sleep(6.0) has_cancel = Btn.commission_cancel.on_screen(utils.screenshot()) # close commission window utils.click(63, 327, 18, 25, 1.0) return has_cancel
def start_lab_image(btn: Clickable): for _ in range(5): if btn.on_screen(adb.screenshot()): utils.click(301, 92, 36, 34, 2.0) # open project if Btn.tech_terminate.on_screen(adb.screenshot()): return True if Btn.commence.click(adb.screenshot()): if Btn.universal_confirm.click(adb.screenshot()): if Btn.tech_terminate.on_screen(adb.screenshot()): return True else: utils.click(445, 77, 38, 52, 0.5) # close project else: utils.click(445, 77, 38, 52, 0.5) # close project return False utils.click(445, 77, 38, 52, 0.5) # next project utils.click(445, 77, 38, 52, 1.5) # close project return False
def test_deleting_expense(self): self.browser.get(SLATE_URL) # We want to verify that this expense is deleted. add_expense(self.browser, '7.50', 'Food (out)', 'Burrito') self.browser.get('%s/account/settings' % SLATE_URL) click(self.browser, '//tr//td[text()="Food (out)"]/..//a[text()="Edit"]') click(self.browser, '//input[@value="Delete"]', '//h3[text()="Edit category"]') self.browser.switch_to.alert.accept() self.browser.get(SLATE_URL) select = Select( wait_until(self.browser, '//select[@name="category_id"]') ) for option in select.options: self.assertTrue(option.text != 'Food (out)') self.browser.get('%s/expenses' % SLATE_URL) self.assertFalse( exists_by_xpath(self.browser, '//td[text()="Food (out)"]') )
def teleport(text): print("teleport", text) try: call, prev = wrapper(teleport, text), useful['mapid'] app.send_keystrokes('h') if cond_wait(1.5, 2.5, ('mapid', prev, 5, call)): return print("enter haven bag", useful['mapid']) click(173, offx=-10, offy=-10) sleep(uniform(2.5, 3.5)) click(134, offy=-10) sleep(uniform(2, 2.5)) app.send_keystrokes(text + '{ENTER}', with_spaces=True) if cond_wait(3, 5, ('mapid', 162793472, 5, call)): return except RuntimeError: sleep(uniform(3, 5)) teleport(text) print("done teleport")
def collect(rsc, farmer_exception, e=None, out=False): count, lc = 7, useful['mypos'] if out: e = get_current_node(2) app.send_keystrokes('{VK_SHIFT DOWN}') for c in order([ x['elementCellId'] if x['enabledSkill'] not in farmer_exception else x['elementCellId'] - 28 for x in useful['resources'].values() if x['enabledSkill'] in rsc ]): count, s = count + 3, str(c) try: click(c, offx=e[s]['xoffset'] + 2, offy=e[s]['yoffset'], alt=e[s]['altitude'], first=first) except: pass print("error in collect", c, useful['mapid'], useful['mypos'], e) count, lc = count + 3, c return count, int(lc)
def learn_book(): utils.click(3, 70, 11, 24, 2.0) # open left panel utils.click(200, 207, 41, 10, 2.0) log("Completing books") while Btn.universal_confirm.click(adb.screenshot()): points = find_green() if len(points) == 0: log("ERROR: books not found") break x, y = random.choice(points) utils.click(x, y, 10, 10, 2.0) utils.click(558, 302, 40, 14, 2.0) if Btn.universal_confirm.click(adb.screenshot()): log("Learning started") log("Books done")
def start_lab(): utils.click(3, 70, 11, 24, 2.0) # open left panel while not Btn.technology.on_screen(adb.screenshot()): # open lab utils.click(212, 277, 19, 11, 1.0) utils.click(301, 92, 36, 34, 2.0) # click center if Btn.tech_terminate.on_screen(adb.screenshot()): return utils.click(445, 77, 38, 52, 0.5) # close project for btn in [ Btn.lab_girl, Btn.tech_rigging, Btn.tech_donation, Btn.tech_basic ]: if start_lab_image(btn): break
def begin_battle() -> bool: if not MODE_FIGHT: # enable auto in auto mode for auto in [Btn.auto, Btn.auto_sub]: auto.click(utils.screenshot()) # enable auto # use heals if not Btn.zero_heals.on_screen(utils.screenshot()): utils.click(47, 255, 25, 25, 2.0) Btn.use_heal.click(utils.screenshot()) Btn.cancel_heal.click(utils.screenshot()) # Check mood screen = utils.screenshot() if Btn.mood.on_screen(screen): log("Ships in bad mood. Wait 60 min") utils.warn("mood", screen) time.sleep(60 * 60) log("Continue") return False Btn.battle.click(utils.screenshot()) # begin battle if Btn.enhance_start.click(utils.screenshot()): menu.enhance_ships() for i in range(2): adb.back() time.sleep(1.5) return begin_battle() if Btn.battle.on_screen(utils.screenshot()): # check if battle started return False if MODE_FIGHT: fight() else: log("Waiting 30s") time.sleep(30.0) return True
def automate(process_name, first_step=1, last_step=100): processDir = r'C:\AlessandroBAM\2017m01 - Abbott DPE-PgM-PM\CIC Brazil\Automation\Processes' autoDir = os.path.join(processDir, process_name) files = [] for r, d, f in os.walk(os.path.join(processDir, process_name)): for file in f: files.append(file) for f in files: i = getIndex(f) # print(first_step) # print(last_step) if i >= first_step and i <= last_step: x_offset = getArgument(f, "x") y_offset = getArgument(f, "y") sleep = getArgument(f, "s") # print("index: " + str(getIndex(f)) + " X_offset: " + str(x_offset) + " Y_offset: " + str(y_offset) + " sleep: " + str(sleep) + " File Name: " + f) if not isOptional(f): r = utils.waitUntil(os.path.join(autoDir, f)) else: r = utils.waitUntil(os.path.join(autoDir, f), attempts=5) print("optional: " + f) if r != False: if not isWait(f): utils.click(r, x_offset, y_offset) else: time.sleep(sleep) print(r) else: if not isOptional(f): msgbox("Error", "Automation failed. File not found: " + f, 0) sys.exit()
def retire_ships(): def sort_rare(show_rare: bool): utils.click(556, 7, 32, 12, 2.5) # click sort while True: is_rare = adb.screenshot(False)[700, 920, 0] > 160 # check button color if show_rare == is_rare: # check if needed state break utils.click(318, 226, 31, 8, 1.5) # click rare utils.click(372, 318, 55, 7, 2.5) # click confirm utils.click(491, 336, 55, 16, 3.0) # click build if not Btn.retire_button.click(utils.screenshot()): # click retire log("ERROR: Retire not found!") return sort_rare(True) # no ships if Btn.retire_nothing.on_screen(adb.screenshot()): log("Nothing to retire") sort_rare(False) # disable sorting return # select ships for x in range(7): utils.click(54 + x * 82, 56, 54, 50, 0.3) if Btn.universal_confirm.click(adb.screenshot()): # click confirm if Btn.universal_confirm.click(adb.screenshot()): # confirm retire if Btn.item.click(adb.screenshot()): # accept items if Btn.universal_confirm.click( adb.screenshot()): # confirm disassemble if Btn.enhance_break.click( utils.screenshot()): # press disassemble Btn.item.click(adb.screenshot()) # accept items sort_rare(False)
def sort_rare(show_rare: bool): utils.click(556, 7, 32, 12, 2.5) # click sort while True: is_rare = adb.screenshot(False)[700, 920, 0] > 160 # check button color if show_rare == is_rare: # check if needed state break utils.click(318, 226, 31, 8, 1.5) # click rare utils.click(372, 318, 55, 7, 2.5) # click confirm
def after_level(use_lab: bool): utils.click_home() # go to main menu log("Removing trash") utils.click(87, 332, 74, 24, 3.0) # open dock enhance_ships() utils.click_home() # go to main menu log("Retiring trash") retire_ships() log("Collecting oil") utils.click_home() # go to main menu left_panel() if use_lab: log("Starting labs") utils.click_home() # go to main menu start_lab() utils.click_home() # go to main menu learn_book() utils.click_home() # go to main menu log("Done!")
def enhance_ships(): Btn.sort.click(utils.screenshot()) if adb.screenshot(False)[820, 1144, 2] > 100: utils.click(384, 260, 57, 14, 1.0) Btn.universal_confirm.click(adb.screenshot()) utils.click(49, 53, 63, 56, 3.0) # click first ship Btn.enhance.click(utils.screenshot()) no_enhance = 0 while True: # click enhance if Btn.enhance.on_screen(utils.screenshot()): utils.click(483, 302, 58, 19, 0.5) # press fill button utils.click(567, 302, 58, 19, 2.0) # press enhance button if Btn.universal_confirm.click(adb.screenshot()): # press confirm no_enhance = 0 if Btn.enhance_break.click( utils.screenshot()): # press disassemble utils.click(434, 244, 164, 97, 2.0) # tap to continue else: # something went wrong log("No break button!") else: no_enhance += 1 else: no_enhance += 10 log("No enhance button!") if no_enhance >= 4: # stop if we can't enhance 4 times break adb.swipe( # swipe to next ship random.randint(900, 966), random.randint(501, 558), random.randint(210, 276), random.randint(501, 558)) time.sleep(1.0)
def getClickPositionButton(self, btn): pause = self.app.getEntry("Delay(s)") if (btn == "Capture Click Position"): self.storedXpos = self.xpos self.storedYpos = self.ypos self.app.setLabel( "Click Position", "X:" + str(self.storedXpos) + ",Y:" + str(self.storedYpos)) elif (btn == "Save Click Position"): x, y = self.app.getLabel("Click Position").split(',') self.commandList.append("Click on position X:{} Y:{}".format( x[2:], y[2:])) self.pythonCommands.append(utils.click(x[2:], y[2:], pause)) self.writeCommands()
def run(self): while True: try: self.connect() time.sleep(6) # Splash Screen utils.swipe_left(self.driver, y_ratio=3 / 4) print('开始读要闻') while self.artical_counter: while self.artical_counter: item = f'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.support.v4.view.ViewPager/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.FrameLayout[1]/android.widget.LinearLayout' title = utils.get_text( self.driver, item + '/android.widget.TextView') if title and title not in self.articles: self.read_article(item, title) else: utils.swipe_up(self.driver, y_ratio=5 / 9) while not utils.click( self.driver, '//android.widget.FrameLayout[@content-desc="电视台"]/android.widget.RelativeLayout' ): time.sleep(1) print('开始看视频') while self.audio_counter: while self.audio_counter: item = f'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.support.v4.view.ViewPager/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.FrameLayout[1]/android.widget.LinearLayout' title = utils.get_text( self.driver, item + '/android.widget.LinearLayout/android.widget.TextView' ) or utils.get_text( self.driver, item + '/android.view.ViewGroup/android.widget.TextView') if title and title not in self.audio: self.play_audio(item, title) else: utils.swipe_up(self.driver, y_ratio=5 / 9) # self.subscribe() print('搞定啦~') break except KeyboardInterrupt: break except Exception as e: print('Exception:', e) finally: self.driver.quit()
def deactivate(): try: click(self.driver, self.driver.find_element_by_id('check-all')) except: # No inactive orders return for span in self.driver.find_elements_by_class_name('manage__action-text'): if 'deactivate' in span.text.lower(): click(self.driver, span) break time.sleep(1) click(self.driver, self.driver.find_element_by_xpath("//button[@class='btn btn--green product-action-page']"))
def send_girl(): utils.click(121, 159, 27, 24, 3.0) # click first plus for _ in range(3): # swipe to bottom utils.scroll_down() for y in range(3): for x in range(7): utils.click(60 + 84 * x, 60 + 114 * y, 40, 10, 2.0) Btn.commission_select_cancel.click(adb.screenshot()) if not Btn.commission_select_0.on_screen(adb.screenshot()): utils.click(535, 328, 60, 14, 2.0) return adb.back() time.sleep(2.0)
def add_order(self, order: Order, price: float): logging.info(f'[{dt.datetime.now().isoformat()}] Add order: [{order}] with price {price}') self.driver.get('https://www.g2g.com/sell/index') try: trade_selection = Select(self.driver.find_element_by_xpath('//select[@id="service"]')) trade_selection.select_by_value('1') wait_element(self.driver, '//select[@id="game"]') random_sleep(delay=0.3) game_selection = Select(self.driver.find_element_by_xpath('//select[@id="game"]')) game_selection.select_by_visible_text( f'World Of Warcraft ({order.region.upper()})' ) wait_element(self.driver, "//h3[contains(text(), 'Product Details')]") random_sleep(delay=0.3) # ------------------------------------------------------------------------------------------ server_selection = Select(self.driver.find_element_by_xpath("//select[@id='server']")) server_selection.select_by_visible_text(order.server) random_sleep() faction_selection = Select(self.driver.find_element_by_xpath("//select[@id='faction']")) faction_selection.select_by_visible_text(order.faction) random_sleep() self.driver.find_element_by_id('C2cProductsListing_products_description').send_keys(order.description) currency_selection = Select(self.driver.find_element_by_xpath( "//select[contains(@id, 'products_base_currency')]")) currency_selection.select_by_value(order.currency.upper()) random_sleep() self.driver.find_element_by_xpath("//input[@id='C2cProductsListing_products_price']") \ .send_keys(str(price)) random_sleep() self.driver.find_element_by_xpath("//input[@id='C2cProductsListing_forecast_quantity']") \ .send_keys(str(order.stock)) random_sleep() self.driver.find_element_by_xpath("//input[@id='C2cProductsListing_minimum_quantity']") \ .send_keys(str(order.min_unit_per_order)) random_sleep() delivery_widget = self.driver.find_element_by_class_name('create__action-delivery') for span in delivery_widget.find_elements_by_class_name('create__action-duration'): if span.text.lower() in order.delivery_option.lower(): click(self.driver, span.find_element_by_tag_name('input')) random_sleep(delay=-0.05) online_hrs_selection = Select(self.driver.find_element_by_xpath( "//select[@id='C2cProductsListing_online_hr']" )) online_hrs_selection.select_by_value(str(order.online_hrs)) random_sleep() offline_hrs_selection = Select(self.driver.find_element_by_xpath( "//select[@id='C2cProductsListing_offline_hr']" )) offline_hrs_selection.select_by_value(str(order.offline_hrs)) random_sleep() click(self.driver, self.driver.find_element_by_xpath("//button[contains(text(), 'Submit')]")) except Exception as e: logging.info(f'[{dt.datetime.now().isoformat()}] Error adding order: ' + str(e))
def test_cancelling_edit(self): click(self.browser, '//a[text()="Edit"][1]', '//h3[text()="Edit category"]') click(self.browser, '//a[text()="Cancel"]', '//h2[text()="Settings"]') self.assertTrue(exists_by_xpath(self.browser, '//tr[1]//td[text()="Alcohol"]'))
def fight(): start_time, last_enemy_time, sub_used = -1.0, -1.0, False last_player = None while True: screen = adb.screenshot(False) frame = frame_recognition.process_frame(screen) # start time counting if frame.auto_button and start_time < 0: start_time = time.time() last_enemy_time = start_time # level finished if not frame.auto_button and check_end(): adb.release() log(f"Level finished in {time.time() - start_time:.2f}s") return # auto mode need? target_auto = True if frame.barrage_button: target_auto = False # change mode if frame.auto_button != target_auto: utils.click(3, 15, 73, 15, 0) adb.release() continue # no control in auto mode if not target_auto or (last_player is None and frame.player is None): continue # launch submarine 5 seconds after start # if time.time() - start_time > 5.0 and not sub_used: # sub_used = True # utils.click(354, 295, 27, 25, 0) # adb.release() # pressing buttons # only if we have enemys or don't have them for 5 seconds if len(frame.enemys) > 0 or time.time() - last_enemy_time > 5.0: last_enemy_time = time.time() if frame.air_button: utils.click(428, 296, 25, 25, 0) adb.release() # player searching if frame.player is None: player_x, player_y = last_player else: player_x, player_y = frame.player last_player = frame.player enemy_y = -1 # pressing torpedoes if frame.torp_button and player_x > 650: utils.click(500, 296, 25, 25, 0) adb.release() # finding best enemy best_x = 100000 if len(frame.bombs) > 0: # bombs always best best_dst = 100000 for x, y in frame.bombs: dst = abs(player_y - y) if dst < best_dst: best_dst = dst enemy_y = y elif len(frame.enemys) > 0: # normal enemys - second target for x, y in frame.enemys: if x < best_x: best_x = x enemy_y = y else: # didn't found enemy, go to center enemy_y = 1080 // 2 # move to enemy y move_y = (enemy_y - player_y) / 300.0 move_x = 0.4 if player_x < 400 or frame.player is None else -0.2 # move forward if no enemys if len(frame.enemys) == 0 or best_x > 1500: move_x = 0.4 if player_x < 850 or frame.player is None else -0.2 # move faster if we have bomb ships or torpedoes ready if len(frame.bombs) > 0 or frame.torp_button: move_y = (enemy_y - player_y) / 100.0 move_x = 0.6 # make a move move_y = float(np.clip(move_y, -1.0, 1.0)) move(move_x, move_y)
def send_commission(): clicked_complete = False utils.click(200, 135, 42, 12, 2.0) # click commissions while Btn.commission_s.click(utils.screenshot()): clicked_complete = True if clicked_complete: utils.click(200, 135, 42, 12, 2.0) # click go if Btn.commission_0.on_screen(utils.screenshot()): log("0 fleets") return log("Starting urgent commissions oil") utils.click(11, 114, 28, 25, 3.0) while send_best_commission(True, 40000): pass if Btn.commission_0.on_screen(utils.screenshot()): log("0 fleets") return log("Starting daily commissions oil") utils.click(12, 63, 30, 30, 3.0) while send_best_commission(True, 40000): pass if Btn.commission_0.on_screen(utils.screenshot()): log("0 fleets") return log("Starting urgent commissions") utils.click(11, 114, 28, 25, 3.0) while send_best_commission(False, 29000): pass if Btn.commission_0.on_screen(utils.screenshot()): log("0 fleets") return log("Starting daily commissions") utils.click(12, 63, 30, 30, 3.0) while send_best_commission(False, 22000): pass if Btn.commission_0.on_screen(utils.screenshot()): log("0 fleets") return
def read_article(self, item, title): print(f'点开了文章《{title}》') utils.click(self.driver, item) while self.collect_counter: print(f'点击收藏') # 收藏 self.collect_counter -= utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView[1]' ) time.sleep(random.uniform(0.8, 1.8)) # 可能会有”我知道了“的提示 utils.click(self.driver, 'cn.xuexi.android:id/btn_right_text') time.sleep(random.uniform(0.8, 1.8)) # 取消收藏 print(f'取消收藏') utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView[1]' ) time.sleep(random.uniform(0.8, 1.8)) while self.share_counter: print('点击分享') utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView[2]' ) time.sleep(random.uniform(0.8, 1.8)) # 分享到微信 if utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.support.v4.view.ViewPager/android.widget.GridView/android.widget.RelativeLayout[2]/android.widget.ImageView' ): # 双开微信? utils.click( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.ListView/android.widget.LinearLayout/android.widget.LinearLayout[1]' ) self.share_counter -= 1 self.driver.back() print('开始阅读') while True: read_time = random.uniform(3, 6) time.sleep(read_time) print(f'读了{round(read_time, 2)}秒', end='\r', flush=True) self.article_time -= read_time # 观点 if utils.find_element( self.driver, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.TextView' ): print('看到评论区了,那就可以不读了') if self.artical_counter == 1 and self.article_time > 0: read_time = random.uniform(self.article_time, self.article_time + 2) print( f'读完了,但距离完成任务还有{round(self.article_time, 2)}秒,所以随便等个{round(read_time, 2)}秒' ) self.wait(read_time) break else: utils.swipe_up(self.driver) self.artical_counter -= 1 self.articles.append(title) print(f'读完惹,还有{self.artical_counter}篇要读') self.driver.back()
def run(): if not MODE_SKIP: menu.after_level(MODE_LAB) # free space & collect oil first clear_count, battle_count = 0, 0 nothing_start = 0.0 is_nothing, clicked_boss = False, False target_team, attacked_fleet = True, False fight_started = False ship_face = utils.screen_face() while True: screen = utils.screenshot() # after fight if fight_started: if Btn.switch.on_screen(screen): # fight finished fight_started = False log(f"Fight finished ({battle_count+1}/{MODE_BOSS})") time.sleep(6.0) battle_count += 1 if battle_count % MODE_SWAP == 0: target_team = not target_team # change fleets log("Swap") continue elif clicked_boss and ( Btn.level_name.on_screen(screen) or Btn.event_name.on_screen(screen)): # level finished fight_started = False log(f"Boss killed ({clear_count+1}/2)") clear_count += 1 battle_count = 0 if clear_count % 2 == 0: menu.after_level(MODE_LAB) continue else: # wait utils.do_nothing() continue if Btn.battle.on_screen(screen): is_nothing = False if not begin_battle(): menu.after_level(MODE_LAB) attacked_fleet = True else: fight_started = True continue # click go (for swap on start) if Btn.go1.click(screen): is_nothing = False utils.screenshot() if MODE_STARTSWAP: swap() continue # level selection if Btn.archives.on_screen(screen): is_nothing = False if MODE_EVENT: utils.click(587, 80, 31, 29, 5.0) else: if Btn.level_name.click( screen): # level on screen, no need to search continue for _ in range(15): # go to right world utils.click(605, 181, 9, 13, 0.25) time.sleep(6.0) # wait for warnings disappear for _ in range(14): # go back until level found if Btn.level_name.click(utils.screenshot()): break utils.click(25, 178, 6, 17, 3.0) continue elif MODE_EVENT and Btn.event_name.click(screen): is_nothing = False continue # on map if Btn.switch.on_screen(screen): is_nothing = False if battle_count == 0: # first battle, remember face target_team = True ship_face = utils.screen_face() else: # not first, ensure face right swap_team(ship_face, target_team) if attacked_fleet: # in fight, returned from menu attacked_fleet = False utils.click(583, 332, 39, 12, 2.0) # just click attack continue clicked_boss = False state = "none" if battle_count >= MODE_BOSS: state = click_boss() if state == "boss": clicked_boss = True if state == "none": if not click_enemy(): # try click ships log("Ships not found") Btn.retreat.click(utils.screenshot()) battle_count = 0 else: # nothing to do if not is_nothing: nothing_start = time.time() is_nothing = True log("Nothing to do") elif time.time() - nothing_start > 60 * 5: utils.warn("nothing", screen) log("Nothing to do for 5 minutes") is_nothing = False utils.restart_game() else: utils.do_nothing()