From 2225244159016c45d9dd65a7eb6499c6087017f5 Mon Sep 17 00:00:00 2001 From: Nam PHAM <13-npham@users.noreply.gitlab.maiia.io> Date: Wed, 28 Sep 2022 12:40:35 +0200 Subject: [PATCH] fix: Fix way to get paged of maiia --- scraper/maiia/maiia.py | 2 -- scraper/maiia/maiia_utils.py | 12 ++++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/scraper/maiia/maiia.py b/scraper/maiia/maiia.py index d8773e019c4..346de69cc17 100644 --- a/scraper/maiia/maiia.py +++ b/scraper/maiia/maiia.py @@ -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", []) diff --git a/scraper/maiia/maiia_utils.py b/scraper/maiia/maiia_utils.py index 22ab20e8502..627f59c6d17 100644 --- a/scraper/maiia/maiia_utils.py +++ b/scraper/maiia/maiia_utils.py @@ -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: @@ -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