Rekham1110 commited on
Commit
7d214fd
·
verified ·
1 Parent(s): ea6167a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -21,7 +21,7 @@ API_KEY = os.getenv("API_KEY", "your-api-key-here")
21
 
22
  # Validate Salesforce credentials
23
  if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN ]):
24
- raise ValueError("Missing Salesforce credentials. Set SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN in environment variables.")
25
 
26
  # Initialize Salesforce connection
27
  try:
@@ -123,7 +123,7 @@ def process_image(image, project_name):
123
 
124
  # Validate image size and type
125
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
126
- if image_size_mb > 20:
127
  return "Error: Image size exceeds 20MB.", "Failure", "", "", 0
128
  if not image.lower().endswith(('.jpg', '.jpeg', '.png')):
129
  return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
@@ -133,7 +133,7 @@ def process_image(image, project_name):
133
 
134
  # Update Salesforce record
135
  record = {
136
- "Name": project_name,
137
  "Current_Milestone__c": milestone,
138
  "Completion_Percentage__c": percent_complete,
139
  "Last_Updated_On__c": datetime.now().isoformat(),
@@ -142,13 +142,15 @@ def process_image(image, project_name):
142
  }
143
 
144
  try:
145
- query = f"SELECT Id FROM Construction_Project__c WHERE Name = '{project_name}'"
 
 
146
  result = sf.query(query)
147
  if result["totalSize"] > 0:
148
  project_id = result["records"][0]["Id"]
149
- sf.Construction_Project__c.update(project_id, record)
150
  else:
151
- sf.Construction_Project__c.create(record)
152
  except Exception as e:
153
  return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
154
 
 
21
 
22
  # Validate Salesforce credentials
23
  if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN ]):
24
+ raise ValueError("Missing Salesforce credentials. Set SF_USERNAME, SF_PASSWORD SF_SECURITY_TOKEN in environment variables.")
25
 
26
  # Initialize Salesforce connection
27
  try:
 
123
 
124
  # Validate image size and type
125
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
126
+ if image_size_mb_tb > 20:
127
  return "Error: Image size exceeds 20MB.", "Failure", "", "", 0
128
  if not image.lower().endswith(('.jpg', '.jpeg', '.png')):
129
  return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
 
133
 
134
  # Update Salesforce record
135
  record = {
136
+ "Name__c": project_name, # Changed from "Name" to "Name__c"
137
  "Current_Milestone__c": milestone,
138
  "Completion_Percentage__c": percent_complete,
139
  "Last_Updated_On__c": datetime.now().isoformat(),
 
142
  }
143
 
144
  try:
145
+ # Escape single quotes in project_name to prevent SQL injection
146
+ escaped_project_name = project_name.replace("'", "''")
147
+ query = f"SELECT Id FROM Construction__c WHERE Name__c = '{escaped_project_name}'"
148
  result = sf.query(query)
149
  if result["totalSize"] > 0:
150
  project_id = result["records"][0]["Id"]
151
+ sf.Construction__c.update(project_id, record)
152
  else:
153
+ sf.Construction__c.create(record)
154
  except Exception as e:
155
  return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
156