From 5438db9f2713c8077a5db90535bd7174287022fc Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 9 May 2023 20:26:45 -0500 Subject: [PATCH] Add `max_pages` arg for API `get_people_with_tag()` method for sake of testing, limit how many results to fetch --- rattail_nationbuilder/nationbuilder/webapi.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rattail_nationbuilder/nationbuilder/webapi.py b/rattail_nationbuilder/nationbuilder/webapi.py index 7e7eecd..65a7810 100644 --- a/rattail_nationbuilder/nationbuilder/webapi.py +++ b/rattail_nationbuilder/nationbuilder/webapi.py @@ -110,7 +110,7 @@ class NationBuilderWebAPI(object): message="Fetching Person data from NationBuilder") return people - def get_people_with_tag(self, tag, page_size=100, **kwargs): + def get_people_with_tag(self, tag, page_size=100, max_pages=None, **kwargs): """ Retrieve all Person records with the given tag. @@ -124,11 +124,15 @@ class NationBuilderWebAPI(object): response = self.get(api_method) data = response.json() people.extend(data['results']) + pages = 1 # get more pages, until complete while data['next']: + if max_pages and pages >= max_pages: + break response = self.get(data['next']) data = response.json() people.extend(data['results']) + pages += 1 return people