get_stories(): Fetch in chunks of 100 users
It seems there is a limit of how many user stories can be requested at once. Now, Instaloader.get_stories() chunks the stories request. Fixes #157 and fixes #134.
This commit is contained in:
parent
a34d750152
commit
a070ed42ae
@ -396,16 +396,21 @@ class Instaloader:
|
|||||||
:param userids: List of user IDs to be processed in terms of downloading their stories, or None.
|
:param userids: List of user IDs to be processed in terms of downloading their stories, or None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if userids is None:
|
if not userids:
|
||||||
data = self.context.graphql_query("d15efd8c0c5b23f0ef71f18bf363c704",
|
data = self.context.graphql_query("d15efd8c0c5b23f0ef71f18bf363c704",
|
||||||
{"only_stories": True})["data"]["user"]
|
{"only_stories": True})["data"]["user"]
|
||||||
if data is None:
|
if data is None:
|
||||||
raise BadResponseException('Bad stories reel JSON.')
|
raise BadResponseException('Bad stories reel JSON.')
|
||||||
userids = list(edge["node"]["id"] for edge in data["feed_reels_tray"]["edge_reels_tray_to_reel"]["edges"])
|
userids = list(edge["node"]["id"] for edge in data["feed_reels_tray"]["edge_reels_tray_to_reel"]["edges"])
|
||||||
|
|
||||||
stories = self.context.graphql_query("bf41e22b1c4ba4c9f31b844ebb7d9056",
|
def _userid_chunks():
|
||||||
{"reel_ids": userids, "precomposed_overlay": False})["data"]
|
userids_per_query = 100
|
||||||
|
for i in range(0, len(userids), userids_per_query):
|
||||||
|
yield userids[i:i + userids_per_query]
|
||||||
|
|
||||||
|
for userid_chunk in _userid_chunks():
|
||||||
|
stories = self.context.graphql_query("bf41e22b1c4ba4c9f31b844ebb7d9056",
|
||||||
|
{"reel_ids": userid_chunk, "precomposed_overlay": False})["data"]
|
||||||
yield from (Story(self.context, media) for media in stories['reels_media'])
|
yield from (Story(self.context, media) for media in stories['reels_media'])
|
||||||
|
|
||||||
@_requires_login
|
@_requires_login
|
||||||
|
Loading…
Reference in New Issue
Block a user