RathodHarish commited on
Commit
a531ca7
·
verified ·
1 Parent(s): e8bdc91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -23,8 +23,8 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
23
  # Salesforce configuration
24
  try:
25
  sf = Salesforce(
26
- username=os.getenv('SF_USERNAME'),
27
- password=os.getenv('SF_PASSWORD'),
28
  security_token=os.getenv('SF_SECURITY_TOKEN'),
29
  domain='login'
30
  )
@@ -33,13 +33,13 @@ except Exception as e:
33
  logging.error(f"Failed to connect to Salesforce: {str(e)}")
34
  sf = None
35
 
36
- # Email configuration (using environment variables)
37
  SMTP_SERVER = os.getenv('SMTP_SERVER', 'smtp.gmail.com')
38
  SMTP_PORT = int(os.getenv('SMTP_PORT', 587))
39
- SMTP_USERNAME = os.getenv('harishkumarr@sathkrutha.com') # e.g., your-email@gmail.com
40
- SMTP_PASSWORD = os.getenv('Harish@048') # App-specific password if using Gmail
41
- EMAIL_FROM = os.getenv('harishkumarr@sathkrutha.com', SMTP_USERNAME)
42
- EMAIL_TO = "harishkumarr@sathkrutha.com"
43
 
44
  # Try to import reportlab
45
  try:
@@ -135,8 +135,8 @@ def send_amc_reminder_emails(reminders_df):
135
  logging.info("No AMC reminders to send via email.")
136
  return "No AMC reminder emails sent (no reminders found)."
137
 
138
- if not all([SMTP_USERNAME, SMTP_PASSWORD, EMAIL_FROM]):
139
- logging.error("SMTP credentials not configured. Please set SMTP_USERNAME, SMTP_PASSWORD, and EMAIL_FROM environment variables.")
140
  return "Failed to send emails: SMTP credentials not configured."
141
 
142
  try:
@@ -157,7 +157,7 @@ def send_amc_reminder_emails(reminders_df):
157
  msg['Subject'] = f"AMC Reminder for Device {device_id}"
158
 
159
  body = f"""
160
- Dear Harish Kumar,
161
 
162
  This is a reminder that the Annual Maintenance Contract (AMC) for the following device is due:
163
 
@@ -167,6 +167,7 @@ This is a reminder that the Annual Maintenance Contract (AMC) for the following
167
  Please schedule the maintenance at your earliest convenience.
168
 
169
  Best regards,
 
170
  LabOps Team
171
  """
172
  msg.attach(MIMEText(body, 'plain'))
@@ -215,6 +216,7 @@ def create_salesforce_reports(df):
215
  "folderId": LABOPS_REPORTS_FOLDER_ID
216
  }
217
  }
 
218
  usage_result = sf.restful('analytics/reports', method='POST', json=usage_report_metadata)
219
  usage_report_id = usage_result['id']
220
  logging.info(f"Usage Report created: {usage_report_id}")
@@ -238,6 +240,7 @@ def create_salesforce_reports(df):
238
  "folderId": LABOPS_REPORTS_FOLDER_ID
239
  }
240
  }
 
241
  amc_result = sf.restful('analytics/reports', method='POST', json=amc_report_metadata)
242
  amc_report_id = amc_result['id']
243
  logging.info(f"AMC Reminders Report created: {amc_report_id}")
 
23
  # Salesforce configuration
24
  try:
25
  sf = Salesforce(
26
+ username=os.getenv('SF_USERNAME', 'multi-devicelabopsdashboard@sathkrutha.com'),
27
+ password=os.getenv('SF_PASSWORD', 'Team@1234'),
28
  security_token=os.getenv('SF_SECURITY_TOKEN'),
29
  domain='login'
30
  )
 
33
  logging.error(f"Failed to connect to Salesforce: {str(e)}")
34
  sf = None
35
 
36
+ # Email configuration
37
  SMTP_SERVER = os.getenv('SMTP_SERVER', 'smtp.gmail.com')
38
  SMTP_PORT = int(os.getenv('SMTP_PORT', 587))
39
+ SMTP_USERNAME = os.getenv('SMTP_USERNAME') # e.g., harishkumarr@sathkrutha.com
40
+ SMTP_PASSWORD = os.getenv('SMTP_PASSWORD') # App-specific password
41
+ EMAIL_FROM = "harishkumarr@sathkrutha.com"
42
+ EMAIL_TO = "sanjaybhargavneela@sathkrutha.com"
43
 
44
  # Try to import reportlab
45
  try:
 
135
  logging.info("No AMC reminders to send via email.")
136
  return "No AMC reminder emails sent (no reminders found)."
137
 
138
+ if not all([SMTP_USERNAME, SMTP_PASSWORD]):
139
+ logging.error("SMTP credentials not configured. Please set SMTP_USERNAME and SMTP_PASSWORD environment variables.")
140
  return "Failed to send emails: SMTP credentials not configured."
141
 
142
  try:
 
157
  msg['Subject'] = f"AMC Reminder for Device {device_id}"
158
 
159
  body = f"""
160
+ Dear Sanjay Bhargav Neela,
161
 
162
  This is a reminder that the Annual Maintenance Contract (AMC) for the following device is due:
163
 
 
167
  Please schedule the maintenance at your earliest convenience.
168
 
169
  Best regards,
170
+ Harish Kumar
171
  LabOps Team
172
  """
173
  msg.attach(MIMEText(body, 'plain'))
 
216
  "folderId": LABOPS_REPORTS_FOLDER_ID
217
  }
218
  }
219
+ logging.info(f"Creating Usage Report with metadata: {json.dumps(usage_report_metadata, indent=2)}")
220
  usage_result = sf.restful('analytics/reports', method='POST', json=usage_report_metadata)
221
  usage_report_id = usage_result['id']
222
  logging.info(f"Usage Report created: {usage_report_id}")
 
240
  "folderId": LABOPS_REPORTS_FOLDER_ID
241
  }
242
  }
243
+ logging.info(f"Creating AMC Reminders Report with metadata: {json.dumps(amc_report_metadata, indent=2)}")
244
  amc_result = sf.restful('analytics/reports', method='POST', json=amc_report_metadata)
245
  amc_report_id = amc_result['id']
246
  logging.info(f"AMC Reminders Report created: {amc_report_id}")