routes.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. @author: luojunhui
  3. """
  4. import time
  5. import uuid
  6. from quart import Blueprint, jsonify, request
  7. from applications.log import logging
  8. from applications.process import ProcessParams
  9. my_blueprint = Blueprint('kimi', __name__)
  10. @my_blueprint.route('/healthcheck')
  11. async def hello():
  12. """
  13. Hello World Test
  14. :return:
  15. """
  16. logging(
  17. code="1001",
  18. info="请求接口成功",
  19. port="healthcheck"
  20. )
  21. return jsonify({'message': 'Hello, World!'})
  22. @my_blueprint.route('/title_to_video', methods=['POST'])
  23. async def post_data():
  24. """
  25. 请求接口代码
  26. :return:
  27. """
  28. trace_id = str(uuid.uuid4()) + "-" + str(int(time.time()))
  29. logging(
  30. code="1001",
  31. info="请求接口成功",
  32. port="title_to_video",
  33. trace_id=trace_id
  34. )
  35. p = ProcessParams(t_id=trace_id)
  36. data = await request.get_json()
  37. processed_data = p.process(data)
  38. return jsonify(processed_data)
  39. @my_blueprint.route('/search_videos', methods=['POST'])
  40. async def search_data():
  41. """
  42. 通过搜索词去搜索获取视频信息
  43. :return:
  44. """
  45. trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
  46. logging(
  47. code="1001",
  48. info="请求接口成功",
  49. port="search_videos",
  50. trace_id=trace_id
  51. )
  52. data = await request.get_json()
  53. result = await search_spider(data)
  54. return jsonify(result)