|
8 | 8 | import datetime |
9 | 9 | import json |
10 | 10 | from .parser.ProfileParser import parse_profile |
11 | | -from .structures import Profile, StoryLink |
| 11 | +from .parser.FollowersParser import parse_followers |
| 12 | +from .parser.FollowingsParser import parse_followings |
| 13 | +from .structures import Profile, StoryLink, Followers, Followings |
12 | 14 | from .Direct import Direct |
13 | 15 | from ensta.Utils import time_id, fb_uploader |
14 | 16 |
|
@@ -699,3 +701,72 @@ def unlike(self, media_id: str) -> bool: |
699 | 701 | "Unable to unlike media. Maybe try using another account, switch " |
700 | 702 | "to a different network, or use reputed proxies." |
701 | 703 | ) |
| 704 | + |
| 705 | + def followers(self, identifier: str, next_cursor: str | int | None = None) -> Followers: |
| 706 | + """ |
| 707 | + Get followers list of an account |
| 708 | + :param: identifier: Username or UserID (UserID Recommended) |
| 709 | + :return: Followers Object |
| 710 | + """ |
| 711 | + |
| 712 | + next_cursor: str = str(next_cursor) if next_cursor is not None else None |
| 713 | + user_id: str = self.profile(identifier).user_id |
| 714 | + max_id_line: str = f"&max_id={next_cursor}" if next_cursor is not None else "" |
| 715 | + |
| 716 | + response: Response = self.session.get( |
| 717 | + url=f"https://i.instagram.com/api/v1/friendships/{user_id}/followers/?enable_groups=true{max_id_line}" |
| 718 | + ) |
| 719 | + |
| 720 | + try: |
| 721 | + response_dict: dict = response.json() |
| 722 | + |
| 723 | + if response_dict.get("status", "") != "ok": |
| 724 | + raise NetworkError( |
| 725 | + "Response status was not ok.\n" |
| 726 | + f"Response Dict: {response_dict}" |
| 727 | + ) |
| 728 | + |
| 729 | + return parse_followers(response_dict) |
| 730 | + |
| 731 | + except JSONDecodeError: |
| 732 | + raise NetworkError( |
| 733 | + "Unable to get followers list. Make sure either the account is public or you're " |
| 734 | + "already following the target user. Also, make sure the user hasn't blocked or " |
| 735 | + "restricted you. Try using another account, switch " |
| 736 | + "to a different network, or use reputed proxies." |
| 737 | + ) |
| 738 | + |
| 739 | + def followings(self, identifier: str, next_cursor: str | int | None = None) -> Followings: |
| 740 | + """ |
| 741 | + Get followings list of an account |
| 742 | + :param: identifier: Username or UserID (UserID Recommended) |
| 743 | + :return: Followings Object |
| 744 | + """ |
| 745 | + |
| 746 | + next_cursor: str = str(next_cursor) if next_cursor is not None else None |
| 747 | + user_id: str = self.profile(identifier).user_id |
| 748 | + max_id_line: str = f"&max_id={next_cursor}" if next_cursor is not None else "" |
| 749 | + |
| 750 | + response: Response = self.session.get( |
| 751 | + url=f"https://i.instagram.com/api/v1/friendships/{user_id}/following/?enable_groups=true" |
| 752 | + f"&includes_hashtags=true{max_id_line}" |
| 753 | + ) |
| 754 | + |
| 755 | + try: |
| 756 | + response_dict: dict = response.json() |
| 757 | + |
| 758 | + if response_dict.get("status", "") != "ok": |
| 759 | + raise NetworkError( |
| 760 | + "Response status was not ok.\n" |
| 761 | + f"Response Dict: {response_dict}" |
| 762 | + ) |
| 763 | + |
| 764 | + return parse_followings(response_dict) |
| 765 | + |
| 766 | + except JSONDecodeError: |
| 767 | + raise NetworkError( |
| 768 | + "Unable to get followings list. Make sure either the account is public or you're " |
| 769 | + "already following the target user. Also, make sure the user hasn't blocked or " |
| 770 | + "restricted you. Try using another account, switch " |
| 771 | + "to a different network, or use reputed proxies." |
| 772 | + ) |
0 commit comments