Instapy: Relationship ratio: unknown

Created on 6 May 2018  ·  14Comments  ·  Source: timgrossmann/InstaPy

I suppose there is a bug.
If the ratio is almost a unit, like 1 or 2 i get in the log:
followers: 1253 | following: 1276 | relationship ratio: 1.0
followers: 1048 | following: 2610 | relationship ratio: 2.0

otherwise i get ratio: unknow like:
241 | following: 186 | relationship ratio: unknown
1159 | following: 778 | relationship ratio: unknown

my setup is: session.set_relationship_bounds(enabled=True,potency_ratio=-1.05,delimit_by_numbers=True,max_followers=None,max_following=None,min_followers=30,min_following=30)

wontfix

All 14 comments

Hi @redsector72,
Can you show a console output of that example?
I would like to see, cos the value of unknown should only be returned when either _followers count_ or _following count_ was _unknown_.

is this a console log?

INFO [2018-05-06 08:34:36] [uuu] https://www.instagram.com/p/Bib3-jGA1y2/?taken-at=214548286
INFO [2018-05-06 08:34:39] [uuu] Image from: ceci1602
INFO [2018-05-06 08:34:42] [uuu] User: ceci1602 >> followers: 154 | following: 150 | relationship ratio: unknown

[8/10]
INFO [2018-05-06 08:36:08] [uuu] https://www.instagram.com/p/Bib6gHChXhU/?taken-at=213050058
INFO [2018-05-06 08:36:10] [uuu] Image from: tjevina
INFO [2018-05-06 08:36:15] [uuu] User: tjevina >> followers: 394 | following: 387 | relationship ratio: unknown
INFO [2018-05-06 08:36:15] [uuu] Link: https://www.instagram.com/p/Bib6gHChXhU/?taken-at=213050058
INFO [2018-05-06 08:36:15] [uuu] Description: “birds” 🐦🦅
INFO [2018-05-06 08:36:17] [uuu] --> Image Liked!

Very weird! @redsector72,
I wonder what is your system (OS & python version)
But try this:
in like_util.py file, find and replace

float("{0:.2f}".format(relationship_ratio)) if relationship_ratio else 'unknown'))

with

float("{0:.2f}".format(relationship_ratio)) if relationship_ratio is not None else 'unknown'))

_See if it works, now_

I am on a Mac, with Python 2.7.10 (default, Oct 6 2017, 22:29:07).
will try and report.
thanks

I have given a try.
Now there is no more "unknown", bu the math is something wrong.
here some example
[1/26]
https://www.instagram.com/p/BifCxMtFMIw/?taken-at=217395054
Image from: michelesciacqua
User: michelesciacqua >> followers: 574 | following: 1061 | relationship ratio: 1.0

that's not a 1.0 ratio

https://www.instagram.com/p/BifCn0QBt8M/?taken-at=217395054
Image from: nella_semeraro
User: nella_semeraro >> followers: 304 | following: 288 | relationship ratio: 0.0

and that's not a zero.

https://www.instagram.com/p/BifCnwEhiEr/?taken-at=217395054
Image from: nichelcromo
User: nichelcromo >> followers: 318 | following: 274 | relationship ratio: 0.0
Link: https://www.instagram.com/p/BifCnwEhiEr/?taken-at=217395054

Ok I've done some test.
Seems like the division of 2 interger, is an integer.
To get the code work, without any modification, i had to add at the very first line of like_util.py
from __future__ import division
this way a division of two integer become a float.

Is there a way to fix that?

here the output with the added line at the top.

https://www.instagram.com/p/Bie9NpVHI2t/?tagged=nuove
Image from: ch04_official
User: ch04_official >> followers: 794 | following: 17 | relationship ratio: 0.02

https://www.instagram.com/p/Bie4I3Mnqdr/?tagged=nuove
Image from: grandistefano89
User: grandistefano89 >> followers: 586 | following: 1627 | relationship ratio: 2.78

Wow! @redsector72, how could I miss that point!
On python 2.7, dividing integers results in an integer :C

Find and replace,

relationship_ratio = (followers_count/following_count
                       if not reverse_relationship
                        else following_count/followers_count)

with

relationship_ratio = (float(followers_count)/float(following_count)
                       if not reverse_relationship
                        else float(following_count)/float(followers_count))

_We just added float data type notation before following & followers counts._
Importing division from __future__ module is also an option but it has a downside which will return double-precision floating point values in every division at that file..
Can you test one more time and PR this change?
_Also, I think you will not need the previous modification I suggested in above comment https://github.com/timgrossmann/InstaPy/issues/1975#issuecomment-386878000, after adding those float notations._

Hi UluQulu,
I've added only the last suggested patch (from git reset hard)
this way works correctly, so you can commit.
Thanks for

amazing! @redsector72,
It is your catch ;)
Can you pull a request covering this change?

I have no idea on how to pull a request

@redsector72,
It is very easy!
Fork a fresh InstaPy and make only the change we have done here and the click pull a request button, and there make sure the only change in that PR is the one we have done here. After verifying it is correct, click on Create Pull Request.

There is another flaw with the relationship ratio calculation that doesn't handle divide by zero.

Should add

except ZeroDivisionError:
relationship_ratio = (float(followers_count)/float(following_count+1)

Some accounts don't follow others.

I've thought of it,

if followers_count and following_count:
    relationship_ratio = (float(followers_count)/float(following_count)
               if not reverse_relationship
                else float(following_count)/float(followers_count))

if followers_count and following_count: statement will make sure neither followers_count nor following_count is zero in order to avoid ZeroDevisionError.

But having thought again, it will be good to make it work with zero, I will look at it some time.

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