Skip to content

Commit

Permalink
fix: Fix way to get paged of maiia
Browse files Browse the repository at this point in the history
  • Loading branch information
Nam PHAM committed Sep 28, 2022
1 parent 8819e67 commit 2225244
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 0 additions & 2 deletions scraper/maiia/maiia.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ def get_reasons(
) -> list:
url = PLATFORM_API.get("motives").format(center_id=center_id)
result = get_paged(url, limit=limit, client=client, request=request, request_type="motives")
if not result["total"]:
return []
return result.get("items", [])


Expand Down
12 changes: 4 additions & 8 deletions scraper/maiia/maiia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ def get_paged(
) -> dict:
result = dict()
result["items"] = []
result["total"] = 0
page = 0
loops = 0
while loops <= result["total"]:
base_url = f"{url}&limit={limit}&page={page}"
while True:
base_url = f"{url}&limit={limit}&page={page}&size={limit}"
if request:
request.increase_request_count(request_type)
try:
Expand All @@ -49,10 +47,8 @@ def get_paged(
result["total"] = payload["total"]
if not payload["items"]:
break
for item in payload.get("items"):
result["items"].append(item)
if len(result["items"]) >= result["total"]:
result["items"].extend(payload["items"])
if len(payload["items"]) < limit:
break
page += 1
loops += 1
return result

0 comments on commit 2225244

Please sign in to comment.