routes.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. from applications.mq import MQ
  10. my_blueprint = Blueprint('kimi', __name__)
  11. @my_blueprint.route('/healthcheck')
  12. async def hello():
  13. """
  14. Hello World Test
  15. :return:
  16. """
  17. logging(
  18. code="1001",
  19. info="请求接口成功",
  20. port="healthcheck"
  21. )
  22. return jsonify({'message': 'Hello, World!'})
  23. @my_blueprint.route('/title_to_video', methods=['POST'])
  24. async def post_data():
  25. """
  26. 请求接口代码
  27. :return:
  28. """
  29. trace_id = str(uuid.uuid4()) + "-" + str(int(time.time()))
  30. logging(
  31. code="1001",
  32. info="请求接口成功",
  33. port="title_to_video",
  34. trace_id=trace_id
  35. )
  36. p = ProcessParams(t_id=trace_id)
  37. data = await request.get_json()
  38. processed_data = p.process(data)
  39. return jsonify(processed_data)
  40. @my_blueprint.route('/search_videos', methods=['POST'])
  41. async def search_data():
  42. """
  43. 通过搜索词去搜索获取视频信息
  44. :return:
  45. """
  46. mq = MQ(topic_name="search_spider_prod")
  47. trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
  48. logging(
  49. code="1001",
  50. info="请求接口成功",
  51. port="search_videos",
  52. trace_id=trace_id
  53. )
  54. data = await request.get_json()
  55. mq.send_msg(params=data)
  56. return jsonify({
  57. "code": 0
  58. })