Spaces:
Runtime error
Runtime error
File size: 2,577 Bytes
54f831b fc7416b bc1fd1a e8fd9dc e033ca1 fc7416b 54f831b fc7416b 0279e41 fc7416b 54f831b fc7416b 54f831b fc7416b |
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 |
from simple_salesforce import Salesforce
# Salesforce Connection
sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
# Function to fetch menu items from Salesforce
def load_menu_from_salesforce():
try:
query = "SELECT Name, Price__c, Description__c, Image1__c, Ingredients__c FROM Menu_Item__c"
result = sf.query(query)
return result['records']
except Exception as e:
raise ValueError(f"Error loading menu data from Salesforce: {e}")
# Function to filter menu items based on preference
def filter_menu_from_salesforce(preference):
menu_data = load_menu_from_salesforce()
filtered_data = []
for item in menu_data:
if preference == "Halal/Non-Veg":
if any(x in item.get("Ingredients__c", "").lower() for x in ["chicken", "mutton", "fish", "prawns", "goat"]):
filtered_data.append(item)
elif preference == "Vegetarian":
if not any(x in item.get("Ingredients__c", "").lower() for x in ["chicken", "mutton", "fish", "prawns", "goat"]):
filtered_data.append(item)
elif preference == "Guilt-Free":
if "fat:" in item.get("Description__c", "").lower():
filtered_data.append(item)
else:
filtered_data = menu_data
# Generate HTML content
html_content = ""
for item in filtered_data:
html_content += f"""
<div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
<div style="flex: 1; margin-right: 15px;">
<h3 style="margin: 0; font-size: 18px;">{item['Name']}</h3>
<p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
<p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description__c']}</p>
</div>
<div style="flex-shrink: 0; text-align: center;">
<img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
<button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Name']}', '{item['Image1__c']}', '{item['Description__c']}', '{item['Price__c']}')">Add</button>
</div>
</div>
"""
return html_content
|