Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #coding: utf-8 !/usr/bin/python
- from flask import Flask, request,render_template
- from flask import jsonify # <- `jsonify` instead of `json`
- from flask import json
- from bot import bot
- import pymysql
- import os
- import config
- flag =0
- class Database:
- def __init__(self ):
- host = "18.223.99.6"
- user = "trash"
- password = "3baseldaw1"
- db = "pixie"
- self.con = pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=pymysql.cursors.DictCursor)
- self.cur = self.con.cursor()
- def list_employees(self , item_name ):
- global flag
- self.cur.execute("SELECT * FROM Items where Name = %s LIMIT 50" , item_name)
- result = self.cur.fetchall()
- flag = self.cur.rowcount
- return result
- app = Flask(__name__)
- @app.route('/health_check')
- def healthCheck():
- return "Hello World!\n"
- #@app.route("/", methods=['POST']) def root():
- #@app.route('/price_check')
- #def price_check():
- # db = Database()
- # prices = db.list_employees()
- # return jsonify(prices)
- @app.route('/test', methods=['POST'])
- def item_query():
- def bolbol():
- db = Database()
- emps = db.list_employees(request.get_json()['item'])
- return emps
- res = bolbol()
- #requestJsond = jsonify(request)
- #return jsonify()
- #print (request.get_json()['item'])
- if flag == 0 :
- return jsonify(
- status=200,
- replies=[{
- 'type': 'text',
- 'content': 'القظعة غير متوفرة',
- }],
- conversation={
- 'memory': { 'price': '0'
- }
- }
- )
- else:
- return jsonify(
- status=200,
- replies=[{
- 'type': 'text',
- 'content': 'سعر ال' + request.get_json()['item'] + ' هو ' + res[0]['Price'] + 'جنية مصري ',
- }],
- conversation={
- 'memory': { 'price': res[0]['Price'] ,
- 'itemname': request.get_json()['item'] }
- }
- )
- #print (request.headers.get('aaaa'))
- #return result
- #return request.headers.get('aaaa')
- app.run(host='0.0.0.0', port=5000) # for AWS
- ############ health check --- required by AWS Load ealth_check')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement