Esempio n. 1
0
def click_next():
    """Scroll down and click 'nastepna' to go to next page.

    Site feature 'nastepna' come in two shades of blue depending on number of pages already browsed.
    It changes to darker blue after ca. 200.
    If neither is visible, clicks 'go back' button, moves cursor over result page and recursively calls itself.

    Raises
    ------
        If recursion limit is exhausted RecursionError is raised. This enables main.py module to recalibrate program.
    """
    pyautogui.scroll(-7000)
    if pyautogui.locateOnScreen(IMG_NASTEPNA_1,
                                2,
                                grayscale=True,
                                region=(0, 0.5 * HEIGHT, WIDTH, HEIGHT)):
        try_click_image(IMG_NASTEPNA_1)
    elif pyautogui.locateOnScreen(IMG_NASTEPNA_2,
                                  2,
                                  grayscale=True,
                                  region=(0, 0.5 * HEIGHT, WIDTH, HEIGHT)):
        try_click_image(IMG_NASTEPNA_2)
    elif pyautogui.locateOnScreen(IMG_NASTEPNA_3,
                                  2,
                                  grayscale=True,
                                  region=(0, 0.5 * HEIGHT, WIDTH, HEIGHT)):
        try_click_image(IMG_NASTEPNA_3)
    else:
        try_click_image(IMG_BREAK)
        try_click_image(IMG_BACK)
        pyautogui.move(0, 50, duration=5)
        click_next()
Esempio n. 2
0
def set_strony():
    """Set number of pages browsed by downloading to 1.

    Clicks at location 'numer ostatniej strony' and moves 20 pixels beneath to the combo box.
    Activates the box, deletes whatever is in it and types '1' to ensure browsing of 1 page at a time.
    """
    try_click_image(IMG_NROSTAT)
    pyautogui.move(0, 20)
    pyautogui.click()
    pyautogui.press('delete', presses=5)
    pyautogui.typewrite('1')
Esempio n. 3
0
def click_start():
    """Click 'Start' button to start downloading results.

    Waits 30 secs until 'Start' button is visible in inactive mode (black) and clicks it.
    If the button is not visible after 30 secs, clicks 'back' button, as this usually unfreezes page hung by loading.
    Then function recursively calls itself.

    Raises
    ------
        If recursion limit is exhausted RecursionError is raised. This enables main.py module to recalibrate program.
    """
    if pyautogui.locateOnScreen(IMG_START_BLACK,
                                30,
                                grayscale=True,
                                region=(0, 0, 0.5 * WIDTH, 0.3 * HEIGHT)):
        try_click_image(IMG_START_BLACK)
    else:
        try_click_image(IMG_BACK)
        click_start()
Esempio n. 4
0
def actively_check_list_site():
    """Waits until results page is visible.

    If the site is not visible after 15 secs, clicks 'back' button, as this usually unfreezes page hung by loading.
    Then moves cursor beneath 'back' button and scrolls up in case it landed at the bottom of page.
    Then function recursively calls itself.

    Raises
    ------
        If recursion limit is exhausted RecursionError is raised. This enables main.py module to recalibrate program.
    """
    if pyautogui.locateOnScreen(IMG_LISTA,
                                10,
                                grayscale=True,
                                region=(0, 0, 0.5 * WIDTH, 0.3 * HEIGHT)):
        try_click_image(IMG_LISTA)
    else:
        pyautogui.move(0, 200)
        pyautogui.click()
        pyautogui.scroll(7000)
        if pyautogui.locateOnScreen(IMG_LISTA,
                                    10,
                                    grayscale=True,
                                    region=(0, 0, 0.5 * WIDTH, 0.3 * HEIGHT)):
            try_click_image(IMG_LISTA)
        else:
            try_click_image(IMG_BACK)
            actively_check_list_site()
Esempio n. 5
0
def click_back_n_times():
    """Click 'go back' button once plus once per each results page loaded during download.

    Clicking 'go back' once is always needed to return from start page to results page.
    For every downloaded results another time of 'go back' is needed to reach results page.
    Function uses recognize_number() to identify number of results downloaded and computes sum of 'go backs'.

    Returns
    -------
        int: Number of new results. This is then used by BrowsingReport class for running total of downloads.
    """
    new = recognize_number()
    n_times = new + 1
    if pyautogui.locateOnScreen(IMG_WYSZUKIWARKA_2,
                                grayscale=True,
                                region=(0, 0, 0.5 * WIDTH, 0.2 * HEIGHT)):
        try_click_image(IMG_BACK, clicks=n_times, interval=0.5)
        pyautogui.move(0, 100, duration=1)
    else:
        try_click_image(IMG_WYSZUKIWARKA_1)
        click_back_n_times()
    return new
Esempio n. 6
0
def switch_window_when_done():
    """Wait until downloading is done and click at location 'Wyszukiwarka' to switch back to searching tab.

    Function takes 2 secs to move cursor, which creates delay before locateOnScreen() takes screen shot.
    Otherwise screen shot is often made before downloading starts, so the function fires to soon.
    Downloading usually takes up to 20 secs, however freezes occur frequently, so function calls itself recursively.

    Raises
    ------
        If recursion limit is exhausted RecursionError is raised. This enables main.py module to recalibrate program.
    """
    # time.sleep(1)
    # if pyautogui.locateOnScreen(IMG_NOWE_DONE, grayscale=True, region=(0, 0, 0.5*WIDTH, 0.2*HEIGHT)):
    #     time.sleep(1)
    #     if pyautogui.locateOnScreen(IMG_NOWE_DONE, grayscale=True, region=(0, 0, 0.5*WIDTH, 0.2*HEIGHT)):
    #         if pyautogui.locateOnScreen(IMG_WYSZUKIWARKA_1, grayscale=True, region=(0, 0, 0.2 * WIDTH, 0.2 * HEIGHT)):
    #             try_click_image(IMG_WYSZUKIWARKA_1)
    #         else:
    #             try_click_image(IMG_WYSZUKIWARKA_2)
    # else:
    #     switch_window_when_done()

    # v2
    time.sleep(2)
    if pyautogui.locateOnScreen(IMG_START_GRAY,
                                grayscale=True,
                                region=(0, 0, 0.5 * WIDTH, 0.2 * HEIGHT)):
        if pyautogui.locateOnScreen(IMG_NOWE_DONE,
                                    grayscale=True,
                                    region=(0, 0, 0.5 * WIDTH, 0.2 * HEIGHT)):
            if pyautogui.locateOnScreen(IMG_WYSZUKIWARKA_1,
                                        grayscale=True,
                                        region=(0, 0, 0.2 * WIDTH,
                                                0.2 * HEIGHT)):
                try_click_image(IMG_WYSZUKIWARKA_1)
            else:
                try_click_image(IMG_WYSZUKIWARKA_2)
    else:
        switch_window_when_done()
Esempio n. 7
0
def click_flag():
    if pyautogui.locateOnScreen(IMG_flag_CAeast, 2, grayscale=True, region=(0.5 * WIDTH, 0, WIDTH, HEIGHT)):
        try_click_image(IMG_flag_CAeast)
Esempio n. 8
0
def click_status_and_search():
    """Click location 'Status' on start page, scroll down and click 'Szukaj'."""
    try_click_image(IMG_STATUS)
    pyautogui.scroll(-7000)
    try_click_image(IMG_SZUKAJ)
Esempio n. 9
0
def click_stop_if_not_done():
    if pyautogui.locateOnScreen(IMG_STOP,
                                2,
                                grayscale=True,
                                region=(0, 0, 0.5 * WIDTH, 0.3 * HEIGHT)):
        try_click_image(IMG_STOP)