routes.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.functions.search_video import search_spider
  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. trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
  47. logging(
  48. code="1001",
  49. info="请求接口成功",
  50. port="search_videos",
  51. trace_id=trace_id
  52. )
  53. data = await request.get_json()
  54. result = await search_spider(data)
  55. return jsonify(result)