Skip to content

Commit

Permalink
SFR-2304_Add Airtable API Authentication Flow (#446)
Browse files Browse the repository at this point in the history
* SFR-2304_Add Airtable API Authentication Flow

* Added Airtable integration to util function

* fixing newlines

---------

Co-authored-by: Dmitri <[email protected]>
Co-authored-by: kyle <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent b4ce653 commit edda0ce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
from .ingest.loc import LOCProcess
from .ingest.u_of_m import UofMProcess
from .file.fulfill_url_manifest import FulfillURLManifestProcess
from .ingest.publisher_backlist import PublisherBacklistProcess
33 changes: 33 additions & 0 deletions processes/ingest/publisher_backlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
from ..util import airtable_integration

from ..core import CoreProcess
from logger import create_log

logger = create_log(__name__)

class PublisherBacklistProcess(CoreProcess):
def __init__(self, *args):
super(PublisherBacklistProcess, self).__init__(*args[:4])

self.ingest_offset = int(args[5] or 0)
self.ingest_limit = (int(args[4]) + self.ingestOffset) if args[4] else 5000
self.full_import = self.process == 'complete'

self.generateEngine()
self.createSession()

self.s3_bucket = os.environ['FILE_BUCKET']
self.createS3Client()

def runProcess(self):
try:

response = airtable_integration.create_airtable_request()

print(response)

except Exception as e:
logger.exception('Failed to run Pub Backlist process')
raise e

17 changes: 17 additions & 0 deletions processes/util/airtable_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import requests

def create_authorization_header():
bearer_token = os.environ.get("AIRTABLE_KEY")

headers = {"Authorization": f"Bearer {bearer_token}"}

return headers

def create_airtable_request():

headers = create_authorization_header()

response = requests.get('https://api.airtable.com/v0/appBoLf4lMofecGPU/Publisher%20Backlists%20%26%20Collections%20%F0%9F%93%96?view=UofMichigan%20Press&maxRecords=3', headers=headers)

return response.json()

0 comments on commit edda0ce

Please sign in to comment.