geethareddy commited on
Commit
d51774d
·
verified ·
1 Parent(s): 3759223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -28
app.py CHANGED
@@ -10,16 +10,21 @@ from gtts import gTTS
10
  import time
11
 
12
  app = Flask(__name__)
13
- logging.basicConfig(level=logging.INFO)
14
-
15
- # Salesforce connection setup (ensure this is correct)
16
- sf = Salesforce(
17
- username='diggavalli98@gmail.com',
18
- password='Sati@1020',
19
- security_token='sSSjyhInIsUohKpG8sHzty2q',
20
- consumer_key='3MVG9WVXk15qiz1JbtW1tT9a7Wnkos2RuGamw6p1lC5uPescT5NB2nPygpo6rQ87K1T.zBEn.wR.A6JdgHnIU',
21
- consumer_secret='A75C6B7801D5D20BED0E46631CF58C4F7FF28E4DAF442FE667553D29C35C0451'
22
- )
 
 
 
 
 
23
 
24
  # Global variables
25
  cart = [] # To store items, quantities, and prices
@@ -32,23 +37,25 @@ awaiting_quantity = False
32
  # Fetching menu items dynamically from Salesforce
33
  def get_menu_items():
34
  menu_items = {}
35
- # Querying the Menu_Item__c object to fetch details
36
- query = "SELECT Name, Category__c, Price__c, Ingredients__c FROM Menu_Item__c"
37
- results = sf.query_all(query)
38
-
39
- # Organizing the menu items by category
40
- for record in results['records']:
41
- category = record['Category__c']
42
- item_name = record['Name']
43
- price = record['Price__c']
44
-
45
- if category not in menu_items:
46
- menu_items[category] = {}
47
- menu_items[category][item_name] = price
48
-
49
- return menu_items
50
-
51
- # Update global MENU variable
 
 
52
  MENU = get_menu_items()
53
 
54
  # HTML Template for Frontend (for register, login, and menu pages)
@@ -157,8 +164,10 @@ def register():
157
  'Email__c': email,
158
  'Phone_Number__c': phone
159
  })
 
160
  return redirect(url_for('menu')) # Redirect to menu after successful registration
161
  except Exception as e:
 
162
  return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
163
 
164
  return render_template_string(html_code)
@@ -178,8 +187,10 @@ def login():
178
  customer_query = sf.query(f"SELECT Id, Name FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone}'")
179
  if customer_query['totalSize'] == 0:
180
  return jsonify({"error": "Customer not found."}), 404
 
181
  return redirect(url_for('menu')) # Redirect to menu after successful login
182
  except Exception as e:
 
183
  return jsonify({'error': f'Failed to query Salesforce: {str(e)}'}), 500
184
 
185
  return render_template_string(html_code)
@@ -225,6 +236,7 @@ def process_audio():
225
  except BadRequest as br:
226
  return jsonify({"response": f"Bad Request: {str(br)}"}), 400
227
  except Exception as e:
 
228
  return jsonify({"response": f"An error occurred: {str(e)}"}), 500
229
  finally:
230
  os.unlink(temp_file.name)
@@ -301,4 +313,4 @@ def process_command(command):
301
  return "Sorry, I didn't understand that. Please try again."
302
 
303
  if __name__ == "__main__":
304
- app.run(host="0.0.0.0", port=7860)
 
10
  import time
11
 
12
  app = Flask(__name__)
13
+ logging.basicConfig(level=logging.DEBUG)
14
+
15
+ # Salesforce connection setup
16
+ try:
17
+ sf = Salesforce(
18
+ username='diggavalli98@gmail.com',
19
+ password='Sati@1020',
20
+ security_token='sSSjyhInIsUohKpG8sHzty2q',
21
+ consumer_key='3MVG9WVXk15qiz1JbtW1tT9a7Wnkos2RuGamw6p1lC5uPescT5NB2nPygpo6rQ87K1T.zBEn.wR.A6JdgHnIU',
22
+ consumer_secret='A75C6B7801D5D20BED0E46631CF58C4F7FF28E4DAF442FE667553D29C35C0451'
23
+ )
24
+ logging.info("Successfully connected to Salesforce")
25
+ except Exception as e:
26
+ logging.error(f"Error connecting to Salesforce: {str(e)}")
27
+ sf = None
28
 
29
  # Global variables
30
  cart = [] # To store items, quantities, and prices
 
37
  # Fetching menu items dynamically from Salesforce
38
  def get_menu_items():
39
  menu_items = {}
40
+ try:
41
+ query = "SELECT Name, Category__c, Price__c, Ingredients__c FROM Menu_Item__c"
42
+ results = sf.query_all(query)
43
+
44
+ # Organizing the menu items by category
45
+ for record in results['records']:
46
+ category = record['Category__c']
47
+ item_name = record['Name']
48
+ price = record['Price__c']
49
+
50
+ if category not in menu_items:
51
+ menu_items[category] = {}
52
+ menu_items[category][item_name] = price
53
+
54
+ return menu_items
55
+ except Exception as e:
56
+ logging.error(f"Error fetching menu items from Salesforce: {str(e)}")
57
+ return {}
58
+
59
  MENU = get_menu_items()
60
 
61
  # HTML Template for Frontend (for register, login, and menu pages)
 
164
  'Email__c': email,
165
  'Phone_Number__c': phone
166
  })
167
+ logging.info("Customer registered successfully")
168
  return redirect(url_for('menu')) # Redirect to menu after successful registration
169
  except Exception as e:
170
+ logging.error(f"Error during registration: {str(e)}")
171
  return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
172
 
173
  return render_template_string(html_code)
 
187
  customer_query = sf.query(f"SELECT Id, Name FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone}'")
188
  if customer_query['totalSize'] == 0:
189
  return jsonify({"error": "Customer not found."}), 404
190
+ logging.info("Customer logged in successfully")
191
  return redirect(url_for('menu')) # Redirect to menu after successful login
192
  except Exception as e:
193
+ logging.error(f"Error during login: {str(e)}")
194
  return jsonify({'error': f'Failed to query Salesforce: {str(e)}'}), 500
195
 
196
  return render_template_string(html_code)
 
236
  except BadRequest as br:
237
  return jsonify({"response": f"Bad Request: {str(br)}"}), 400
238
  except Exception as e:
239
+ logging.error(f"Error processing audio: {str(e)}")
240
  return jsonify({"response": f"An error occurred: {str(e)}"}), 500
241
  finally:
242
  os.unlink(temp_file.name)
 
313
  return "Sorry, I didn't understand that. Please try again."
314
 
315
  if __name__ == "__main__":
316
+ app.run(host="0.0.0.0", port=7860)