lokesh341 commited on
Commit
ab8a910
·
1 Parent(s): 7a73535

Update services/salesforce_dispatcher.py

Browse files
Files changed (1) hide show
  1. services/salesforce_dispatcher.py +29 -17
services/salesforce_dispatcher.py CHANGED
@@ -1,29 +1,41 @@
1
- # services/salesforce_dispatcher.py
2
  import json
 
3
  import logging
 
4
 
5
- # Configure logging
6
- logging.basicConfig(level=logging.INFO)
7
- logger = logging.getLogger(__name__)
 
 
 
 
 
 
 
8
 
9
  def dispatch_to_salesforce(detections, timestamp):
10
  """
11
- Dispatch detection data to Salesforce.
12
  Args:
13
- detections: Detection dictionary
14
- timestamp: Timestamp of the frame
15
- Returns:
16
- bool: Success status
17
  """
18
  try:
19
- # Mock Salesforce dispatch (replace with actual Salesforce API calls)
20
- payload = {
21
  "timestamp": timestamp,
22
- "detections": detections
 
 
 
23
  }
24
- logger.info(f"Dispatching to Salesforce: {json.dumps(payload, indent=2)}")
25
- # Example: Use simple_salesforce or requests to send data to Salesforce
26
- return True
 
 
 
 
27
  except Exception as e:
28
- logger.error(f"Failed to dispatch to Salesforce: {str(e)}")
29
- return False
 
 
1
  import json
2
+ import os
3
  import logging
4
+ from datetime import datetime
5
 
6
+ # Setup logging
7
+ logging.basicConfig(
8
+ filename="app.log",
9
+ level=logging.INFO,
10
+ format="%(asctime)s - %(levelname)s - %(message)s"
11
+ )
12
+
13
+ # Directory for Salesforce logs
14
+ SALESFORCE_LOG_DIR = "salesforce_logs"
15
+ os.makedirs(SALESFORCE_LOG_DIR, exist_ok=True)
16
 
17
  def dispatch_to_salesforce(detections, timestamp):
18
  """
19
+ Dispatch detection data to Salesforce (simulated by logging to a JSON file).
20
  Args:
21
+ detections: Dict containing detection data (items, metrics, etc.)
22
+ timestamp: Timestamp of the detection
 
 
23
  """
24
  try:
25
+ # Prepare data
26
+ data = {
27
  "timestamp": timestamp,
28
+ "detections": detections["items"],
29
+ "metrics": detections["metrics"],
30
+ "frame_count": detections["frame_count"],
31
+ "gps_coordinates": detections["gps_coordinates"]
32
  }
33
+
34
+ # Write to JSON file
35
+ log_file = os.path.join(SALESFORCE_LOG_DIR, f"detections_{timestamp.replace(':', '-')}.json")
36
+ with open(log_file, "w") as f:
37
+ json.dump(data, f, indent=2)
38
+
39
+ logging.info(f"Dispatched detections to Salesforce log: {log_file}")
40
  except Exception as e:
41
+ logging.error(f"Error dispatching to Salesforce: {str(e)}")