main.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from flask import Flask, request, jsonify, make_response
  2. import json
  3. import sys
  4. from classify_service import classifyer
  5. sys.path.append("classify_service")
  6. import logging
  7. logging.basicConfig(level=logging.DEBUG)
  8. app = Flask(__name__)
  9. @app.route('/get_category', methods=["POST"])
  10. def get_testcase_category():
  11. request_data = request.data.decode('utf-8')
  12. try:
  13. app.logger.debug(request_data)
  14. json_data = json.loads(request_data, strict=False)
  15. except:
  16. app.logger.debug(sys.exc_info()[0])
  17. return make_response(jsonify({"Bad Request"}), 400)
  18. result = classifyer.get_testcase_label(json_data)
  19. return jsonify(result)
  20. if __name__ == "__main__":
  21. handler = logging.FileHandler('./flask.log', encoding='UTF-8') # 设置日志字符集和存储路径名字
  22. logging_format = logging.Formatter( # 设置日志格式
  23. '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
  24. handler.setFormatter(logging_format)
  25. app.logger.addHandler(handler)
  26. app.run('0.0.0.0', port=8200, debug=True)