Skip to content

Commit

Permalink
Merge pull request #43 from Sayvai-io/patch
Browse files Browse the repository at this point in the history
Patch
  • Loading branch information
Sanjaypranav authored Nov 10, 2023
2 parents 227afea + 83b6091 commit 931993f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]

setup(
name="sayvai_tools",
name="sayvai-tools",
version="0.0.1",
description="Tools for the assistant",
author="sayvai-io",
Expand Down
10 changes: 6 additions & 4 deletions src/sayvai_tools/utils/google/gcalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/sayvai_tools/utils/google/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import gspread
import datetime
from gspread import utils
import os


class GSheets:
"""Google Sheets API""" ""

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

Expand Down

0 comments on commit 931993f

Please sign in to comment.