import os import json from google.oauth2.service_account import Credentials import gspread def connect_sheet(): creds_dict = json.loads(os.environ["GOOGLE_CREDENTIALS"]) credentials = Credentials.from_service_account_info( creds_dict, scopes=[ "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive" ] ) client = gspread.authorize(credentials) sheet = client.open_by_key("YOUR_SHEET_ID").sheet1 return sheet