routes.py 1.5 KB

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