Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
@@ -76,8 +76,18 @@ def saveTemplate(template:str):
|
|
76 |
"https://www.googleapis.com/auth/spreadsheets"
|
77 |
]
|
78 |
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|