Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
-
import
|
| 5 |
|
| 6 |
# ---------------------- CONFIG ----------------------
|
| 7 |
CLIENT_ID = "3MVG9VMBZCsTL9hnfx2eVMOHa56mwSZnvuAnPr3kVVBEQfeLYvrSfJNRRjjSlKWPLy99XM6kefg=="
|
| 8 |
CLIENT_SECRET = "6F7E9C95CE20CC07FC1EBD39B34909739D99975A0EEB548240926EA0686E428E"
|
| 9 |
USERNAME = "greenenergy@vedavathi.com"
|
| 10 |
-
PASSWORD = "Vedavathi@04"
|
|
|
|
| 11 |
TOKEN_URL = "https://login.salesforce.com/services/oauth2/token"
|
| 12 |
API_VERSION = "v60.0"
|
| 13 |
|
|
@@ -15,15 +16,15 @@ API_VERSION = "v60.0"
|
|
| 15 |
@st.cache_data
|
| 16 |
def get_salesforce_token():
|
| 17 |
data = {
|
| 18 |
-
"grant_type": "
|
| 19 |
-
"client_id":
|
| 20 |
-
"client_secret":
|
| 21 |
-
"username":
|
| 22 |
-
"password":
|
| 23 |
}
|
| 24 |
response = requests.post(TOKEN_URL, data=data)
|
| 25 |
if response.status_code != 200:
|
| 26 |
-
st.error("Authentication failed!")
|
| 27 |
return None, None
|
| 28 |
res = response.json()
|
| 29 |
return res["access_token"], res["instance_url"]
|
|
@@ -33,7 +34,7 @@ def fetch_pole_data(instance_url, access_token):
|
|
| 33 |
headers = {
|
| 34 |
"Authorization": f"Bearer {access_token}"
|
| 35 |
}
|
| 36 |
-
query = "SELECT Name, Location_Latitude__c,
|
| 37 |
url = f"{instance_url}/services/data/{API_VERSION}/query?q={query}"
|
| 38 |
response = requests.get(url, headers=headers)
|
| 39 |
if response.status_code != 200:
|
|
@@ -41,7 +42,7 @@ def fetch_pole_data(instance_url, access_token):
|
|
| 41 |
return pd.DataFrame()
|
| 42 |
records = response.json().get("records", [])
|
| 43 |
df = pd.DataFrame(records)
|
| 44 |
-
return df[[
|
| 45 |
|
| 46 |
# ---------------------- UI ----------------------
|
| 47 |
st.title("🚦Vedavathi Smart Poles Viewer")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
+
import simple_salesforce
|
| 5 |
|
| 6 |
# ---------------------- CONFIG ----------------------
|
| 7 |
CLIENT_ID = "3MVG9VMBZCsTL9hnfx2eVMOHa56mwSZnvuAnPr3kVVBEQfeLYvrSfJNRRjjSlKWPLy99XM6kefg=="
|
| 8 |
CLIENT_SECRET = "6F7E9C95CE20CC07FC1EBD39B34909739D99975A0EEB548240926EA0686E428E"
|
| 9 |
USERNAME = "greenenergy@vedavathi.com"
|
| 10 |
+
PASSWORD = "Vedavathi@04" # Keep this as the password (without the security token)
|
| 11 |
+
SECURITY_TOKEN = "qe4His8AcuFJucZz5NBHfGU" # Your Salesforce Security Token
|
| 12 |
TOKEN_URL = "https://login.salesforce.com/services/oauth2/token"
|
| 13 |
API_VERSION = "v60.0"
|
| 14 |
|
|
|
|
| 16 |
@st.cache_data
|
| 17 |
def get_salesforce_token():
|
| 18 |
data = {
|
| 19 |
+
"grant_type": "password", # Corrected grant_type
|
| 20 |
+
"client_id": CLIENT_ID,
|
| 21 |
+
"client_secret": CLIENT_SECRET,
|
| 22 |
+
"username": USERNAME,
|
| 23 |
+
"password": PASSWORD + SECURITY_TOKEN # Correctly concatenate password and security token
|
| 24 |
}
|
| 25 |
response = requests.post(TOKEN_URL, data=data)
|
| 26 |
if response.status_code != 200:
|
| 27 |
+
st.error(f"Authentication failed! Status code: {response.status_code}, Message: {response.text}")
|
| 28 |
return None, None
|
| 29 |
res = response.json()
|
| 30 |
return res["access_token"], res["instance_url"]
|
|
|
|
| 34 |
headers = {
|
| 35 |
"Authorization": f"Bearer {access_token}"
|
| 36 |
}
|
| 37 |
+
query = "SELECT Name, Location_Latitude__c, Location_Longitude__c, Camera_Status__c FROM Pole__c LIMIT 100"
|
| 38 |
url = f"{instance_url}/services/data/{API_VERSION}/query?q={query}"
|
| 39 |
response = requests.get(url, headers=headers)
|
| 40 |
if response.status_code != 200:
|
|
|
|
| 42 |
return pd.DataFrame()
|
| 43 |
records = response.json().get("records", [])
|
| 44 |
df = pd.DataFrame(records)
|
| 45 |
+
return df[["Name", "Location_Latitude__c", "Location_Longitude__c", "Camera_Status__c"]]
|
| 46 |
|
| 47 |
# ---------------------- UI ----------------------
|
| 48 |
st.title("🚦Vedavathi Smart Poles Viewer")
|