Spaces:
Runtime error
Runtime error
Update services/salesforce_dispatcher.py
Browse files
services/salesforce_dispatcher.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import json
|
2 |
import os
|
3 |
import logging
|
4 |
-
from
|
5 |
|
6 |
# Setup logging
|
7 |
logging.basicConfig(
|
@@ -10,32 +10,13 @@ logging.basicConfig(
|
|
10 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
11 |
)
|
12 |
|
13 |
-
|
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 |
-
|
20 |
Args:
|
21 |
-
|
22 |
-
timestamp: Timestamp of the detection
|
23 |
"""
|
24 |
try:
|
25 |
-
|
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)}")
|
|
|
1 |
import json
|
2 |
import os
|
3 |
import logging
|
4 |
+
from typing import Dict, Any
|
5 |
|
6 |
# Setup logging
|
7 |
logging.basicConfig(
|
|
|
10 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
11 |
)
|
12 |
|
13 |
+
def send_to_salesforce(payload: Dict[str, Any]) -> None:
|
|
|
|
|
|
|
|
|
14 |
"""
|
15 |
+
Simulated Salesforce integration by logging to console.
|
16 |
Args:
|
17 |
+
payload: Dict containing detection data (items, metrics, etc.)
|
|
|
18 |
"""
|
19 |
try:
|
20 |
+
logging.info(f"Salesforce Dispatch Simulated: {json.dumps(payload, indent=2)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
except Exception as e:
|
22 |
logging.error(f"Error dispatching to Salesforce: {str(e)}")
|