Skip to content

Commit

Permalink
rename airtable api key to pat to recognize new auth method airtable …
Browse files Browse the repository at this point in the history
…is forcing on us
  • Loading branch information
floptical committed Feb 14, 2024
1 parent e04e672 commit c6ac215
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions databridge_etl_tools/airtable/airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@


class Airtable():
def __init__(self, app_id:str, api_key:str, table_name:str, s3_bucket:str, s3_key:str, add_objectid:bool, get_fields=None):
def __init__(self, app_id:str, pat_token:str, table_name:str, s3_bucket:str, s3_key:str, add_objectid:bool, get_fields=None):
self.app_id = app_id
self.api_key = api_key
self.pat_token = pat_token
self.table_name = table_name
self.s3_bucket = s3_bucket
self.s3_key = s3_key
Expand All @@ -38,21 +38,25 @@ def get_fieldnames(self):
response = requests.get(
request_stmt,
headers={
'Authorization': f'Bearer {self.api_key}'
'Authorization': f'Bearer {self.pat_token}'
}
)

data = response.json()

fieldnames = []

for record in data['records']:
record_fieldnames = list(record['fields'].keys())
try:
for record in data['records']:
record_fieldnames = list(record['fields'].keys())

for fieldname in record_fieldnames:
if fieldname not in fieldnames:
for fieldname in record_fieldnames:
if fieldname not in fieldnames:

fieldnames.append(fieldname)
fieldnames.append(fieldname)
except KeyError as e:
print(data)
raise Exception('Got unexpected response trying to determine headers!')

# Enforce lower-case headers because
# we're going into postgres and don't want mixed case.
Expand All @@ -76,7 +80,7 @@ def get_records(self, offset=None):
response = requests.get(
request_stmt,
headers={
'Authorization': f'Bearer {self.api_key}'
'Authorization': f'Bearer {self.pat_token}'
},
params={
'offset': offset
Expand Down
2 changes: 1 addition & 1 deletion databridge_etl_tools/airtable/airtable_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@click.group()
@click.pass_context
@click.option('--app_id', required=True)
@click.option('--api_key', required=True)
@click.option('--pat_token', required=True, help='Create here: https://airtable.com/create/tokens')
@click.option('--table_name', required=True)
@click.option('--s3_bucket', required=True)
@click.option('--s3_key', required=True)
Expand Down

0 comments on commit c6ac215

Please sign in to comment.