AjaykumarPilla commited on
Commit
7f9e413
·
verified ·
1 Parent(s): 650f224

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -19
app.py CHANGED
@@ -19,16 +19,7 @@ SF_SECURITY_TOKEN = os.getenv('SF_SECURITY_TOKEN', 'your_salesforce_security_tok
19
  SF_INSTANCE_URL = os.getenv('SF_INSTANCE_URL', 'https://your_instance.salesforce.com')
20
 
21
  # Initialize Salesforce connection
22
- def connect_to_salesforce():
23
- try:
24
- sf = Salesforce(username=SF_USERNAME, password=SF_PASSWORD, security_token=SF_SECURITY_TOKEN, instance_url=SF_INSTANCE_URL)
25
- print("Connected to Salesforce successfully!")
26
- return sf
27
- except Exception as e:
28
- print(f"Error connecting to Salesforce: {str(e)}")
29
- return None
30
-
31
- sf = connect_to_salesforce()
32
 
33
  # Function to format high_risk_phases with flag and alert
34
  def format_high_risk_phases(high_risk_phases):
@@ -100,10 +91,6 @@ def generate_pdf(input_data, prediction, heatmap_fig):
100
 
101
  # Function to save data in Salesforce custom object (Delay_Predictor__c)
102
  def save_to_salesforce(input_data, prediction):
103
- if not sf:
104
- print("Salesforce connection not established.")
105
- return
106
-
107
  try:
108
  # Create record in Delay_Predictor__c object
109
  record = {
@@ -125,12 +112,9 @@ def save_to_salesforce(input_data, prediction):
125
  'Weather_Condition_Forecast__c': prediction['weather_condition']
126
  }
127
 
128
- # Debugging output: Print the record before attempting to insert into Salesforce
129
- print(f"Attempting to insert the following record: {record}")
130
-
131
  # Insert record into Salesforce
132
- result = sf.Delay_Predictor__c.create(record)
133
- print(f"Record saved to Salesforce successfully! Record ID: {result['id']}")
134
  except Exception as e:
135
  print(f"Error saving to Salesforce: {str(e)}")
136
 
 
19
  SF_INSTANCE_URL = os.getenv('SF_INSTANCE_URL', 'https://your_instance.salesforce.com')
20
 
21
  # Initialize Salesforce connection
22
+ sf = Salesforce(username=SF_USERNAME, password=SF_PASSWORD, security_token=SF_SECURITY_TOKEN, instance_url=SF_INSTANCE_URL)
 
 
 
 
 
 
 
 
 
23
 
24
  # Function to format high_risk_phases with flag and alert
25
  def format_high_risk_phases(high_risk_phases):
 
91
 
92
  # Function to save data in Salesforce custom object (Delay_Predictor__c)
93
  def save_to_salesforce(input_data, prediction):
 
 
 
 
94
  try:
95
  # Create record in Delay_Predictor__c object
96
  record = {
 
112
  'Weather_Condition_Forecast__c': prediction['weather_condition']
113
  }
114
 
 
 
 
115
  # Insert record into Salesforce
116
+ sf.Delay_Predictor__c.create(record)
117
+ print("Record saved to Salesforce successfully!")
118
  except Exception as e:
119
  print(f"Error saving to Salesforce: {str(e)}")
120