Ejemplo n.º 1
0
    def do_action(self):
        """ Scan a specified area of the screen for an image and store the location in a variable """

        try:
            img = Image.open(self.screenshot)
        except:
            if (self.screenshot is None):
                s = "No image selected in detect image action"
            else:
                s = "Image " + self.screenshot + " Not Found."
            messagebox.showinfo("Image Not Found",
                                s,
                                parent=ToplevelObserver.top())
            return False

        width, height = img.size
        pt = imgsearch.imagesearcharea(self.screenshot,
                                       self.scanPoint.x,
                                       self.scanPoint.y,
                                       self.scanPoint.x + self.scanWidth,
                                       self.scanPoint.y + self.scanHeight,
                                       precision=(float(self.precision) /
                                                  100.0))
        point = POINT(int(pt[0] + (width / 2) + self.scanPoint.x),
                      int(pt[1] + (height / 2 + self.scanPoint.y)))
        if (pt[0] is -1):
            if (self.failOption.get() == 'Set Default Value'):
                point = self.failDefaultValue
            elif (self.failOption.get() == 'Retry'):
                timer = time.time()
                while (pt[0] is -1
                       and (time.time() - timer) < self.retryTimer):
                    pt = imgsearch.imagesearcharea(
                        self.screenshot,
                        self.scanPoint.x,
                        self.scanPoint.y,
                        self.scanPoint.x + self.scanWidth,
                        self.scanPoint.y + self.scanHeight,
                        precision=(float(self.precision) / 100.0))
                if pt[0] is -1:
                    s = "Image not found after retry, stopping."
                    messagebox.showinfo("Image Not Found",
                                        s,
                                        parent=ToplevelObserver.top())
                    return False
                point = POINT(int(pt[0] + (width / 2) + self.scanPoint.x),
                              int(pt[1] + (height / 2 + self.scanPoint.y)))
            else:
                s = "Image not found, stopping."
                messagebox.showinfo("Image Not Found",
                                    s,
                                    parent=ToplevelObserver.top())
                return False

        s = str(point.x) + " " + str(point.y)
        VariableList.set(self.storeVariable.get(), point)
        return True
Ejemplo n.º 2
0
def wait():
  startTime = datetime.now()
  im = pyautogui.screenshot(region=(610,190,120,155))

  pos = imagesearcharea(back_of_card, 610, 190, 730, 345, 0.6, im)
  print("waiting...")
  while pos[0] == -1:
    im = pyautogui.screenshot(region=(610,190,120,155))
    pos = imagesearcharea(back_of_card, 610, 190, 730, 345, 0.6, im)
  print(datetime.now() - startTime)
  return
Ejemplo n.º 3
0
def isCompTemplate(comp_image):
    comp = imagesearcharea(template("comp_template2.png"), 0, 0, 0, 0, 0.95,
                           comp_image)
    if comp[0] == -1:
        return False, comp
    else:
        return True, comp
Ejemplo n.º 4
0
def isCompWaitingForStart(comp_image):
    comp = imagesearcharea(template("waiting_for_start.png"), 0, 0, 0, 0, 0.95,
                           comp_image)
    if comp[0] == -1:
        return False, comp
    else:
        return True, comp
Ejemplo n.º 5
0
def imageSearchBaalKiller(baalPart):
    startCord = baalPart[0]
    stopCord = baalPart[1]
    region = baalPart[2]
    image = baalPart[3]
    clicked = 0
    timeSinceLastClick = 0
    # pyautogui.moveTo(region[0], region[1])
    # time.sleep(1)
    # pyautogui.moveTo(region[2], region[3])
    # time.sleep(1)
    pyautogui.click(startCord)
    while True:
        if (clicked == 50):
            break
        if (timeSinceLastClick > 50):
            pyautogui.click(stopCord)
            pyautogui.click(startCord)
            timeSinceLastClick = 0
        pos = imagesearcharea(image, region[0], region[1], region[2],
                              region[3], 0.98)
        if pos[0] != -1:
            print("position : ", pos[0], pos[1])
            # pyautogui.moveTo(pos[0], pos[1])
            pyautogui.click(startCord)
            clicked += 1
            time.sleep(0.1)
        else:
            timeSinceLastClick += 1
            print("image not found")
    pyautogui.click(stopCord)
Ejemplo n.º 6
0
def __clickWhenFound(name, x1=0, y1=0, x2=0, y2=0, precision=0.9):
    found = False
    while not found:
        pos = imagesearcharea(template(f"{name}.png"), x1, y1, x2, y2,
                              precision)
        if pos[0] != -1:
            found = True
            moveToAndClick(pos[0] + 1, pos[1] + 1)
        time.sleep(0.1)
Ejemplo n.º 7
0
def buying_empower(gold=15000):
    # Searching for empower
    empower_pos = imgs.imagesearch(tc_empower)

    # If card found
    if empower_pos[0] != -1:

        pos = imgs.imagesearcharea(image=empower_lowest_price,
                                   x1=empower_pos[0] + 350,
                                   y1=empower_pos[1],
                                   width=70,
                                   height=17,
                                   name="Test.png",
                                   precision=0.95)

        # If more than 74 empowers then click on empower
        if pos[0] != -1:
            pya.moveTo(empower_pos[0],
                       empower_pos[1],
                       duration=r.uniform(0.45, 0.75))
            t.sleep(r.uniform(0.05, 0.15))
            pya.click(empower_pos[0], empower_pos[1])

        # Buying until 74 empowers are left
        while pos[0] != -1:
            t.sleep(0.5)
            gold -= 3200
            imgs.clicking_image(buy)
            t.sleep(0.5)
            screen = pya.screenshot()
            ok_pos = imgs.imagesearch(ok, screenshot=screen)
            if ok_pos[0] != -1:
                imgs.moving_clicking_on_positions_x_y(ok_pos)
            else:
                imgs.clicking_image(buy_yes, screenshot=screen)
            t.sleep(0.5)
            pos = imgs.imagesearcharea(image=empower_lowest_price,
                                       x1=empower_pos[0] + 350,
                                       y1=empower_pos[1],
                                       width=70,
                                       height=17,
                                       name="Test.png",
                                       precision=0.95)
Ejemplo n.º 8
0
def this_is_on_screen(*given_images, x1=None, y1=None, x2=None, y2=None):

    image_found = None

    for images in given_images:
        image_path = screenshots_dir + images + '.png'
        if x1 and y1 and x2 and y2:
            pos = imagesearcharea(image_path, x1, y1, x2, y2)
        else:
            pos = imagesearch(image_path, precision=.85)

        pos = imagesearch(image_path, precision=.85)
        if pos[0] != -1:
            print("Found: " + images)
            image_found = str(images)

        else:
            print("Not Found: " + images)

    return image_found
Ejemplo n.º 9
0
def nextCompetition(direction="right"):
    i = 0
    #move cursor to the corner so it does not mess the center pics being taken
    resetCursor()
    # wait till league settings button is visible
    imagesearch_loop(template("league_settings.png"), 0.2, 0.95)
    # pick start image, it will be used to tell that we went full circle
    starting_image = region_grabber(region=(860, 440, 1050, 480))
    starting_image.save(template("tmp_league.png"))

    while True:
        imagesearch_loop(template("comp_round.png"), 0.1, 0.95)
        image = pyautogui.screenshot()
        # ignore first competition as it is the starting one
        if i > 1:
            comp = imagesearcharea(template("tmp_league.png"), 0, 0, 0, 0,
                                   0.999, image)
            if comp[0] != -1:
                break

        yield image
        i += 1
        right_arrow = imagesearch(template(f"{direction}.png"))
        moveToAndClick(right_arrow[0] + 10, right_arrow[1] + 10)
Ejemplo n.º 10
0
def scanTeams(compname, teams=[]):
    clickWhenActive("new_season")

    # navigate to input
    inp = imagesearch_loop(template("new_season_comp_name_input.png"), 0.1,
                           0.99)
    moveToAndClick(inp[0] + 10, inp[1] + 10)
    # clear it
    for _ in range(0, 24):
        pyautogui.press("backspace")

    #pyautogui.typewrite(compname)
    keyboard.type(compname)
    time.sleep(1)

    clickYes()
    inp = imagesearch_loop(template("comp_created_msg.png"), 0.1, 0.9)

    for team in teams:
        # navigate to teams
        clickWhenActive("teams_button")

        #wait till rendered
        found = False
        while not found:
            left_arrow = imagesearcharea(template("small_left.png"), 0, 0, 500,
                                         500, 0.9)
            if left_arrow[0] != -1:
                found = True
        #        moveToAndClick(left_arrow[0]+1,left_arrow[1]+1)
            time.sleep(0.1)

        team_input = imagesearch(template("enter_team_name_text.PNG"), 0.99)
        coach_input = imagesearch(template("enter_coach_name_text.PNG"), 0.99)

        coach, teamname = team["coach"], team["team"]
        # fill the coach/team info while in member section

        moveToAndClick(team_input[0] + 320, team_input[1])
        keyboard.type(f"%{teamname}"[0:25])
        time.sleep(1.1)
        moveToAndClick(coach_input[0] + 320, coach_input[1])
        keyboard.type(coach)
        time.sleep(1.1)
        # navigate to All
        clickSmallLeft()

        # moving left to All initiates the search
        # search with coach is fast but lets wait 2 seconds just in case
        time.sleep(2)

        # look for no result or invite button
        found = False

        while not found:
            time.sleep(0.1)
            no_result = imagesearch(template("no_result_text.PNG"), 0.99)
            invite = imagesearcharea(template("invite_team_button.PNG"), 0, 0,
                                     900, 600, 0.99)

            if no_result[0] != -1:
                found = True
                #exit team loop
                print(f"Not Found: {coach}: {teamname}")
            elif invite[0] != -1:
                found = True
                print(f"Found: {coach}: {teamname}")

        # naviagte to schedule to clear the inputs
        clickWhenActive("schedule_button")
Ejemplo n.º 11
0
def createComp(compname, teams=[]):
    clickWhenActive("new_season")

    # navigate to input
    inp = imagesearch_loop(template("new_season_comp_name_input.png"), 0.1,
                           0.99)
    moveToAndClick(inp[0] + 10, inp[1] + 10)
    # clear it
    for _ in range(0, 24):
        pyautogui.press("backspace")

    keyboard.type(compname)
    time.sleep(1)

    clickYes()
    inp = imagesearch_loop(template("comp_created_msg.png"), 0.1, 0.9)
    logging.info(f"Competition {compname} created")
    for team in teams:
        # navigate to teams
        clickWhenActive("teams_button")

        #wait till rendered
        found = False
        i = 0
        while not found:
            left_arrow = imagesearcharea(template("small_left.png"), 0, 0, 500,
                                         500, 0.9)
            if left_arrow[0] != -1:
                found = True
        #        moveToAndClick(left_arrow[0]+1,left_arrow[1]+1)
            time.sleep(0.1)
            i += 1
            # sometimes the click is interupted by BB, if we do not get anything in 3 seconds then try it again
            if i == 30 and not found:
                clickWhenActive("teams_button")
                i = 0

        team_input = imagesearch(template("enter_team_name_text.PNG"), 0.99)
        coach_input = imagesearch(template("enter_coach_name_text.PNG"), 0.99)

        coach, teamname = team["coach"], team["team"]
        # fill the coach/team info while in member section

        moveToAndClick(team_input[0] + 320, team_input[1])
        keyboard.type(f"%{teamname}"[0:25])
        time.sleep(1.1)
        moveToAndClick(coach_input[0] + 320, coach_input[1])
        keyboard.type(coach)
        time.sleep(1.1)
        # navigate to All
        clickSmallLeft()

        # moving left to All initiates the search
        # search with coach is fast but lets wait 2 seconds just in case
        # time.sleep(2)

        # look for no result or invite button
        found = False

        i = 0
        while not found:
            time.sleep(0.1)
            #no_result = imagesearch(template("no_result_text.PNG"), 0.99)
            invite = imagesearcharea(template("invite_team_button.PNG"), 0, 0,
                                     900, 550, 0.99)
            invite2 = imagesearcharea(template("invite_team_button.PNG"), 900,
                                      470, 1100, 550, 0.99)

            if invite[0] != -1:
                found = True
                # mutliple teams found
                if invite2[0] != -1:
                    logging.error(
                        f"Found multiple teams for coach {coach} and team {teamname}"
                    )
                    break
                logging.info(
                    f"Found team for coach {coach} and team {teamname}")
                pyautogui.moveTo(invite[0] + 10, invite[1] + 5)
                ns = imagesearch_loop(
                    template("invite_team_button_active.png"), 0.1, 0.99)
                moveToAndClick(ns[0] + 10, ns[1] + 5)
                ticket = imagesearch_loop(template("ticket_sent_msg.png"), 0.1,
                                          0.9)
                logging.info(f"Ticket sent")
                while ticket[0] != -1:
                    ticket = imagesearch(template("ticket_sent_msg.png"), 0.9)

            else:
                i += 1

            if i == 50:
                logging.error(
                    f"Team not found for coach {coach} and team {teamname}")
                break

        # naviagte to schedule to clear the inputs
        clickWhenActive("schedule_button")
Ejemplo n.º 12
0
pos = imagesearch("github.png", prefix="assets/img/")
if pos[0] != -1:
    print("position : ", pos[0], pos[1])
    pyautogui.moveTo(pos[0], pos[1])
else:
    print("image not found")

# search for the github logo continuously :
# pos = imagesearch_loop("github.png", 0.5, prefix="assets/img/")

print("image found ", pos[0], pos[1])

# search for the logo on the 0,0,800,600 region
#  (a rectangle starting from the top left going 800 pixels to the right and down 600 pixels)

pos = imagesearcharea("github.png", 0, 0, 800, 600, prefix="assets/img/")
if pos[0] != -1:
    print("position : ", pos[0], pos[1])
    pyautogui.moveTo(pos[0], pos[1])
else:
    print("image not found")

# the im parameter is usefull if you plan on looking for several different images without the need for recapturing the screen
# the screen capture being one of the most time consuming function it's a good way to optimize

# non -optimized way :
time1 = time.clock()
for i in range(10):
    imagesearcharea("github.png", 0, 0, 800, 600, prefix="assets/img/")
    imagesearcharea("panda.png", 0, 0, 800, 600, prefix="assets/img/")
print(str(time.clock() - time1) + " seconds (non optimized)")
Ejemplo n.º 13
0
    def __init__(self):
        self.tiempo_de_espera_minutos = Value('i', 0)

    def retornar_cronometro(self):
        return self.tiempo_de_espera_minutos.value

    # Este método siempre se debe de ejecutar a través de un subproceso
    def comenzar_cronometro(self, tiempo_de_espera_minutos):
        self.tiempo_de_espera_minutos.value = tiempo_de_espera_minutos
        print("comienza a correr cronometro")
        time.sleep(int(tiempo_de_espera_minutos) * 60)
        self.tiempo_de_espera_minutos.value = 0


'''
click on the center of an image with a bit of random.
eg, if an image is 100*100 with an offset of 5 it may click at 52,50 the first time and then 55,53 etc
Usefull to avoid anti-bot monitoring while staying precise.
this function doesn't search for the image, it's only ment for easy clicking on the images.
input :
image : path to the image file (see opencv imread for supported types)
pos : array containing the position of the top left corner of the image [x,y]
action : button of the mouse to activate : "left" "right" "middle", see pyautogui.click documentation for more info
time : time taken for the mouse to move from where it was to the new position
'''

if __name__ == "__main__":
    imagen_ver_compra = imagesearcharea("imagen_ver_compra.jpg", 1130, 690,
                                        1250, 770)
    print(imagen_ver_compra)