From fa2a6c9c77f40ddb132fce5524dbae53ee75db64 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 11 Mar 2023 22:07:56 +0000 Subject: [PATCH] Properly check if pagination is present --- core/clients/platform.py | 59 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/core/clients/platform.py b/core/clients/platform.py index 90d34ac..604e448 100644 --- a/core/clients/platform.py +++ b/core/clients/platform.py @@ -292,14 +292,15 @@ class LocalPlatformClient(ABC): if "pagination" in ads: if ads["pagination"]: if "next" in ads["pagination"]: - page += 1 - ads_iter = await self.enum_ad_ids(page) - if ads_iter is None: - return False - if ads_iter is False: - return False - for ad in ads_iter: - ads_total.append(ad) + if ads["pagination"]["next"] is not None: + page += 1 + ads_iter = await self.enum_ad_ids(page) + if ads_iter is None: + return False + if ads_iter is False: + return False + for ad in ads_iter: + ads_total.append(ad) return ads_total async def enum_ads(self, requested_asset=None, page=0): @@ -321,14 +322,15 @@ class LocalPlatformClient(ABC): if "pagination" in ads: if ads["pagination"]: if "next" in ads["pagination"]: - page += 1 - ads_iter = await self.enum_ads(requested_asset, page) - if ads_iter is None: - return False - if ads_iter is False: - return False - for ad in ads_iter: - ads_total.append([ad[0], ad[1], ad[2], ad[3], ad[4]]) + if ads["pagination"]["next"] is not None: + page += 1 + ads_iter = await self.enum_ads(requested_asset, page) + if ads_iter is None: + return False + if ads_iter is False: + return False + for ad in ads_iter: + ads_total.append([ad[0], ad[1], ad[2], ad[3], ad[4]]) return ads_total def last_online_recent(self, date): @@ -413,18 +415,19 @@ class LocalPlatformClient(ABC): if "pagination" in ads: if ads["pagination"]: if "next" in ads["pagination"]: - page += 1 - ads_iter = await self.enum_public_ads( - asset, currency, provider, page - ) - if ads_iter is None: - return False - if ads_iter is False: - return False - for ad in ads_iter: - to_append = [ad[0], ad[1], ad[2], ad[3], ad[4], ad[5]] - if to_append not in to_return: - to_return.append(to_append) + if ads["pagination"]["next"] is not None: + page += 1 + ads_iter = await self.enum_public_ads( + asset, currency, provider, page + ) + if ads_iter is None: + return False + if ads_iter is False: + return False + for ad in ads_iter: + to_append = [ad[0], ad[1], ad[2], ad[3], ad[4], ad[5]] + if to_append not in to_return: + to_return.append(to_append) return to_return async def cheat(self, assets=None):