Skip to content

Commit 70499b3

Browse files
committed
add handling for paginated airtable responses
1 parent b1da2be commit 70499b3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

pybot/plugins/airtable/api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ async def post(self, url, **kwargs):
3232
async with self.session.post(url, headers=auth_header, **kwargs) as r:
3333
return await r.json()
3434

35+
async def _depaginate_records(self, url, params, offset):
36+
records = []
37+
while offset:
38+
params["offset"] = offset
39+
response = await self.get(url, params=params)
40+
records.extend(response["records"])
41+
offset = response.get("offset")
42+
43+
return records
44+
3545
def table_url(self, table_name, record_id=None):
3646
url = f"{self.API_ROOT}{self.base_key}/{table_name}"
3747
if record_id:
@@ -79,7 +89,13 @@ async def find_mentors_with_matching_skillsets(self, skillsets):
7989
)
8090
skillsets = skillsets.split(",")
8191
response = await self.get(url, params=params)
92+
offset = response.get("offset")
8293
mentors = response["records"]
94+
95+
if offset:
96+
additional_mentors = await self._depaginate_records(url, params, offset)
97+
mentors.extend(additional_mentors)
98+
8399
partial_match = []
84100
complete_match = []
85101
try:

0 commit comments

Comments
 (0)