Skip to content

Commit

Permalink
Airtable: Take base and table IDs from environment (#200)
Browse files Browse the repository at this point in the history
* Airtable: Switch to using copy of base+table I have a token for.

Might be a better approach here, but this works for now.

* Airtable: Take base and table IDs from environment.

This allows them to be swapped out for alternative copies,
for different users running the script.

* Airtable: Prefix airtable base+table ID env vars with the dataset.

Also shuffle where we use them up to the dataset config level.

Makes it easier to add additional Airtable datasets.
  • Loading branch information
jbeshir authored Apr 24, 2024
1 parent 7c0f8c6 commit 2bc78e9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ MIN_CONFIDENCE="0.5"

CODA_TOKEN=""
YOUTUBE_API_KEY=""

AIRTABLE_API_KEY=""
AGISF_AIRTABLE_BASE_ID=""
AGISF_AIRTABLE_TABLE_ID=""

ARD_DB_USER="user"
ARD_DB_PASSWORD="we all live in a yellow submarine"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/check-articles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
env:
CODA_TOKEN: ${{ secrets.CODA_TOKEN }}
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
AGISF_AIRTABLE_BASE_ID: ${{ secrets.AGISF_AIRTABLE_BASE_ID }}
AGISF_AIRTABLE_TABLE_ID: ${{ secrets.AGISF_AIRTABLE_TABLE_ID }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ARD_DB_USER: ${{ secrets.ARD_DB_USER }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fetch-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
datasource: ${{ matrix.datasource }}
coda_token: ${{ inputs.coda_token }}
airtable_api_key: ${{ inputs.airtable_api_key }}
agisf_airtable_base_id: ${{ inputs.agisf_airtable_base_id }}
agisf_airtable_table_id: ${{ inputs.agisf_airtable_table_id }}
youtube_api_key: ${{ inputs.youtube_api_key }}
db_user: ${{ inputs.db_user }}
db_password: ${{ inputs.db_password }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/fetch-dataset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ on:
airtable_api_key:
type: string
required: true
agisf_airtable_base_id:
type: string
required: true
agisf_airtable_table_id:
type: string
required: true
youtube_api_key:
type: string
required: true
Expand Down Expand Up @@ -72,6 +78,8 @@ jobs:
env:
CODA_TOKEN: ${{ secrets.CODA_TOKEN || inputs.coda_token }}
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY || inputs.airtable_api_key }}
AGISF_AIRTABLE_BASE_ID: ${{ secrets.AGISF_AIRTABLE_BASE_ID || inputs.agisf_airtable_base_id }}
AGISF_AIRTABLE_TABLE_ID: ${{ secrets.AGISF_AIRTABLE_TABLE_ID || inputs.agisf_airtable_table_id }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY || inputs.youtube_api_key }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || inputs.openai_api_key }}
ARD_DB_USER: ${{ secrets.ARD_DB_USER || inputs.db_user }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fetch-weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
datasource: ${{ matrix.datasource }}
coda_token: ${{ inputs.coda_token }}
airtable_api_key: ${{ inputs.airtable_api_key }}
agisf_airtable_base_id: ${{ inputs.agisf_airtable_base_id }}
agisf_airtable_table_id: ${{ inputs.agisf_airtable_table_id }}
youtube_api_key: ${{ inputs.youtube_api_key }}
db_user: ${{ inputs.db_user }}
db_password: ${{ inputs.db_password }}
Expand Down
2 changes: 2 additions & 0 deletions align_data/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

### Airtable ###
AIRTABLE_API_KEY = os.environ.get("AIRTABLE_API_KEY")
AGISF_AIRTABLE_BASE_ID = os.environ.get("AGISF_AIRTABLE_BASE_ID")
AGISF_AIRTABLE_TABLE_ID = os.environ.get("AGISF_AIRTABLE_TABLE_ID")

### MYSQL ###
user = os.environ.get("ARD_DB_USER", "user")
Expand Down
6 changes: 4 additions & 2 deletions align_data/sources/agisf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from align_data.sources.airtable import AirtableDataset
from align_data.sources.agisf.agisf import AGISFPodcastDataset

from align_data.settings import AGISF_AIRTABLE_BASE_ID, AGISF_AIRTABLE_TABLE_ID


datasets = [
AirtableDataset(
name="agisf_governance",
base_id="app9q0E0jlDWlsR0z",
table_id="tblgTb3kszvSbo2Mb",
base_id=AGISF_AIRTABLE_BASE_ID,
table_id=AGISF_AIRTABLE_TABLE_ID,
mappings={
"title": "[>] Resource",
"url": "[h] [>] Link",
Expand Down
4 changes: 4 additions & 0 deletions align_data/sources/airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class AirtableDataset(AlignmentDataset):
def setup(self):
if not AIRTABLE_API_KEY:
raise ValueError("No AIRTABLE_API_KEY provided!")
if not self.base_id:
raise ValueError("No airtable base ID provided!")
if not self.table_id:
raise ValueError("No airtable table ID provided!")
super().setup()
self.at = airtable.Airtable(self.base_id, AIRTABLE_API_KEY)

Expand Down

0 comments on commit 2bc78e9

Please sign in to comment.