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