Rakshitjan commited on
Commit
8ca33c0
·
verified ·
1 Parent(s): 3ce6086

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -11
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": userdata.get("SERVICE_ACCOUNT_TYPE"),
417
- "project_id": userdata.get("PROJECT_ID"),
418
- "private_key_id": userdata.get("PRIVATE_KEY_ID"),
419
- "private_key": userdata.get("PRIVATE_KEY").replace('\\n', '\n'),
420
- "client_email": userdata.get("CLIENT_EMAIL"),
421
- "client_id": userdata.get("CLIENT_ID"),
422
- "auth_uri": userdata.get("AUTH_URI"),
423
- "token_uri": userdata.get("TOKEN_URI"),
424
- "auth_provider_x509_cert_url": userdata.get("AUTH_PROVIDER_X509_CERT_URL"),
425
- "client_x509_cert_url": userdata.get("CLIENT_X509_CERT_URL"),
426
- "universe_domain": userdata.get("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()