[instagram] restore 'cursor' functionality (#2991)
This commit is contained in:
@@ -338,6 +338,14 @@ class InstagramExtractor(Extractor):
|
|||||||
"username" : user["username"],
|
"username" : user["username"],
|
||||||
"full_name": user["full_name"]})
|
"full_name": user["full_name"]})
|
||||||
|
|
||||||
|
def _init_cursor(self):
|
||||||
|
return self.config("cursor") or None
|
||||||
|
|
||||||
|
def _update_cursor(self, cursor):
|
||||||
|
self.log.debug("Cursor: %s", cursor)
|
||||||
|
self._cursor = cursor
|
||||||
|
return cursor
|
||||||
|
|
||||||
|
|
||||||
class InstagramUserExtractor(InstagramExtractor):
|
class InstagramUserExtractor(InstagramExtractor):
|
||||||
"""Extractor for an Instagram user profile"""
|
"""Extractor for an Instagram user profile"""
|
||||||
@@ -741,6 +749,9 @@ class InstagramRestAPI():
|
|||||||
def _pagination(self, endpoint, params=None, media=False):
|
def _pagination(self, endpoint, params=None, media=False):
|
||||||
if params is None:
|
if params is None:
|
||||||
params = {}
|
params = {}
|
||||||
|
extr = self.extractor
|
||||||
|
params["max_id"] = extr._init_cursor()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = self._call(endpoint, params=params)
|
data = self._call(endpoint, params=params)
|
||||||
|
|
||||||
@@ -752,9 +763,12 @@ class InstagramRestAPI():
|
|||||||
|
|
||||||
if not data.get("more_available"):
|
if not data.get("more_available"):
|
||||||
return
|
return
|
||||||
params["max_id"] = data["next_max_id"]
|
params["max_id"] = extr._update_cursor(data["next_max_id"])
|
||||||
|
|
||||||
def _pagination_post(self, endpoint, params):
|
def _pagination_post(self, endpoint, params):
|
||||||
|
extr = self.extractor
|
||||||
|
params["max_id"] = extr._init_cursor()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = self._call(endpoint, method="POST", data=params)
|
data = self._call(endpoint, method="POST", data=params)
|
||||||
|
|
||||||
@@ -764,9 +778,12 @@ class InstagramRestAPI():
|
|||||||
info = data["paging_info"]
|
info = data["paging_info"]
|
||||||
if not info.get("more_available"):
|
if not info.get("more_available"):
|
||||||
return
|
return
|
||||||
params["max_id"] = info["max_id"]
|
params["max_id"] = extr._update_cursor(info["max_id"])
|
||||||
|
|
||||||
def _pagination_sections(self, endpoint, params):
|
def _pagination_sections(self, endpoint, params):
|
||||||
|
extr = self.extractor
|
||||||
|
params["max_id"] = extr._init_cursor()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
info = self._call(endpoint, method="POST", data=params)
|
info = self._call(endpoint, method="POST", data=params)
|
||||||
|
|
||||||
@@ -774,8 +791,8 @@ class InstagramRestAPI():
|
|||||||
|
|
||||||
if not info.get("more_available"):
|
if not info.get("more_available"):
|
||||||
return
|
return
|
||||||
params["max_id"] = info["next_max_id"]
|
|
||||||
params["page"] = info["next_page"]
|
params["page"] = info["next_page"]
|
||||||
|
params["max_id"] = extr._update_cursor(info["next_max_id"])
|
||||||
|
|
||||||
|
|
||||||
class InstagramGraphqlAPI():
|
class InstagramGraphqlAPI():
|
||||||
@@ -871,9 +888,8 @@ class InstagramGraphqlAPI():
|
|||||||
|
|
||||||
def _pagination(self, query_hash, variables,
|
def _pagination(self, query_hash, variables,
|
||||||
key_data="user", key_edge=None):
|
key_data="user", key_edge=None):
|
||||||
cursor = self.extractor.config("cursor")
|
extr = self.extractor
|
||||||
if cursor:
|
variables["after"] = extr._init_cursor()
|
||||||
variables["after"] = cursor
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = self._call(query_hash, variables)[key_data]
|
data = self._call(query_hash, variables)[key_data]
|
||||||
@@ -890,8 +906,7 @@ class InstagramGraphqlAPI():
|
|||||||
raise exception.StopExtraction(
|
raise exception.StopExtraction(
|
||||||
"%s'%s posts are private", self.item, s)
|
"%s'%s posts are private", self.item, s)
|
||||||
|
|
||||||
variables["after"] = self._cursor = info["end_cursor"]
|
variables["after"] = extr._update_cursor(info["end_cursor"])
|
||||||
self.extractor.log.debug("Cursor: %s", self._cursor)
|
|
||||||
|
|
||||||
|
|
||||||
@cache(maxage=360*24*3600, keyarg=1)
|
@cache(maxage=360*24*3600, keyarg=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user