diff --git a/instaloader/__main__.py b/instaloader/__main__.py index 0233f56..7735279 100644 --- a/instaloader/__main__.py +++ b/instaloader/__main__.py @@ -109,7 +109,7 @@ def _main(instaloader: Instaloader, targetlist: List[str], instaloader.context.log("Retrieving followees of %s..." % target[1:]) profile = Profile.from_username(instaloader.context, target[1:]) followees = profile.get_followees() - profiles.update([followee['username'] for followee in followees]) + profiles.update([followee.username for followee in followees]) elif target[0] == '#': instaloader.download_hashtag(hashtag=target[1:], max_count=max_count, fast_update=fast_update, filter_func=filter_func) diff --git a/instaloader/structures.py b/instaloader/structures.py index 42a6000..7207e55 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -477,41 +477,37 @@ class Profile: self._rhx_gis, self._metadata('edge_saved_media'))) - def get_followers(self) -> Iterator[Dict[str, Any]]: + def get_followers(self) -> Iterator['Profile']: """ Retrieve list of followers of given profile. To use this, one needs to be logged in and private profiles has to be followed, otherwise this returns an empty list. - - :param profile: Name of profile to lookup followers. """ if not self._context.is_logged_in: raise LoginRequiredException("--login required to get a profile's followers.") self._obtain_metadata() - yield from self._context.graphql_node_list("37479f2b8209594dde7facb0d904896a", - {'id': str(self.userid)}, - 'https://www.instagram.com/' + self.username + '/', - lambda d: d['data']['user']['edge_followed_by'], - self._rhx_gis) + yield from (Profile(self._context, node) for node in + self._context.graphql_node_list("37479f2b8209594dde7facb0d904896a", + {'id': str(self.userid)}, + 'https://www.instagram.com/' + self.username + '/', + lambda d: d['data']['user']['edge_followed_by'], + self._rhx_gis)) - def get_followees(self) -> Iterator[Dict[str, Any]]: + def get_followees(self) -> Iterator['Profile']: """ Retrieve list of followees (followings) of given profile. To use this, one needs to be logged in and private profiles has to be followed, otherwise this returns an empty list. - - :param profile: Name of profile to lookup followers. """ if not self._context.is_logged_in: raise LoginRequiredException("--login required to get a profile's followees.") self._obtain_metadata() - yield from self._context.graphql_node_list("58712303d941c6855d4e888c5f0cd22f", - {'id': str(self.userid)}, - 'https://www.instagram.com/' + self.username + '/', - lambda d: d['data']['user']['edge_follow'], - self._rhx_gis) - - + yield from (Profile(self._context, node) for node in + self._context.graphql_node_list("58712303d941c6855d4e888c5f0cd22f", + {'id': str(self.userid)}, + 'https://www.instagram.com/' + self.username + '/', + lambda d: d['data']['user']['edge_follow'], + self._rhx_gis)) class StoryItem: diff --git a/test/instaloader_unittests.py b/test/instaloader_unittests.py index 29743aa..85265c3 100644 --- a/test/instaloader_unittests.py +++ b/test/instaloader_unittests.py @@ -111,12 +111,12 @@ class TestInstaloaderLoggedIn(TestInstaloaderAnonymously): def test_get_followees(self): profile = instaloader.Profile.from_username(self.L.context, OWN_USERNAME) for f in profile.get_followees(): - print(f['username']) + print(f.username) def test_get_followers(self): profile = instaloader.Profile.from_username(self.L.context, OWN_USERNAME) for f in profile.get_followers(): - print(f['username']) + print(f.username) def test_get_username_by_id(self): self.assertEqual(PUBLIC_PROFILE.lower(),