1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-11-20 17:22:31 +01:00

get_followe{e,r}s yield Profiles rather than dicts

This commit is contained in:
Alexander Graf 2018-04-17 15:11:50 +02:00
parent 9d8175354b
commit 066c3de113
3 changed files with 17 additions and 21 deletions

View File

@ -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)

View File

@ -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",
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)
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",
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)
self._rhx_gis))
class StoryItem:

View File

@ -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(),