diff --git a/scratchattach/site/user.py b/scratchattach/site/user.py index a36506f..51db4c6 100644 --- a/scratchattach/site/user.py +++ b/scratchattach/site/user.py @@ -494,6 +494,29 @@ def is_followed_by(self, user): return followed return followed + def is_followed_by_me(self): + """ + You can only use this function if this object was created using :meth:`scratchattach.session.Session.connect_user` + + Returns: + boolean: Whether the user is followed by the user currently logged in. + """ + self._assert_auth() + with requests.no_error_handling(): + resp = requests.get( + f"https://scratch.mit.edu/users/{self.username}/", + headers=self._headers, + cookies=self._cookies, + ) + 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.") + return False # defualt to not followed + data_control = follow_btn.get("data-control") + return data_control == 'unfollow' # True if unfollow, False if not + + def project_count(self): with requests.no_error_handling(): text = requests.get( diff --git a/tests/test_user.py b/tests/test_user.py index 6346dee..4dfefe4 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -6,7 +6,7 @@ def test_user(): if not credentials_available(): warnings.warn( - "Skipped test_studio because there were no credentials available." + "Skipped test_user because there were no credentials available." ) return sess = session() @@ -106,6 +106,11 @@ def test_user(): assert status_data["status"] == "Sample status" assert status_data["color"] == "#855cd6" + uukelele = sess.connect_user("uukelele") # could use anyone ScratchAttachV2 is following right now but i think its cool that its following my account - uukelele, 2026 + assert uukelele.is_followed_by_me() + # and someone he is not following + assert not griffpatch.is_followed_by_me() + if __name__ == "__main__": test_user()