harshSethi commited on
Commit
97ebadb
·
verified ·
1 Parent(s): 2556b7c

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +12 -2
tools.py CHANGED
@@ -76,8 +76,18 @@ def saveTemplate(template:str):
76
  "https://www.googleapis.com/auth/spreadsheets"
77
  ]
78
 
79
- # Authorize using the service account credentials
80
- creds = Credentials.from_service_account_file("credentials.json", scopes=scopes)
 
 
 
 
 
 
 
 
 
 
81
  client = gspread.authorize(creds)
82
 
83
  # Open the workbook using the spreadsheet ID
 
76
  "https://www.googleapis.com/auth/spreadsheets"
77
  ]
78
 
79
+ json_string = os.getenv('credentials')
80
+ if not json_string:
81
+ return {"response": "Credentials not found in environment variable.", "status": "error"}
82
+
83
+ # Convert the string back to a JSON object
84
+ try:
85
+ credentials = json.loads(json_string)
86
+ except json.JSONDecodeError:
87
+ return {"response": "Failed to decode JSON credentials.", "status": "error"}
88
+
89
+ # Create credentials from the JSON object
90
+ creds = Credentials.from_service_account_info(credentials, scopes=scopes)
91
  client = gspread.authorize(creds)
92
 
93
  # Open the workbook using the spreadsheet ID