How to use the instapy.util.update_activity function in instapy

To help you get started, we’ve selected a few instapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
follow_button_XP = read_xpath(get_following_status.__name__, "follow_button_XP")
    except NoSuchElementException:
        try:
            follow_button = browser.find_element_by_xpath(
                read_xpath(get_following_status.__name__, "follow_span_XP_following")
            )
            return "Following", follow_button
        except:
            return "UNAVAILABLE", None
    follow_button = explicit_wait(
        browser, "VOEL", [follow_button_XP, "XPath"], logger, 7, False
    )

    if not follow_button:
        browser.execute_script("location.reload()")
        update_activity(browser, state=None)

        follow_button = explicit_wait(
            browser, "VOEL", [follow_button_XP, "XPath"], logger, 14, False
        )
        if not follow_button:
            # cannot find the any of the expected buttons
            logger.error(failure_msg.format(person.encode("utf-8")))
            return None, None

    # get follow status
    following_status = follow_button.text

    return following_status, follow_button
github Instagram-Tools / bot / instapy / print_log_writer.py View on Github external
"""Prints and logs the current number of followers to
    a seperate file"""
    user_link = "https://www.instagram.com/{}".format(username)
    web_address_navigator(browser, user_link)

    try:
        following_num = browser.execute_script(
            "return window._sharedData."
            "entry_data.ProfilePage[0]."
            "graphql.user.edge_follow.count"
        )

    except WebDriverException:
        try:
            browser.execute_script("location.reload()")
            update_activity(browser, state=None)

            sleep(10)
            following_num = browser.execute_script(
                "return window._sharedData."
                "entry_data.ProfilePage[0]."
                "graphql.user.edge_follow.count"
            )

        except WebDriverException:
            following_num = None

    with open("{}followingNum.txt".format(logfolder), "a") as numFile:
        numFile.write(
            "{:%Y-%m-%d %H:%M} {}\n".format(datetime.now(), following_num or 0)
        )
github Instagram-Tools / bot / instapy / comment_util.py View on Github external
def is_commenting_enabled(browser, logger):
    """ Find out if commenting on the post is enabled """

    try:
        comments_disabled = browser.execute_script(
            "return window._sharedData.entry_data."
            "PostPage[0].graphql.shortcode_media.comments_disabled")

    except WebDriverException:
        try:
            browser.execute_script("location.reload()")
            update_activity()

            comments_disabled = browser.execute_script(
                "return window._sharedData.entry_data."
                "PostPage[0].graphql.shortcode_media.comments_disabled")

        except Exception as e:
            msg = ("Failed to check comments' status for verification!\n\t{}"
                   .format(str(e).encode("utf-8")))
            return False, "Failure"

    if comments_disabled is True:
        msg = "Comments are disabled for this post."
        return False, msg

    return True, "Success"
github Instagram-Tools / bot / instapy / commenters_util.py View on Github external
print(
                    "Few likes, not guaranteed you don't follow these"
                    " likers already.\nGot photo likers: {}\n".format(likers)
                )
                return likers

        else:
            print("Couldn't find liked counter button. May be a video.")
            print("Moving on..")
            return []

        sleep(1)
        click_element(browser, element_to_click)
        print("opening likes")
        # update server calls
        update_activity(browser, state=None)

        sleep(1)

        # get a reference to the 'Likes' dialog box
        dialog = browser.find_element_by_xpath(
            read_xpath("class_selectors", "likes_dialog_body_xpath")
        )

        # scroll down the page
        previous_len = -1
        browser.execute_script(
            "arguments[0].scrollTop = arguments[0].scrollHeight", dialog
        )
        update_activity(browser, state=None)
        sleep(1)
github Instagram-Tools / bot / instapy / login_util.py View on Github external
for _ in range(2):
        update_activity(browser, state=None)

    submit_security_code_button = browser.find_element_by_xpath(
        read_xpath(bypass_suspicious_login.__name__, "submit_security_code_button")
    )

    (
        ActionChains(browser)
        .move_to_element(submit_security_code_button)
        .click()
        .perform()
    )

    # update server calls
    update_activity(browser, state=None)

    try:
        sleep(3)
        # locate wrong security code message
        wrong_login = browser.find_element_by_xpath(
            read_xpath(bypass_suspicious_login.__name__, "wrong_login")
        )

        if wrong_login is not None:
            wrong_login_msg = (
                "Wrong security code! Please check the code Instagram"
                "sent you and try again."
            )
            update_activity(
                browser,
                action=None,
github Instagram-Tools / bot / instapy / login_util.py View on Github external
# collect isitdownorjust.me website information
        website_status = browser.find_element_by_xpath(
            read_xpath(login_user.__name__, "website_status")
        )
        response_time = browser.find_element_by_xpath(
            read_xpath(login_user.__name__, "response_time")
        )
        response_code = browser.find_element_by_xpath(
            read_xpath(login_user.__name__, "response_code")
        )

        logger.info("- Instagram WebSite Status: {} ".format(website_status.text))
        logger.info("- Instagram Response Time: {} ".format(response_time.text))
        logger.info("- Instagram Reponse Code: {}".format(response_code.text))
        logger.info("- Instagram Server Status: ok")
        update_activity(
            browser,
            action=None,
            state="Instagram servers are running correctly",
            logfolder=logfolder,
            logger=logger,
        )
    except Exception:
        logger.warn("- Instagram Server Status: error")
        update_activity(
            browser,
            action=None,
            state="Instagram server is down",
            logfolder=logfolder,
            logger=logger,
        )
        return False
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
else:
                logger.warning(
                    "--> Couldn't unfollow '{}'!\t~unexpected failure".format(person)
                )
                return False, "unexpected failure"
    elif track == "dialog":
        # Method of unfollowing from a dialog box

        click_element(browser, button)
        sleep(4)  # TODO: use explicit wait here
        confirm_unfollow(browser)

    # general tasks after a successful unfollow
    logger.info("--> Unfollowed '{}'!".format(person))
    Event().unfollowed(person)
    update_activity(
        browser, action="unfollows", state=None, logfolder=logfolder, logger=logger
    )
    post_unfollow_cleanup(
        "successful", username, person, relationship_data, person_id, logger, logfolder
    )

    # get the post-unfollow delay time to sleep
    naply = get_action_delay("unfollow")
    sleep(naply)

    return True, "success"
github Instagram-Tools / bot / instapy / like_util.py View on Github external
try_again = 0
    sc_rolled = 0
    nap = 1.5
    put_sleep = 0
    try:
        while filtered_links in range(1, amount):
            if sc_rolled > 100:
                logger.info("Scrolled too much! ~ sleeping a bit :>")
                sleep(600)
                sc_rolled = 0

            for i in range(3):
                browser.execute_script(
                    "window.scrollTo(0, document.body.scrollHeight);"
                )
                update_activity(browser, state=None)
                sc_rolled += 1
                sleep(nap)  # if not slept, and internet speed is low,
                # instagram will only scroll one time, instead of many times
                # you sent scoll command...

            sleep(3)
            links.extend(get_links(browser, tag, logger, media, main_elem))

            links_all = links  # uniqify links while preserving order
            s = set()
            links = []
            for i in links_all:
                if i not in s:
                    s.add(i)
                    links.append(i)