Skip to content

Commit

Permalink
Added the new class methods to the spreadsheet blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
johnathan-rodriguez committed Dec 8, 2023
1 parent 975d206 commit 60eb9f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 6 additions & 1 deletion shipyard_blueprints/airtable/shipyard_airtable/airtable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests
from shipyard_templates import Spreadsheets
from pyairtable import Table


class AirtableClient(Spreadsheets):
Expand All @@ -17,3 +16,9 @@ def connect(self):
headers = {"Authorization": f"Bearer {self.api_key}"}
response = requests.get(url, headers=headers)
return response.status_code

def fetch(self):
pass

def upload(self):
pass
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os
import json
import tempfile


from googleapiclient.discovery import build
from google.oauth2 import service_account
from shipyard_templates import Spreadsheets

Expand All @@ -9,6 +13,28 @@ def __init__(self, service_account: str) -> None:
self.service_account = service_account
super().__init__(service_account=service_account)

def _set_env_vars(self):
try:
json_credentials = json.loads(self.service_account)
fd, path = tempfile.mkstemp()
print(f"Storing json credentials temporarily at {path}")
with os.fdopen(fd, "w") as tmp:
tmp.write(self.service_account)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = path
return path
except Exception as e:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.service_account

def connect(self):
service_account_str = self.service_account.replace("\n", "\\n")
service_account.Credentials.from_service_account_info(json.loads(service_account_str))
fd = self._set_env_vars()
creds = service_account.Credentials.from_service_account_file(fd)
service = build("sheets", "v4", credentials=creds)
drive_service = build("drive", "v3", credentials=creds)
return service, drive_service

def fetch(self):
pass

def upload(self):
pass

0 comments on commit 60eb9f8

Please sign in to comment.