Skip to content

Commit

Permalink
Merge branch 'feat/support-airtable-connector' of https://github.com/…
Browse files Browse the repository at this point in the history
…Tanmaypatil123/pandas-ai into feat/support-airtable-connector
  • Loading branch information
Tanmaypatil123 committed Oct 17, 2023
2 parents fc5c326 + b2fe3a7 commit 88c419d
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions pandasai/connectors/airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,38 +178,35 @@ def _request_api(self, params):

def _fetch_data(self):
"""
Feteches data from airtable server through
API and converts it to DataFrame.
Fetches data from the Airtable server via API and converts it to a DataFrame.
"""

params = {}
params = {
"pageSize": 100,
"offset": "0"
}

if self._config.where is not None:
params["filterByFormula"] = self._build_formula()

params["pageSize"] = 100
params["offset"] = "0"

data = []
while True:
response = self._request_api(params=params)

if response.status_code == 200:
res = response.json()
data.extend(
[
{"id": record["id"], **record["fields"]}
for record in res["records"]
]
)
if len(res["records"]) < 100:
break
else:
if response.status_code != 200:
raise InvalidRequestError(
f"""Failed to connect to Airtable.
Status code: {response.status_code},
message: {response.text}"""
f"Failed to connect to Airtable. "
f"Status code: {response.status_code}, "
f"message: {response.text}"
)

res = response.json()
records = res.get("records", [])
data.extend({"id": record["id"], **record["fields"]} for record in records)

if len(records) < 100 or "offset" not in res:
break

if "offset" in res:
params["offset"] = res["offset"]

Expand Down

0 comments on commit 88c419d

Please sign in to comment.