__init__.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """
  2. @author: luojunhui
  3. 投流--路由
  4. """
  5. import time
  6. import uuid
  7. from quart import Blueprint, jsonify, request
  8. from .insertVideoRoute import insert
  9. from .sourceIdRoute import saveSourceToDB
  10. from .recallPQVideos import recallPQVideos
  11. from deal import tempServer
  12. TL_blueprint = Blueprint("TouLiu", __name__)
  13. def Routes(db_client):
  14. """
  15. 路由代码
  16. :param db_client: 异步db连接池
  17. :return:
  18. """
  19. @TL_blueprint.route("/hello")
  20. def helloWorld():
  21. """
  22. :return: Hello World
  23. """
  24. return jsonify({"message": "Hello World!"})
  25. @TL_blueprint.route("/generateInfo", methods=['POST'])
  26. async def generateInfo():
  27. """
  28. 生成一些需要用到到信息
  29. :return:
  30. """
  31. request_id = "generateInfo_{}_{}".format(uuid.uuid4(), int(time.time()))
  32. data = await request.get_json()
  33. response = await saveSourceToDB(
  34. db_client=db_client,
  35. params=data,
  36. request_id=request_id
  37. )
  38. return jsonify(response)
  39. @TL_blueprint.route("/insertVideo", methods=['POST'])
  40. async def insertVideos():
  41. """
  42. 插入视频信息
  43. :return:
  44. """
  45. request_id = "insertVideos_{}_{}".format(uuid.uuid4(), int(time.time()))
  46. data = await request.get_json()
  47. response = await insert(
  48. db_client=db_client,
  49. params=data,
  50. request_id=request_id
  51. )
  52. return jsonify(response)
  53. @TL_blueprint.route("/recallPQVideos", methods=['POST'])
  54. async def recallVideos():
  55. """
  56. 搜索视频信息
  57. :return:
  58. """
  59. request_id = "recallPQVideos_{}_{}".format(uuid.uuid4(), int(time.time()))
  60. data = await request.get_json()
  61. response = await recallPQVideos(
  62. db_client=db_client,
  63. params=data,
  64. request_id=request_id
  65. )
  66. return jsonify(response)
  67. @TL_blueprint.route("/VideoRank", methods=['POST'])
  68. async def ranks():
  69. """
  70. :return:
  71. """
  72. # request_id = "videoRank_{}_{}".format(uuid.uuid4(), int(time.time()))
  73. data = await request.get_json()
  74. gh_id = data['ghId']
  75. ts = tempServer(gh_id=gh_id)
  76. response = ts.chooseCards()
  77. return jsonify(response)
  78. return TL_blueprint