How to use instapy - 10 common examples

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 / like_util.py View on Github external
def get_links(browser, page, logger, media, element):
    links = []
    try:
        # Get image links in scope from hashtag, location and other pages
        link_elems = element.find_elements_by_xpath('//a[starts-with(@href, "/p/")]')
        sleep(2)
        if link_elems:
            for link_elem in link_elems:
                try:
                    post_href = link_elem.get_attribute("href")
                    post_elem = element.find_elements_by_xpath(
                        "//a[@href='/p/" + post_href.split("/")[-2] + "/']/child::div"
                    )

                    if len(post_elem) == 1 and "Photo" in media:
                        # Single photo
                        links.append(post_href)

                    if len(post_elem) == 2:
                        # Carousel or Video
                        post_category = element.find_element_by_xpath(
                            "//a[@href='/p/"
github Instagram-Tools / bot / instapy / login_util.py View on Github external
def dismiss_notification_offer(browser, logger):
    """ Dismiss 'Turn on Notifications' offer on session start """
    offer_elem_loc = read_xpath(dismiss_notification_offer.__name__, "offer_elem_loc")
    dismiss_elem_loc = read_xpath(
        dismiss_notification_offer.__name__, "dismiss_elem_loc"
    )

    # wait a bit and see if the 'Turn on Notifications' offer rises up
    offer_loaded = explicit_wait(
        browser, "VOEL", [offer_elem_loc, "XPath"], logger, 4, False
    )

    if offer_loaded:
        dismiss_elem = browser.find_element_by_xpath(dismiss_elem_loc)
        click_element(browser, dismiss_elem)
github Instagram-Tools / bot / scheduleInstaPy.py View on Github external
def job():
    try:
        # check time restrictions
        is_not_hour_to_run = InstaPyStorage()
        if is_not_hour_to_run.check_limit() is True:
            print("Not an Hour to run")
            return 0
        #taglist = ['10monthsold', '8monthsold', 'babygram', 'kidstagram', 'babybump', '6months', 'proudmommy', 'toddlerfashion','girlmom','bows','momofgirls', 'babygirl', 'mommylife', 'momanddaughter', 'baby', 'mybabygirl', 'babygirl']
        taglist = ['10monthsold', '8monthsold', 'babygram', 'kidstagram', 'babybump', '6months', 'childhoodunplugged', 'candidchildhood', 'cameramama']
        shuffle(taglist)
        taglist = taglist[:5]
        print(taglist)

        #create instance
        session = InstaPy(username=insta_username, password=insta_password,
                          proxy_address='67.220.231.78', proxy_port=21317)
        session.login()

        # limits
        session.set_dont_like(['boy', 'boys', 'store', 'shop in bio', 'shipping', 'worldwide', 'shop'])
        #limits
        session.set_blacklist(enabled=True, campaign='General')
        session.set_upper_follower_count(limit=25500)
        session.set_dont_include(original_all_following)
        session.set_dont_include_language(['fa', 'ar', 'id', 'tr', 'ab', 'af', 'as', 'az', 'ba', 'zh', 'cv', 'th', 'sq'])
        session.set_user_interact(amount=2, randomize=False, percentage=100, media='Photo', listUsersFromDirectory=True)
        #configurations
        session.set_do_like(True, percentage=95)
        session.set_do_comment(True, percentage=20)
        session.set_do_follow(True, percentage=30, times=1)
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 / unfollow_util.py View on Github external
"--> Couldn't follow '{}'!\t~{}".format(user_name, failure_msg)
            )
            return False, following_status

        elif following_status is None:
            sirens_wailing, emergency_state = emergency_exit(browser, login, logger)
            if sirens_wailing is True:
                return False, emergency_state

            else:
                logger.warning(
                    "--> Couldn't unfollow '{}'!\t~unexpected failure".format(user_name)
                )
                return False, "unexpected failure"
    elif track == "dialog":
        click_element(browser, button)
        sleep(3)

    # general tasks after a successful follow
    logger.info("--> Followed '{}'!".format(user_name.encode("utf-8")))
    Event().followed(user_name)
    update_activity(
        browser, action="follows", state=None, logfolder=logfolder, logger=logger
    )

    # get user ID to record alongside username
    user_id = get_user_id(browser, track, user_name, logger)

    logtime = datetime.now().strftime("%Y-%m-%d %H:%M")
    log_followed_pool(login, user_name, logger, logfolder, logtime, user_id)

    follow_restriction("write", user_name, None, logger)
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
return False, following_status

        elif following_status is None:
            sirens_wailing, emergency_state = emergency_exit(browser, username, logger)
            if sirens_wailing is True:
                return False, emergency_state

            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)
github breuerfelix / instapy-gui / services / instapy / bot.py View on Github external
# set assets folder as a workspace
ASSETS = os.path.dirname(os.path.abspath(__file__)) + '/assets'
set_workspace(ASSETS)

# get an InstaPy session!
session = InstaPy(**instapy_args)

# function that will be executed before sig kill, to the browser window closes
def exit_browser(*args):
    session.browser.quit()


if platform.system() != 'Windows':
    signal.signal(signal.SIGUSR1, exit_browser)

with smart_run(session):
    for job in jobs:
        arguments = dict()
        for param in job['params']:
            arguments[param['name']] = param['value']

        getattr(session, job['functionName'])(**arguments)
github breuerfelix / instapy-gui / services / start_bot.py View on Github external
# convert to list
            param['value'] = param['value'].split(';')



    # login credentials
    insta_username = user['username']
    insta_password = user['password']

    # get an InstaPy session!
    # set headless_browser=True to run InstaPy in the background
    session = InstaPy(username = insta_username,
                      password = insta_password,
                      headless_browser = False)

    with smart_run(session):
        for job in jobs:
            arguments = dict()
            for param in job['params']:
                arguments[param['name']] = param['value']

            getattr(session, job['functionName'])(**arguments)
github Instagram-Tools / bot / instapy / comment_util.py View on Github external
def get_comment_input(browser, logger):
    comment_input = explicit_wait(browser, "VOEL", ['//textarea[@placeholder = "Add a comment…"]', "XPath"], logger, 7, False)

    if not comment_input:
        comment_input = explicit_wait(browser, "VOEL", ['//input[@placeholder = "Add a comment…"]', "XPath"], logger, 7, False)

    return comment_input
github Instagram-Tools / bot / instapy / login_util.py View on Github external
def dismiss_notification_offer(browser, logger):
    """ Dismiss 'Turn on Notifications' offer on session start """
    offer_elem_loc = read_xpath(dismiss_notification_offer.__name__, "offer_elem_loc")
    dismiss_elem_loc = read_xpath(
        dismiss_notification_offer.__name__, "dismiss_elem_loc"
    )

    # wait a bit and see if the 'Turn on Notifications' offer rises up
    offer_loaded = explicit_wait(
        browser, "VOEL", [offer_elem_loc, "XPath"], logger, 4, False
    )

    if offer_loaded:
        dismiss_elem = browser.find_element_by_xpath(dismiss_elem_loc)
        click_element(browser, dismiss_elem)