Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -411,27 +411,31 @@ class CoachingCodeRequest(BaseModel):
|
|
| 411 |
|
| 412 |
# Function to get credentials
|
| 413 |
def get_credentials():
|
|
|
|
| 414 |
try:
|
|
|
|
| 415 |
service_account_info = {
|
| 416 |
-
"type":
|
| 417 |
-
"project_id":
|
| 418 |
-
"private_key_id":
|
| 419 |
-
"private_key":
|
| 420 |
-
"client_email":
|
| 421 |
-
"client_id":
|
| 422 |
-
"auth_uri":
|
| 423 |
-
"token_uri":
|
| 424 |
-
"auth_provider_x509_cert_url":
|
| 425 |
-
"client_x509_cert_url":
|
| 426 |
-
"universe_domain":
|
| 427 |
}
|
| 428 |
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
| 429 |
creds = Credentials.from_service_account_info(service_account_info, scopes=scope)
|
| 430 |
return creds
|
|
|
|
| 431 |
except Exception as e:
|
| 432 |
print(f"Error getting credentials: {e}")
|
| 433 |
return None
|
| 434 |
|
|
|
|
| 435 |
# Select files based on coaching code
|
| 436 |
def select_files(coaching_code):
|
| 437 |
creds = get_credentials()
|
|
|
|
| 411 |
|
| 412 |
# Function to get credentials
|
| 413 |
def get_credentials():
|
| 414 |
+
"""Get Google Sheets API credentials from environment variables."""
|
| 415 |
try:
|
| 416 |
+
# Construct the service account info dictionary
|
| 417 |
service_account_info = {
|
| 418 |
+
"type": os.getenv("SERVICE_ACCOUNT_TYPE"),
|
| 419 |
+
"project_id": os.getenv("PROJECT_ID"),
|
| 420 |
+
"private_key_id": os.getenv("PRIVATE_KEY_ID"),
|
| 421 |
+
"private_key": os.getenv("PRIVATE_KEY").replace('\\n', '\n'),
|
| 422 |
+
"client_email": os.getenv("CLIENT_EMAIL"),
|
| 423 |
+
"client_id": os.getenv("CLIENT_ID"),
|
| 424 |
+
"auth_uri": os.getenv("AUTH_URI"),
|
| 425 |
+
"token_uri": os.getenv("TOKEN_URI"),
|
| 426 |
+
"auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"),
|
| 427 |
+
"client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL"),
|
| 428 |
+
"universe_domain": os.getenv("UNIVERSE_DOMAIN")
|
| 429 |
}
|
| 430 |
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
| 431 |
creds = Credentials.from_service_account_info(service_account_info, scopes=scope)
|
| 432 |
return creds
|
| 433 |
+
|
| 434 |
except Exception as e:
|
| 435 |
print(f"Error getting credentials: {e}")
|
| 436 |
return None
|
| 437 |
|
| 438 |
+
|
| 439 |
# Select files based on coaching code
|
| 440 |
def select_files(coaching_code):
|
| 441 |
creds = get_credentials()
|