Skip to content

Commit 0e176eb

Browse files
committed
Corrected page range
1 parent 365f08c commit 0e176eb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scratchattach/site/user.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,20 @@ def loves(self, *, limit=40, offset=0, get_full_project: bool=False) -> [project
286286
raise exceptions.BadRequest("limit parameter must be >= 0")
287287

288288
# There are 40 projects on display per page
289-
# So number of pages to view until the limit is ceil(limit / 40)
290-
291-
# The first page you need to view is 1 + offset // 40
289+
# So the first page you need to view is 1 + offset // 40
292290
# (You have to add one because the first page is idx 1 instead of 0)
291+
292+
# The final project to view is at idx offset + limit - 1
293+
# (You have to -1 because the index starts at 0)
294+
# So the page number for this is 1 + (offset + limit - 1) // 40
295+
296+
# But this is a range so we have to add another 1 for the second argument
293297
pages = range(1 + offset // 40,
294-
1 + offset // 40 + math.ceil(limit / 40))
298+
2 + (offset + limit - 1) // 40)
295299
_projects = []
296300

297301
for page in pages:
302+
print(f"Requesting p {page}")
298303
# The index of the first project on page #n is just (n-1) * 40
299304
first_idx = (page - 1) * 40
300305

0 commit comments

Comments
 (0)