2025-03-31 12:16:51 -04:00
|
|
|
from google.oauth2.service_account import Credentials
|
|
|
|
|
import gspread
|
|
|
|
|
import os
|
2025-04-17 17:39:58 -07:00
|
|
|
from dotenv import load_dotenv
|
2025-03-31 12:16:51 -04:00
|
|
|
|
2025-04-17 17:39:58 -07:00
|
|
|
load_dotenv()
|
2025-03-31 12:16:51 -04:00
|
|
|
|
|
|
|
|
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")
|
2025-04-17 17:39:58 -07:00
|
|
|
|
2025-03-31 12:16:51 -04:00
|
|
|
spreadsheet = client.open_by_url(spreadsheet_url)
|
|
|
|
|
return spreadsheet
|
2025-04-17 17:39:58 -07:00
|
|
|
|
|
|
|
|
|