Spaces:
Sleeping
Sleeping
Create salesforce_integration.py
Browse files- salesforce_integration.py +39 -0
salesforce_integration.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from simple_salesforce import Salesforce
|
2 |
+
|
3 |
+
# Salesforce Authentication
|
4 |
+
def authenticate_salesforce():
|
5 |
+
return Salesforce(username='[email protected]', password='Vedavathi@04', security_token='jqe4His8AcuFJucZz5NBHfGU')
|
6 |
+
|
7 |
+
# Fetch data from Salesforce custom objects (Pole, Sensor Data, Alerts)
|
8 |
+
def fetch_salesforce_data(site_name):
|
9 |
+
sf = authenticate_salesforce()
|
10 |
+
|
11 |
+
# Salesforce SOQL Query to get pole data based on the site
|
12 |
+
query = f"""
|
13 |
+
SELECT Id, Name, Solar_kWh__c, Wind_kWh__c, Power_Required__c, Power_Status__c, Tilt_Angle__c,
|
14 |
+
Vibration__c, Camera_Status__c, Alert_Level__c, Health_Score__c, Last_Checked__c
|
15 |
+
FROM Pole__c
|
16 |
+
WHERE Site__c = '{site_name}'
|
17 |
+
"""
|
18 |
+
response = sf.query(query)
|
19 |
+
data = response['records']
|
20 |
+
|
21 |
+
# Return the data in a usable format
|
22 |
+
return [
|
23 |
+
{
|
24 |
+
'Pole ID': record['Name'],
|
25 |
+
'Site': site_name,
|
26 |
+
'Solar (kWh)': record['Solar_kWh__c'],
|
27 |
+
'Wind (kWh)': record['Wind_kWh__c'],
|
28 |
+
'Power Required (kWh)': record['Power_Required__c'],
|
29 |
+
'Power Status': record['Power_Status__c'],
|
30 |
+
'Tilt Angle (°)': record['Tilt_Angle__c'],
|
31 |
+
'Vibration (g)': record['Vibration__c'],
|
32 |
+
'Camera Status': record['Camera_Status__c'],
|
33 |
+
'Health Score': record['Health_Score__c'],
|
34 |
+
'Alert Level': record['Alert_Level__c'],
|
35 |
+
'Anomalies': "", # Can be filled if necessary
|
36 |
+
'Last Checked': record['Last_Checked__c']
|
37 |
+
}
|
38 |
+
for record in data
|
39 |
+
]
|