def delete(): body_data = request.json print(body_data) try: pizza_type = body_data['pizza'] print(pizza) if pizza_type == "" or pizza_type is None: return err.ReturnValueError() conn = connect.ConnectMySql() print(f'Connection status : {conn.is_connected()}') if (conn is False): return err.ReturnConnectionError() else: cur1 = conn.cursor() print(f'Cursor object : {cur1}') query = (f'DELETE from orderPizza where pizza_type="{pizza}"') cur1.execute(query) cur2 = conn.cursor() selectquery = SelectQuery() cur2.execute(selectquery) msg = "Data deleted succesfully" result = res.generateResponse(cur2, msg) conn.close() return result except KeyError as e: return err.ReturnKeyError() except Exception as e: print(e) return e
def fetch(): body_data = request.json print(body_data) try: status = body_data['status'] print(status) if status == "" or status is None: return err.ReturnValueError() conn = connect.ConnectMySql() print(f'Connection status : {conn.is_connected()}') if (conn is False): return ReturnConnectionError() else: cur = conn.cursor() print(f'Cursor object : {cur}') query = (f'SELECT * from orderPizza where status="{status}"') cur.execute(query) msg = "Fetched data succesfully" result = res.generateResponse(cur, msg) conn.close() return result except KeyError as e: return err.ReturnKeyError() except Exception as e: print(e) return err.ReturnFetchError()
def makeWebhookResult(req): if req.get("queryResult").get("action")=="input_details": pizzaord = connection.ConnectMySql() return() result = req.get("queryResult") parameters = result.get("parameters") orderid = parameters.get("orderid") name = parameters("name") pizza_name = parameters.get("pizza_name") pizza_size = parameters.get("pizza_size") pizza_type = parameters.get("pizza_type") name = parameter.get("name") mobileno = parameters.get("mobileno") Address = parameters.get("address") status = parameters.get("status") speech = "Orderid"+orderid +" "+ "Name" + name +" "+"Pizza name"+pizza_name+" "+"Pizza size" +pizza_size+ " " +"Pizza type"+ pizza_type+" " +"mobile no"+ mobileno+" "+ " Address"+address+"Status: ordered" print(speech) return { "fulfillmentText": speech, "fulfillmentText": speech, } if pizzaord is Flase: return err.ReturnConnectionError() else: try: mycursor = pizzadb.cursor() query = "select *from pizzaorder" mycursor.execute(query) myresult = mycursor.fetchall() print(myresult)
def webhook(): conn = connection.ConnectMySql() req = request.get_json(silent=True, force=True) res = makeWebhookResult(req) res = json.dumps(res, indent=4) print(res) r = make_response(res) print(r) r.headers['Content-Type'] = 'application/json' return r
def insert(): body_data = request.json print(body_data) try: pizza_type = body_data['pizza'] print(pizza_type) pizza_size = body_data['size'] print(pizza_size) pizza_count = body_data["count"] print(pizza_count) user_name = body_data['name'] print(user_name) mobile_number = body_data['number'] print(mobile_number) address = body_data['address'] print(address) status = body_data['status'] print(status) if (pizza == "" or pizza is None or size == "" or size is None or count == "" or count is None or price == "" or price is None or name == "" or name is None or number == "" or number is None or address == "" or address is None): return err.ReturnValueError() conn = connect.ConnectMySql() print(f'Connection status : {conn.is_connected()}') if (conn is False): return err.ReturnConnectionError() else: cur1 = conn.cursor() print(f'Cursor object : {cur1}') query = ( f'INSERT INTO orderPizza(pizza_type,pizza_size,pizza_count,user_name,mobile_number,address,status)values("{pizza}","{size}",{count}","{name}","{number}","{address}","{status}")' ) cur1.execute(query) cur2 = conn.cursor() selectquery = SelectQuery() cur2.execute(selectquery) msg = "Data inserted succesfully" result = res.generateResponse(cur2, msg) conn.close() return result except KeyError as e: return err.ReturnKeyError() except mysql.connector.IntegrityError as e: print(f'Exception : {e}') return err.ReturnDuplicateDataError()
def display(): conn = connect.ConnectMySql() print(f'Connection status : {conn}') if (conn is False): return err.ReturnConnectionError() else: try: cur = conn.cursor() print(f'Cursor object : {cur}') query = ('SELECT* from orderPizza') cur.execute(query) msg = "Data fetched succesfully" return res.generateResponse(cur, msg) except Exception as e: print(e) return err.ReturnFetchError() finally: conn.close()
def fetch(): conn = connect.ConnectMySql() print(f"Connection status : {conn}") if conn is False: return err.ReturnConnectionError() else: try: cur = conn.cursor() print(f"Cursor object : {cur}") query = "select * from pizza" cur.execute(query) msg = "Data fetched succesfully" return res.generateResponse(cur,msg) except Exception as e: print(e) return err.ReturnFetchError() finally: conn.close()
def fetch(): conn = connect.ConnectMySql() print(f"Connection status : {conn}") if conn is False: return err.ReturnConnectionError() else: try: cur = conn.cursor() print(f"Cursor object : {cur}") query = "select * from Pizza_det" cur.execute(query) msg = "Data fetched succesfully" return jsonify( {"fulfillmentMessages": [{"text": {"text": ["hello world"]}}]} ) except Exception as e: print(e) return err.ReturnFetchError() finally: conn.close()
def makeWebhookResult(req): print(req) if req.get("queryResult").get("action") == "order_placed": pizzadb = connection.ConnectMySql() update_table = connection.update_table(pizzadb) if pizzadb != False and update_table != False: result = req.get("queryResult") parameters = result.get("parameters") pizza_size = parameters.get("pizza_size") pizza_variety = parameters.get("pizza_variety") no_of_pizza = int(parameters.get("no_of_pizza")) amount = no_of_pizza * 100 name = parameters["name"]["name"] phone_no = parameters.get("phone_no") Email_id = parameters.get("Email_id") Address = parameters.get("Address") toppings = parameters.get("toppings") try: mycursor = pizzadb.cursor() sql = "INSERT INTO list_of_orders (Name, Email_Id, Address, Phone_no, No_of_pizza, pizza_size, type_of_pizza, toppings, amount, order_time,preparation_time,delivery_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,NOW()+1,NOW()+200,NOW()+400)" val = (name, Email_id, Address, phone_no, no_of_pizza, pizza_size, pizza_variety, toppings, amount) mycursor.execute(sql, val) pizzadb.commit() id_num = mycursor.lastrowid speech = "Your Order is placed :)<br/> Order ID : " + str( id_num ) + "<br/> Name : " + name + "<br/> Pizza ordered : " + str( no_of_pizza ) + " " + pizza_size + " " + pizza_variety + "<br/> Amount : " + str( amount ) + "<br/> order status : ordered <br/> Do you want to check your status?" return { "fulfillmentText": speech, "fulfillmentMessages": [{ "platform": "ACTIONS_ON_GOOGLE", "simpleResponses": { "simpleResponses": [{ "textToSpeech": speech }] } }] } except Error as err: print(err) return { "fulfillmentText": "Sorry some error has occured :(", "fulfillmentMessages": [{ "platform": "ACTIONS_ON_GOOGLE", "simpleResponses": { "simpleResponses": [{ "textToSpeech": "Sorry some error has occured :(" }] } }] } print(name) else: return { "fulfillmentText": "Sorry some error has occured :(", "fulfillmentMessages": [{ "platform": "ACTIONS_ON_GOOGLE", "simpleResponses": { "simpleResponses": [{ "textToSpeech": "Sorry some error has occured :(" }] } }] } if req.get("queryResult").get("action") == "search_order" or req.get( "queryResult").get("action") == "Searchorder.Searchorder-custom": pizzadb = connection.ConnectMySql() update_table = connection.update_table(pizzadb) if pizzadb != False and update_table != False: result = req.get("queryResult") parameters = result.get("parameters") id_num = int(parameters.get("id")) try: mycursor = pizzadb.cursor() select_query = "select status_of_order from list_of_orders where id = %s" search_id = (str(id_num), ) mycursor.execute(select_query, search_id) myresult = mycursor.fetchall() print(myresult) speech = "" if len(myresult) == 0: speech += "Please check your order id" else: for i in myresult: status = i[0] speech += "Your Order is status :)<br/> Order ID : " + str( id_num) + "<br/> order status : " + status return { "fulfillmentText": speech, "fulfillmentMessages": [{ "platform": "ACTIONS_ON_GOOGLE", "simpleResponses": { "simpleResponses": [{ "textToSpeech": speech }] } }] } except Error as err: print(err) return { "fulfillmentText": "Sorry some error has occured :(", "fulfillmentMessages": [{ "platform": "ACTIONS_ON_GOOGLE", "simpleResponses": { "simpleResponses": [{ "textToSpeech": "Sorry some error has occured :(" }] } }] } else: return { "fulfillmentText": "Sorry some error has occured :(", "fulfillmentMessages": [{ "platform": "ACTIONS_ON_GOOGLE", "simpleResponses": { "simpleResponses": [{ "textToSpeech": "Sorry some error has occured :(" }] } }] }