Commit bd2d791 1 parent 3eb8ab6 commit bd2d791 Copy full SHA for bd2d791
File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ def __init__(
89
89
self ._oauth_token = oauth_token
90
90
self ._params = params
91
91
self ._total = None
92
+ self ._requests_count = 0
92
93
93
94
# Pre-fetch the first page as soon as cursor is instantiated
94
95
self .next_page ()
@@ -115,11 +116,17 @@ def __getitem__(self, index):
115
116
return self ._queue [index ]
116
117
117
118
def next_page (self ):
119
+ # Twitch stops returning a cursor when you're on the last page. So if we've made
120
+ # more than 1 request to their API and we don't get a cursor back, it means
121
+ # we're on the last page, so return whatever's left in the queue.
122
+ if self ._requests_count > 0 and not self ._cursor :
123
+ return self ._queue
124
+
118
125
if self ._cursor :
119
126
self ._params ["after" ] = self ._cursor
120
127
121
128
response = self ._request_get (self ._path , params = self ._params )
122
-
129
+ self . _requests_count += 1
123
130
self ._queue = [self ._resource .construct_from (data ) for data in response ["data" ]]
124
131
self ._cursor = response ["pagination" ].get ("cursor" )
125
132
self ._total = response .get ("total" )
You can’t perform that action at this time.
0 commit comments