File size: 2,176 Bytes
17c62ae
7c1c59d
17c62ae
444fe60
17c62ae
a7abf85
2ed1fc7
17c62ae
 
 
2c788bc
 
 
 
7c1c59d
2c788bc
7c1c59d
2c788bc
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
63
64
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 (WRAPPED IN QUOTES)
SF_USERNAME = os.environ.get("[email protected]")
SF_PASSWORD = os.environ.get("Sati@1020")
SF_SECURITY_TOKEN = os.environ.get("sSSjyhInIsUohKpG8sHzty2q")

# Debugging: Check if credentials exist
if not SF_USERNAME or not SF_PASSWORD or not SF_SECURITY_TOKEN:
    print("❌ ERROR: Missing Salesforce credentials. Please set SF_USERNAME, SF_PASSWORD, and SF_SECURITY_TOKEN.")
    exit(1)

# Establish Salesforce connection
try:
    sf = Salesforce(
        [email protected],
        password=Sati@1020,
        security_token=sSSjyhInIsUohKpG8sHzty2q
    )
    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)