Spaces:
Runtime error
Runtime error
| 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 | |