Skip to content

feat: add is_followed_by_me to fix #571#572

Merged
faretek1 merged 4 commits intoTimMcCool:mainfrom
uukelele:patch-2
Mar 2, 2026
Merged

feat: add is_followed_by_me to fix #571#572
faretek1 merged 4 commits intoTimMcCool:mainfrom
uukelele:patch-2

Conversation

@uukelele
Copy link
Contributor

@uukelele uukelele commented Mar 2, 2026

Solves issue #571

Changes

added is_followed_by_me which uses the follow button.

Tests

works and is ready to merge.

one thing I noticed though:

for users with small amount e.g. <20 followers, is_followed_by is actually faster, in my case (19 followers) 0.19s vs 0.94s.

but for those with more followers e.g. 100, is_followed_by is slower, in my case (131 followers) 1.58s vs 0.54s

Signed-off-by: uukelele <robustrobot11@gmail.com>
Signed-off-by: uukelele <robustrobot11@gmail.com>
Signed-off-by: uukelele <robustrobot11@gmail.com>
Signed-off-by: uukelele <robustrobot11@gmail.com>
Copy link
Collaborator

@faretek1 faretek1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on my machine and it works

soup = BeautifulSoup(resp.text, "html.parser")
follow_btn = soup.select_one("div.follow-button")
if not follow_btn:
print("Warning: follow button not found in page.")
Copy link
Collaborator

@faretek1 faretek1 Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be better if it's done with warnings.warn but this should not happen anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after some usage myself i realised that if you get your own user and try .is_followed_by_me() the follow button wouldn't be found in the page

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should this fall back to the less efficient functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should this fall back to the less efficient functionality?

i think it's better if we just explicitly state in the docs how this function works and when to use it.

as i said in the PR body:

for users with small amount e.g. <20 followers, is_followed_by is actually faster, in my case (19 followers) 0.19s vs 0.94s.

but for those with more followers e.g. 100, is_followed_by is slower, in my case (131 followers) 1.58s vs 0.54s

i guess if you try iterate through like griffpatch's followers then is_followed_by would be a hell of a lot slower than is_followed_by_me.

so we should state that the is_followed_by_me method is best to use on users who 1) are NOT the currently logged in user and 2) have larger amount of followers.

of course i guess we could automate this by perhaps checking in is_followed_by if the username given is the one of the current session, and if the target user has over a set threshold of followers then switch to is_followed_by_me, but i guess that makes it unnecessarily complex and probably just easier to let the dev choose which one they need

Copy link
Contributor Author

@uukelele uukelele Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also one thing I noticed which I don't know why it wasn't implemented is that looking at the amount of times we fetch the users HTML profile page in User methods, maybe it'd be better to cache that?

or maybe we fetch the user page once when class created and store is_followed_by_me as a property? and then have .update() refresh this

@uukelele uukelele marked this pull request as ready for review March 2, 2026 18:13
@uukelele
Copy link
Contributor Author

uukelele commented Mar 2, 2026

I forgot to mark as ready for review after I tested it

@faretek1 faretek1 merged commit 89c2f4f into TimMcCool:main Mar 2, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Todo to Done in scratchattach Mar 2, 2026
@faretek1
Copy link
Collaborator

faretek1 commented Mar 7, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants