Instapy: potency_ratio=None causes error when used with interact_with_user

Created on 25 Apr 2018  路  11Comments  路  Source: timgrossmann/InstaPy

Expected Behavior

should follow user, like one of his photo based on delimit values

Current Behavior

loads a user, stops

Possible Solution (optional)

in like util.py change lines starting 551 and 553 to:
```
if potency_ratio is not None:
if potency_ratio < 0:
potency_ratio *= -1
reverse_relationship = True

this fixed the issue
## InstaPy configuration
not important I think, i am just messing with setting, the important thing is i used "session.interact_with_user"
the error is here tho:

Traceback (most recent call last):
File "quickstart.py", line 45, in
session.interact_by_users(users[:2], amount=1)
File "C:\Users\marti\OneDrive\Proj\InstaPy-master\instapy\instapy.py", line 1307, in interact_by_users
self.logger)
File "C:\Users\marti\OneDrive\Proj\InstaPy-master\instapy\like_util.py", line 551, in check_link
if potency_ratio < 0:
TypeError: '<' not supported between instances of 'NoneType' and 'int'
```

wontfix

Most helpful comment

@uluQulu thanks a lot, you my man

1) ive been trying for 4 hours to get it working with the limits i want, i finally have it, jesus christ selenium is a b*h haha, i have edited your code, i just dont know how to use set_relationship_bounds values, i used integers (1500, 1000, ...) instead, works like charm!

    else:
        if is_private:
            logger.warning("This user is private... ~ sending a follow request".format(username))

            followers = \
            browser.execute_script('return window._sharedData')['entry_data']['ProfilePage'][0]['graphql']['user'][
                'edge_follow']['count']
            followings = \
            browser.execute_script('return window._sharedData')['entry_data']['ProfilePage'][0]['graphql']['user'][
                'edge_followed_by']['count']
            if 1500 > followers > 50 and 600 > followings > 100:
                follow_request_button = browser.find_element_by_css_selector("span._lyv4q._ov9ai > button")
                click_element(browser, follow_request_button)
                sleep(1)

            return False

2) the none thing, cheers for answering, it seems so unnatural to me idk or illogical, ill have to play with it some more to understand

3) made a PR, happy to help

All 11 comments

hi @MMorte,
Thanks for issuing quickly cos this is a great catch!
_Actually I wrote reverse potency_ratio at last steps and somehow forgot that condition with the value of None_
Can you PR this fix?

Well, yes it affects every feature, including your fav intercat_by_users ..

haha sure no prob, i am new to programming and git, so as soon as ill figure how to ill pr, btw since i have you here, i am currently running this:

# users is a list dont worry bout it
    session.set_do_follow(True, percentage=100)
    session.set_do_like(True, percentage=90)
    session.interact_by_users(users[:32], amount=1)

is there a way to not exclude private accounts? it just skips over them

Wow, you're a fast learner, @MMorte!
Well, the only interaction can happen on private accaunts (_those private accaunts you do not fully follow yet_) is to follow (_sending a follow request_).
_Do you really want it?_

thats exactly what I want, will it work with the delimit values?

just to clarify btw, you edited it to "if potency ratio and potency_ratio < 0:"
if potency ratio = None it resolves as if None and potency_ratio < 0:
how come this works it seems weird to me

bonus:
the script got sometimes stuck on google.com, i added time.sleep(1) on line 112 to login_util.py and it works so far if anyone is having a similar issue

Fine,
Consider that, set_relationship_bounds values will not be taking into accaunt while sending a follow request on private accaunts (_cos checking relationship bounds is located inside check_link_)
in like_util.py file, replace,

if is_private:
    logger.warning('This user is private...')
    return False

with

if is_private:
    logger.warning("'{}'s profile is private...  ~ sending a follow request".format(username))

    follow_request_button = browser.find_element_by_css_selector("span._lyv4q._ov9ai > button")
    click_element(browser, follow_request_button)
    sleep(1)

    return False

This modification will work for both interact_by_users and like_by_users

@MMorte,
zx is a test variable

if zx is not None:
    print('cool')
if zx:
    print('cool')

The difference is if zx statement will not print when zx gets a value of 0 which is desired for potency_ratio's behaviour

_Boolean values also trigger if zx statement, but potency_ratio will unlikely get a bool value, that's why it is safe_

It is great, @MMorte, why don't you PR that small time.sleep(1) change?
_regarding login_util.py, it looks helpful_

@uluQulu thanks a lot, you my man

1) ive been trying for 4 hours to get it working with the limits i want, i finally have it, jesus christ selenium is a b*h haha, i have edited your code, i just dont know how to use set_relationship_bounds values, i used integers (1500, 1000, ...) instead, works like charm!

    else:
        if is_private:
            logger.warning("This user is private... ~ sending a follow request".format(username))

            followers = \
            browser.execute_script('return window._sharedData')['entry_data']['ProfilePage'][0]['graphql']['user'][
                'edge_follow']['count']
            followings = \
            browser.execute_script('return window._sharedData')['entry_data']['ProfilePage'][0]['graphql']['user'][
                'edge_followed_by']['count']
            if 1500 > followers > 50 and 600 > followings > 100:
                follow_request_button = browser.find_element_by_css_selector("span._lyv4q._ov9ai > button")
                click_element(browser, follow_request_button)
                sleep(1)

            return False

2) the none thing, cheers for answering, it seems so unnatural to me idk or illogical, ill have to play with it some more to understand

3) made a PR, happy to help

It is great @MMorte,
_To use set_relationship_bounds values, you must pass it's values to desired function._
You have done good job solving _relationship bounds_, but if you also check the user against ignore_users and blacklist lists, then your implementation will be fully operational! (_it is for, e.g. maybe the private user's username is in your ignore list or is in your blacklist, but the only place it is checked is in check_link function, so you have possibility to send a follow request to undesired user_...)
Also, try to add a parameter for it, e.g. private_accaunts=True and pass it for activating/deactivating it's usage.. (_cos some users may not be wanting the same as you do.._)
After doing those above, it would be a good option for many!
Good luck!

@uluQulu ive been trying the whole morning but im just lost in the sea of code, apologies i think im not capable enough yet

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

v77v picture v77v  路  3Comments

Spyd3r0us picture Spyd3r0us  路  3Comments

ingorichter picture ingorichter  路  3Comments

Naramsim picture Naramsim  路  3Comments

46960 picture 46960  路  3Comments