From edda0ce55f6ee79caacb92ade48719ab0ebaf100 Mon Sep 17 00:00:00 2001 From: Dmitri Slory Date: Fri, 15 Nov 2024 11:55:58 -0500 Subject: [PATCH] SFR-2304_Add Airtable API Authentication Flow (#446) * SFR-2304_Add Airtable API Authentication Flow * Added Airtable integration to util function * fixing newlines --------- Co-authored-by: Dmitri Co-authored-by: kyle --- processes/__init__.py | 1 + processes/ingest/publisher_backlist.py | 33 ++++++++++++++++++++++++++ processes/util/airtable_integration.py | 17 +++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 processes/ingest/publisher_backlist.py create mode 100644 processes/util/airtable_integration.py diff --git a/processes/__init__.py b/processes/__init__.py index 8dcf5bc7c8..7d5b05363b 100644 --- a/processes/__init__.py +++ b/processes/__init__.py @@ -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 diff --git a/processes/ingest/publisher_backlist.py b/processes/ingest/publisher_backlist.py new file mode 100644 index 0000000000..5cff652296 --- /dev/null +++ b/processes/ingest/publisher_backlist.py @@ -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 + \ No newline at end of file diff --git a/processes/util/airtable_integration.py b/processes/util/airtable_integration.py new file mode 100644 index 0000000000..b3ceedebc9 --- /dev/null +++ b/processes/util/airtable_integration.py @@ -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()