Spaces:
Runtime error
Runtime error
File size: 2,066 Bytes
17c62ae 7c1c59d 17c62ae 444fe60 17c62ae a7abf85 2ed1fc7 17c62ae 269dff6 fd87d4c 4258c85 7c1c59d 269dff6 fd87d4c 7c1c59d 269dff6 7c1c59d a7abf85 17c62ae 444fe60 17c62ae a7abf85 17c62ae e896c97 a7abf85 17c62ae a7abf85 17c62ae a7abf85 17c62ae a7abf85 7c1c59d 17c62ae a7abf85 17c62ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import os
from flask import Flask, render_template, request, redirect
from simple_salesforce import Salesforce
# Initialize Flask app
app = Flask(__name__)
# Securely store the secret key
app.secret_key = os.environ.get('FLASK_SECRET_KEY', 'your_secret_key')
# Fetch Salesforce credentials correctly (QUOTED STRINGS!)
SF_USERNAME = os.environ.get("SF_USERNAME", "[email protected]")
SF_PASSWORD = os.environ.get("SF_PASSWORD", "Sati@1020")
SF_SECURITY_TOKEN = os.environ.get("SF_SECURITY_TOKEN", "sSSjyhInIsUohKpG8sHzty2q")
# Debugging: Print credentials safely
print(f"Using Salesforce Username: {SF_USERNAME}")
# Establish Salesforce connection
try:
sf = Salesforce(
username=SF_USERNAME,
password=SF_PASSWORD,
security_token=SF_SECURITY_TOKEN
)
print("✅ Salesforce connection established successfully.")
except Exception as e:
print(f"❌ ERROR: Failed to connect to Salesforce: {str(e)}")
exit(1)
@app.route("/")
def home():
return redirect("/menu") # Redirect home page to menu page
@app.route("/menu")
def menu():
selected_category = request.args.get("category", "All")
try:
# Salesforce SOQL Query
query = "SELECT Name, Price__c, Image1__c, Category__c, Description__c FROM Menu_Item__c"
result = sf.query(query)
# Extract menu items
food_items = result.get('records', [])
# Extract unique categories
categories = {item['Category__c'] for item in food_items if 'Category__c' in item}
# Filter by category if selected
if selected_category != "All":
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
except Exception as e:
food_items = []
categories = []
print(f"❌ ERROR: Fetching data from Salesforce failed: {e}")
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860, debug=True)
|