Files
poly-maker/poly_utils/google_utils.py
T
2025-03-31 12:16:51 -04:00

17 lines
659 B
Python

from google.oauth2.service_account import Credentials
import gspread
import os
def get_spreadsheet():
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
creds_file = 'credentials.json' if os.path.exists('credentials.json') else '../credentials.json'
credentials = Credentials.from_service_account_file(creds_file, scopes=scope)
client = gspread.authorize(credentials)
spreadsheet_url = os.getenv("SPREADSHEET_URL")
if not spreadsheet_url:
raise ValueError("SPREADSHEET_URL environment variable is not set")
spreadsheet = client.open_by_url(spreadsheet_url)
return spreadsheet