server.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from flask import Flask,request
  2. from utils.DataSearchUtils import MysqlSearchUtils
  3. from utils.HttpUtils import HttpUtils
  4. from ai_auto_create_creative_job import AiAutoCreateCreativeJob
  5. import json
  6. from utils import ResultDictUtils
  7. from flask_cors import CORS
  8. app = Flask(__name__)
  9. CORS(app, resources=r'/*')
  10. mysql = MysqlSearchUtils()
  11. httpUtils = HttpUtils()
  12. aiAutoCreateCreativeJob = AiAutoCreateCreativeJob()
  13. @app.route('/hello')
  14. def hello_word():
  15. print(request.path)
  16. print(request.full_path)
  17. return 'hello world'
  18. @app.route('/getOne')
  19. def get_json():
  20. response_dict = {}
  21. data = mysql.get_one()
  22. response_dict["data"] = data
  23. return response_dict
  24. @app.route('/getList',methods=["post"])
  25. def get_list():
  26. body = request.json
  27. print(body["accountId"])
  28. response_dict = {}
  29. list = mysql.get_all()
  30. response_dict["list"] = list
  31. return response_dict
  32. @app.route('/testReport',methods=["get"])
  33. def test_report():
  34. rest = httpUtils.get("http://localhost:8079/getOne",{"accountId":"123"},{"accountId":"123"})
  35. return json.loads(rest)
  36. @app.route('/autoCreateCreativeJob')
  37. def auto_create_creative_job():
  38. response_dict = ResultDictUtils.common_success_dict
  39. account_id = request.args.get("accountId")
  40. if 0 == account_id or account_id is None:
  41. return ResultDictUtils.params_error_dict
  42. rest = aiAutoCreateCreativeJob.auto_create_job(account_id)
  43. response_dict["data"] = rest
  44. return response_dict
  45. if __name__ == '__main__':
  46. app.run(host='0.0.0.0',port=8079,debug=True)