From f9c41b1299dd672c8f642adc0c92c48e31591fc4 Mon Sep 17 00:00:00 2001 From: prakashr7d Date: Fri, 10 Nov 2023 22:11:09 +0530 Subject: [PATCH 1/2] Changed constant google credentials path and token path --- setup.py | 2 +- src/sayvai_tools/utils/google/gcalendar.py | 10 ++++++---- src/sayvai_tools/utils/google/sheets.py | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 769933e..ea45dec 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ ] setup( - name="sayvai_tools", + name="sayvai-tools", version="0.0.1", description="Tools for the assistant", author="sayvai-io", diff --git a/src/sayvai_tools/utils/google/gcalendar.py b/src/sayvai_tools/utils/google/gcalendar.py index 8f25857..50a8a16 100644 --- a/src/sayvai_tools/utils/google/gcalendar.py +++ b/src/sayvai_tools/utils/google/gcalendar.py @@ -25,8 +25,10 @@ def __init__(self, scope: str, summary=None, email=None) -> None: self.calendar_id = "primary" self.organizer_email = email self.summary = summary - if os.path.exists("token.json"): - self.creds = Credentials.from_authorized_user_file("token.json", self.SCOPE) + self.token_path = os.environ["GTOKEN_PATH"] + self.credential_path = os.environ["GOOGLE_CREDENTIALS_PATH"] + if os.path.exists(self.token_path): + self.creds = Credentials.from_authorized_user_file(self.token_path, self.SCOPE) else: self.get_credentials() # if self.creds and self.creds.expired and self.creds.refresh_token: @@ -35,10 +37,10 @@ def __init__(self, scope: str, summary=None, email=None) -> None: def get_credentials(self): """Gets the credentials for the user""" - flow = InstalledAppFlow.from_client_secrets_file("credentials.json", self.SCOPE) + flow = InstalledAppFlow.from_client_secrets_file(self.credential_path, self.SCOPE) self.creds = flow.run_local_server(port=0) - with open("token.json", "w") as token: + with open(self.token_path, "w") as token: token.write(self.creds.to_json()) return "Credentials obtained" diff --git a/src/sayvai_tools/utils/google/sheets.py b/src/sayvai_tools/utils/google/sheets.py index 1ad20dc..52c8580 100644 --- a/src/sayvai_tools/utils/google/sheets.py +++ b/src/sayvai_tools/utils/google/sheets.py @@ -10,10 +10,10 @@ class GSheets: def __init__(self) -> None: self.gc, _user = self.authenticate() - pass + self.credential_path = os.environ["GOOGLE_CREDENTIALS_PATH"] def get_credentials(self): - with open("credentials.json") as f: + with open(self.credential_path) as f: data = json.load(f) return data From 83b609193e5f695f5af7823642b0346f1c16da68 Mon Sep 17 00:00:00 2001 From: prakashr7d Date: Fri, 10 Nov 2023 22:21:28 +0530 Subject: [PATCH 2/2] added os in sheets --- src/sayvai_tools/utils/google/sheets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sayvai_tools/utils/google/sheets.py b/src/sayvai_tools/utils/google/sheets.py index 52c8580..4a6af54 100644 --- a/src/sayvai_tools/utils/google/sheets.py +++ b/src/sayvai_tools/utils/google/sheets.py @@ -3,6 +3,7 @@ import gspread import datetime from gspread import utils +import os class GSheets: