Advertisement
Guest User

Untitled

a guest
Nov 26th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #coding: utf-8 !/usr/bin/python
  2. from flask import Flask, request,render_template
  3. from flask import jsonify # <- `jsonify` instead of `json`
  4. from flask import json
  5. from bot import bot
  6. import pymysql
  7. import os
  8. import config
  9. flag =0
  10. class Database:
  11. def __init__(self ):
  12. host = "18.223.99.6"
  13. user = "trash"
  14. password = "3baseldaw1"
  15. db = "pixie"
  16. self.con = pymysql.connect(host=host, user=user, password=password, db=db, cursorclass=pymysql.cursors.DictCursor)
  17. self.cur = self.con.cursor()
  18. def list_employees(self , item_name ):
  19. global flag
  20. self.cur.execute("SELECT * FROM Items where Name = %s LIMIT 50" , item_name)
  21. result = self.cur.fetchall()
  22. flag = self.cur.rowcount
  23. return result
  24. app = Flask(__name__)
  25. @app.route('/health_check')
  26. def healthCheck():
  27. return "Hello World!\n"
  28. #@app.route("/", methods=['POST']) def root():
  29.  
  30.  
  31. #@app.route('/price_check')
  32. #def price_check():
  33. # db = Database()
  34. # prices = db.list_employees()
  35. # return jsonify(prices)
  36.  
  37. @app.route('/test', methods=['POST'])
  38. def item_query():
  39. def bolbol():
  40. db = Database()
  41. emps = db.list_employees(request.get_json()['item'])
  42. return emps
  43. res = bolbol()
  44. #requestJsond = jsonify(request)
  45. #return jsonify()
  46. #print (request.get_json()['item'])
  47. if flag == 0 :
  48. return jsonify(
  49. status=200,
  50. replies=[{
  51. 'type': 'text',
  52. 'content': 'القظعة غير متوفرة',
  53. }],
  54. conversation={
  55. 'memory': { 'price': '0'
  56. }
  57. }
  58. )
  59. else:
  60. return jsonify(
  61. status=200,
  62. replies=[{
  63. 'type': 'text',
  64. 'content': 'سعر ال' + request.get_json()['item'] + ' هو ' + res[0]['Price'] + 'جنية مصري ',
  65. }],
  66. conversation={
  67. 'memory': { 'price': res[0]['Price'] ,
  68. 'itemname': request.get_json()['item'] }
  69. }
  70. )
  71.  
  72. #print (request.headers.get('aaaa'))
  73. #return result
  74. #return request.headers.get('aaaa')
  75.  
  76.  
  77.  
  78. app.run(host='0.0.0.0', port=5000) # for AWS
  79. ############ health check --- required by AWS Load ealth_check')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement