[tiktok] use time cursor for story requests (#8991)
This commit is contained in:
@@ -914,19 +914,22 @@ class TiktokPaginationCursor:
|
||||
|
||||
|
||||
class TiktokTimeCursor(TiktokPaginationCursor):
|
||||
def __init__(self, *, reverse=True):
|
||||
def __init__(self, *, reverse=True, has_more_attribute="hasMore",
|
||||
cursor_attribute="cursor"):
|
||||
super().__init__()
|
||||
self.cursor = 0
|
||||
# If we expect the cursor to go up or down as we go to the next page.
|
||||
# True for down, False for up.
|
||||
self.reverse = reverse
|
||||
self.has_more_key = has_more_attribute
|
||||
self.cursor_key = cursor_attribute
|
||||
|
||||
def current_page(self):
|
||||
return self.cursor
|
||||
|
||||
def next_page(self, data, query_parameters):
|
||||
skip_fallback_logic = self.cursor == 0
|
||||
new_cursor = int(data.get("cursor", 0))
|
||||
new_cursor = int(data.get(self.cursor_key, 0))
|
||||
no_cursor = not new_cursor
|
||||
if not skip_fallback_logic:
|
||||
# If the new cursor doesn't go in the direction we expect, use the
|
||||
@@ -938,7 +941,7 @@ class TiktokTimeCursor(TiktokPaginationCursor):
|
||||
elif no_cursor:
|
||||
raise exception.ExtractionError("Could not extract next cursor")
|
||||
self.cursor = new_cursor
|
||||
return not data.get("hasMore", False)
|
||||
return not data.get(self.has_more_key, False)
|
||||
|
||||
def fallback_cursor(self, data):
|
||||
try:
|
||||
@@ -968,6 +971,12 @@ class TiktokPopularTimeCursor(TiktokTimeCursor):
|
||||
return -50_000
|
||||
|
||||
|
||||
class TiktokStoryTimeCursor(TiktokTimeCursor):
|
||||
def __init__(self):
|
||||
super().__init__(reverse=False, has_more_attribute="HasMoreAfter",
|
||||
cursor_attribute="MaxCursor")
|
||||
|
||||
|
||||
class TiktokLegacyTimeCursor(TiktokPaginationCursor):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -1472,7 +1481,7 @@ class TiktokStoryItemListRequest(TiktokItemListRequest):
|
||||
assert query_parameters["loadBackward"] in ["true", "false"]
|
||||
|
||||
def cursor_type(self, query_parameters):
|
||||
return TiktokItemCursor
|
||||
return TiktokStoryTimeCursor
|
||||
|
||||
|
||||
class TiktokStoryBatchItemListRequest(TiktokItemListRequest):
|
||||
|
||||
Reference in New Issue
Block a user