def mongo_web_interface(target,port=28017,creds=False,enableScreen=False): try: url = 'http://'+target+':'+str(port) code = requests.get(url) if code.status_code == 200 and code.content.find('mongo')!=-1 and code.content.find('db version')!=-1: print colored("\n[+] MongoDB web management open at " + url + ". No authentication required!",'blue') rest_url=url+'/buildInfo?text=1' testrest=requests.get(rest_url) if testrest.content.find('not enabled')!=-1: print colored("\n[-] REST Interface Not enabled",'red') else: print colored("\n[+] REST Interface Enabled URL: "+rest_url,'green') if enableScreen: screenshot(url,creds) elif code.status_code==401: print colored("[-] MongoDB web management Open at " + url + ". Authentication required!",'blue') print colored("[-] Try Supplying credentials using the Auth option",'blue') print colored("[-] Do you Want to Take a ScreenShot of the Page (y/n)",'yellow') choice=raw_input() if enableScreen: screenshot(url,creds) else: pass else: print colored("[-] Web Interface Not Open",'red') except Exception,e: print str(e)
def detect_info() -> bool: time.sleep(1.0) has_unable = False zone = utils.screenshot()[143 : 143 + 40, 192 : 192 + 60] while Btn.unable_info.on_screen(zone): time.sleep(0.5) zone = utils.screenshot()[143 : 143 + 40, 192 : 192 + 60] has_unable = True return has_unable
def test_login(self, username, password, code, expect): """登录""" logging.info('username={} password={} code={} expect={}'.format( username, password, code, expect)) print("test_login start...") try: # 登录 self.login_proxy.login(username, password, code) # 断言 time.sleep(3) self.assertIn(expect, self.driver.title) except Exception as e: utils.screenshot(self) logging.exception(e) raise
def create_recipe_img(): x, y, w, h = recipe_instruction_coords screenshot_path = screenshot(x=x, y=y, w=w, h=h) img = Image.open(screenshot_path) recipe_name = ocr_recipe_name(recipe_name_coords, img) os.rename(screenshot_path, recipe_img_path + recipe_name + '.png')
def run(viewBase64): # Load input images. screen = utils.screenshot() screen=utils.bgr2gray(screen) view = utils.base64_to_cv2(viewBase64) view=utils.bgr2gray(view) screen=utils.resize(screen) view=utils.resize(view) h, w = screen.shape[0:2] # print(view.shape) # Project view centroid to screen space. # x and y are the coordinate of the `view` centroid in `screen` space. try: x, y,im = screenpoint.project(view, screen,True) cv2.imwrite('screenpoint.jpg',im) return { "x":x/w, "y":y/h } except IOError: print(IOError) return None else: print('error') return None
def __init__(self): screen = utils.get_current_monitor() self.WIDTH, self.HEIGHT = screen.width, screen.height - 10 self.ZOOMED_WIDTH, self.ZOOMED_HEIGHT = self.WIDTH, self.HEIGHT self.screenshot_x = self.screenshot_y = 0 self.stroke_size = 3 self.max_stroke_size = 30 self.saved_zoomed_frames = [] self.current_zoom_frame_index = -1 self.screenshot = utils.screenshot(bbox=screen.bbox, all_screens=True) self.screenshot = utils.img_to_surf(self.screenshot) os.environ['SDL_VIDEO_WINDOW_POS'] = '{},{}'.format( screen.x, screen.y + 10) self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT)) self.draw_surface = pygame.Surface((self.WIDTH, self.HEIGHT)) self.draw_surface = self.draw_surface.convert_alpha(self.draw_surface) self.information_surface = pygame.Surface( (self.WIDTH // 16, self.HEIGHT // 16)) self.information_surface = self.information_surface.convert_alpha( self.information_surface) pygame.display.set_caption("ScreenDrawer") pygame.display.set_icon(pygame.image.load("./assets/icons/icon.png"))
def wait_for_battle(seconds: float) -> bool: log(f"Waiting max {seconds}s") end_time = time.time() + seconds while end_time > time.time(): time.sleep(0.5) if not Btn.switch.on_screen(utils.screenshot()): return True return False
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 find_recipe(): x, y, w, h = recipe_instruction_coords screenshot_path = screenshot(x=x, y=y, h=h, w=w) current_recipe = Image.open(screenshot_path) # current_recipe = crop_screenshot(img_path=screenshot_path, coords=recipe_instruction_coords) recipes_imgs = os.listdir(recipe_img_path) for recipe in recipes_imgs: if compare_imgs(current_recipe, Image.open(recipe_img_path + recipe)): if recipe.endswith('.png'): return recipes[recipe[:-4]], recipe[:-4] return recipes[recipe], recipe
def imgur_capture_screen(creds, sleep=0, admin=False): """ Captures the screen after (optionally) sleeping for some number of seconds and uploads it to imgur. If admin is set to true (that is, if you're admin!) Returns the imgur link. """ time.sleep(sleep) if admin: tempdir = tempfile.mkdtemp() fname = utils.screenshot(tempdir, "screencap.png") else: fname = utils.screenshot("./", "screencap.png") link = imgur_upload_image(fname, creds) if admin: shutil.rmtree(tempdir) else: os.remove(fname) return link
def test_tic_tac_toe(setup): buttons = setup["driver"].find_elements_by_class_name("square") number_of_games = int(setup["number_of_games"]) new_game_button = setup["driver"].find_element_by_class_name( "button.button--new-game") game_number = 1 while number_of_games >= game_number: if util.tai_checker(setup, buttons, new_game_button, game_number): util.screenshot(setup, game_number) game_number += 1 continue button_number = random.randint(0, 8) if util.slot_checker(buttons, button_number): continue util.choose_slot(buttons, button_number) if util.winner_checker(setup, new_game_button, game_number): util.screenshot(setup, game_number) game_number += 1 continue
def main(): d = getDateTime() # Global app app = QApplication(sys.argv) QApplication.setQuitOnLastWindowClosed(False) qIcon = QIcon('icons/shotty.png') app.setWindowIcon(qIcon) shotty = ShottyFullscreen() showNotification('Shotty', 'Running in the background') tray = QSystemTrayIcon() if tray.isSystemTrayAvailable(): tray.setIcon(QIcon('icons/shotty.png')) tray.setVisible(True) tray.show() # Add a menu trayMenu = QMenu() region_screenshot_action = QAction(QIcon("icons/screenshot.png"), 'Take region screenshot') full_screenshot_action = QAction(QIcon("icons/screenshot.png"), 'Take screenshot') settings_action = QAction(QIcon("icons/settings.png"), 'Settings') about_action = QAction(QIcon("icons/info.png"), 'About') exit_action = QAction(QIcon("icons/exit.png"), 'Exit Shoty') exit_action.triggered.connect(app.exit) about_action.triggered.connect(shotty.showShottyAboutWindow) region_screenshot_action.triggered.connect(shotty.initUI) # We need to pass checked because connect passes # a bool arg as first param full_screenshot_action.triggered.connect( lambda checked, date=getDateTime( ), x1=-1, y1=-1, x2=-1, y2=-1, im=screenshot( ): shotty.saveScreenShot(date, x1, y1, x2, y2, im=im[:, :, :3])) trayMenu.addAction(region_screenshot_action) trayMenu.addAction(full_screenshot_action) trayMenu.addAction(settings_action) trayMenu.addAction(about_action) trayMenu.addAction(exit_action) tray.setContextMenu(trayMenu) else: print("[ERROR] Can't instantiate tray icon") sys.exit(app.exec_())
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 initUI(self): global displayed QSound.play("sounds/shutter.wav") self.pressed = False QApplication.setOverrideCursor(Qt.CrossCursor) # Create widget self.l_imFullscreen = QLabel(self) self.l_mousePos = QLabel(self) self.l_dimensions = QLabel(self) font = QFont("Calibri", 15) self.l_dimensions.setFont(font) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showFullscreenshotMenu) self.setTextLabelPosition(0, 0) setMouseTracking(self, True) self.rect_x1 = self.rect_y1 = self.rect_x2 = \ self.rect_y2 = self.line_x = self.line_y = 0 im = screenshot() # Remove alpha self.im = removeAlpha(im) h, w, c = self.im.shape print('New shape: {},{},{}'.format(h, w, c)) qImg = QImage(self.im, w, h, QImage.Format_RGB888).rgbSwapped() pixmap = QPixmap.fromImage(qImg) self.l_imFullscreen.setPixmap(pixmap) self.l_imFullscreen.resize(pixmap.width(), pixmap.height()) self.overlay = overlay(self.l_imFullscreen) self.overlay.resize(pixmap.width(), pixmap.height()) print("Overlay size: {}, {}".format( self.overlay.frameGeometry().width(), self.overlay.frameGeometry().height())) setMouseTracking(self, True) monitor = QDesktopWidget().screenGeometry(-1) self.move(monitor.left(), monitor.top()) displayed = True self.showFullScreen()
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 test_logged_in_user_can_open_the_profile_page(self): return text = "" perform_login(self.driver) # Todo Javascript action fails in selenium headless # self.driver.execute_script("arguments[0].click();", # self.driver.find_element_by_xpath("//div[@class='container text-1 ']/div[@class='col-md-4 col-sm-6'][1]/ul/li[1]/a")) self.driver.get(self.url.rstrip("/") + "/courses/labprofile") try: w = WebDriverWait(self.driver, 10) w.until( EC.text_to_be_present_in_element_value( (By.XPATH, "//div[@class='display-tc animate-box h1-bg']/h1"), "Lab Profile")) text = self.driver.find_element_by_xpath( "//div[@class='display-tc animate-box h1-bg']/h1").text except NoSuchElementException as e: print("Ex: {}".format(e)) screenshot(self.driver, "test_logged_in_user_can_open_the_profile_page") self.assertTrue("Profile" in text, "Profile Page not reached")
def mongo_web_interface(target, port=28017, creds=False, enableScreen=False): try: url = 'http://' + target + ':' + str(port) code = requests.get(url) if code.status_code == 200 and code.content.find( 'mongo') != -1 and code.content.find('db version') != -1: print colored( "\n[+] MongoDB web management open at " + url + ". No authentication required!", 'blue') rest_url = url + '/buildInfo?text=1' testrest = requests.get(rest_url) if testrest.content.find('not enabled') != -1: print colored("\n[-] REST Interface Not enabled", 'red') else: print colored("\n[+] REST Interface Enabled URL: " + rest_url, 'green') if enableScreen: screenshot(url, creds) elif code.status_code == 401: print colored( "[-] MongoDB web management Open at " + url + ". Authentication required!", 'blue') print colored( "[-] Try Supplying credentials using the Auth option", 'blue') print colored( "[-] Do you Want to Take a ScreenShot of the Page (y/n)", 'yellow') choice = raw_input() if enableScreen: screenshot(url, creds) else: pass else: print colored("[-] Web Interface Not Open", 'red') except Exception, e: print str(e)
def find_active_number(order_numbers): # x, y, w, h = recipe_instruction_coords # screenshot_path = screenshot(x=x, y=y, h=h, w=w) for num in order_numbers: if not num[ 'in_use']: # in use means we're currently cooking food on that order number x, y, h, w = num['coords'] screenshot_path = screenshot(x=x, y=y, h=h, w=w) # img = crop_screenshot(img_path=screenshot_path, # coords=num['coords']) img = Image.open(screenshot_path) same_img = compare_imgs(img, Image.open(num['path2img'])) if same_img: print(f'thread: {threading.get_ident()} doing number %s' % str(num)) return num
def click_boss() -> str: log(f"Searching boss") for sw in swipes: sw() # swipe in some direction time.sleep(1.0) click_question() screen = utils.screenshot() for boss_pic in [Img.boss, Img.boss2, Img.boss_mini]: boss_point = img.find_best(screen, boss_pic, 0.7) if boss_point is not None: boss_point = boss_point[0] + boss_pic.shape[1] // 2, boss_point[1] + boss_pic.shape[0] // 2 break else: continue x, y = boss_point point = None for _ in range(2): # 2 click try's point = enemy_finder.get_safe_point(x * 3, y * 3) if point is None: continue bx, by = point log(f"Tap boss [{bx}, {by}]") adb.tap(bx, by) if detect_info(): # don't try second click break if wait_for_battle(8.0): # success if switch disappeared return "boss" if point is None: # don't attack ships if boss not clickable continue # failed log(f"Searching ships near boss") ships = [] screen = adb.screenshot(False) for yellow in [True, False]: ships.extend(enemy_finder.find_triangles(screen, yellow)) sort_near(ships, (x * 3, y * 3)) # ships near boss if tap_ships(ships): return "ship" return "none"
def click_enemy() -> bool: log("Searching ships") for yellow in [True, False]: for sw in swipes: sw() # swipe in some direction time.sleep(1.0) click_question() screen = utils.screenshot() # click buttons ships = enemy_finder.find_triangles(adb.screenshot(False), yellow) player_point = img.find_best(screen, Img.arrow, 0.95) # if we find player go near player if player_point is not None: px, py = player_point sort_near(ships, (px * 3, (py + 70) * 3)) # player 70 pixels bellow arrow if tap_ships(ships): return True return False
def click_question(clicks_before: int = 0): screen = utils.screenshot() zones = img.find_zones(screen, Img.question0, 0.8) zones.extend(img.find_zones(screen, Img.question1, 0.8)) for x, y, w, h in zones: x, y = x + w / 2, y + h / 2 + 30 point = enemy_finder.get_safe_point(int(x) * 3, int(y) * 3) if point is None: continue x, y = point log(f"Click question [{x}, {y}]") adb.tap(x, y) if detect_info(): continue time.sleep(7.0) if clicks_before < 4: click_question(clicks_before + 1) 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 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 shot_settings_base(logged_in_client, full_testdata): logged_in_client.go_to("office:settings.base") screenshot(logged_in_client, "office_settings_base.png")
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()
def shot_dashboard(logged_in_client, full_testdata): logged_in_client.go_to("office:dashboard") screenshot(logged_in_client, "office_dashboard.png")
def shot_member_list(logged_in_client, full_testdata): logged_in_client.go_to("office:members.list") screenshot(logged_in_client, "office_members_list.png")
def shot_login(client): client.go_to("common:login") screenshot(client, "common_login.png")
def check_end() -> bool: screen = utils.screenshot() return Btn.confirm.on_screen(screen)
def shot_settings_about(logged_in_client, full_testdata): logged_in_client.go_to("office:settings.about") screenshot(logged_in_client, "office_settings_about.png")
def shot_settings_registration(logged_in_client, full_testdata): logged_in_client.go_to("office:settings.registration") screenshot(logged_in_client, "office_settings_registration.png")