Add max_pages
arg for API get_people_with_tag()
method
for sake of testing, limit how many results to fetch
This commit is contained in:
parent
dfbd8f1652
commit
5438db9f27
|
@ -110,7 +110,7 @@ class NationBuilderWebAPI(object):
|
||||||
message="Fetching Person data from NationBuilder")
|
message="Fetching Person data from NationBuilder")
|
||||||
return people
|
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.
|
Retrieve all Person records with the given tag.
|
||||||
|
|
||||||
|
@ -124,11 +124,15 @@ class NationBuilderWebAPI(object):
|
||||||
response = self.get(api_method)
|
response = self.get(api_method)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
people.extend(data['results'])
|
people.extend(data['results'])
|
||||||
|
pages = 1
|
||||||
|
|
||||||
# get more pages, until complete
|
# get more pages, until complete
|
||||||
while data['next']:
|
while data['next']:
|
||||||
|
if max_pages and pages >= max_pages:
|
||||||
|
break
|
||||||
response = self.get(data['next'])
|
response = self.get(data['next'])
|
||||||
data = response.json()
|
data = response.json()
|
||||||
people.extend(data['results'])
|
people.extend(data['results'])
|
||||||
|
pages += 1
|
||||||
|
|
||||||
return people
|
return people
|
||||||
|
|
Loading…
Reference in a new issue