__init__.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 .process_killer import kill_task_by_name
  12. from deal import tempServer
  13. TL_blueprint = Blueprint("TouLiu", __name__)
  14. def Routes(db_client):
  15. """
  16. 路由代码
  17. :param db_client: 异步db连接池
  18. :return:
  19. """
  20. @TL_blueprint.route("/hello")
  21. def helloWorld():
  22. """
  23. :return: Hello World
  24. """
  25. return jsonify({"message": "Hello World!"})
  26. @TL_blueprint.route("/generateInfo", methods=['POST'])
  27. async def generateInfo():
  28. """
  29. 生成一些需要用到到信息
  30. :return:
  31. """
  32. request_id = "generateInfo_{}_{}".format(uuid.uuid4(), int(time.time()))
  33. data = await request.get_json()
  34. response = await saveSourceToDB(
  35. db_client=db_client,
  36. params=data,
  37. request_id=request_id
  38. )
  39. return jsonify(response)
  40. @TL_blueprint.route("/insertVideo", methods=['POST'])
  41. async def insertVideos():
  42. """
  43. 插入视频信息
  44. :return:
  45. """
  46. request_id = "insertVideos_{}_{}".format(uuid.uuid4(), int(time.time()))
  47. data = await request.get_json()
  48. response = await insert(
  49. db_client=db_client,
  50. params=data,
  51. request_id=request_id
  52. )
  53. return jsonify(response)
  54. @TL_blueprint.route("/recallPQVideos", methods=['POST'])
  55. async def recallVideos():
  56. """
  57. 搜索视频信息
  58. :return:
  59. """
  60. request_id = "recallPQVideos_{}_{}".format(uuid.uuid4(), int(time.time()))
  61. data = await request.get_json()
  62. response = await recallPQVideos(
  63. db_client=db_client,
  64. params=data,
  65. request_id=request_id
  66. )
  67. return jsonify(response)
  68. @TL_blueprint.route("/VideoRank", methods=['POST'])
  69. async def ranks():
  70. """
  71. :return:
  72. """
  73. # request_id = "videoRank_{}_{}".format(uuid.uuid4(), int(time.time()))
  74. data = await request.get_json()
  75. gh_id = data['ghId']
  76. ts = tempServer(gh_id=gh_id)
  77. response = ts.chooseCards()
  78. return jsonify(response)
  79. @TL_blueprint.route("/KILL", methods=['GET'])
  80. async def kill():
  81. """
  82. 杀掉进程
  83. :return:
  84. """
  85. task_name = request.args.get("taskName")
  86. if task_name:
  87. if task_name in ['historyTask.py', 'newContentIdTask.py']:
  88. status = await kill_task_by_name(task_name)
  89. if status:
  90. return jsonify({"message": "success"})
  91. else:
  92. return jsonify({"message": "failed"})
  93. else:
  94. return jsonify({"message": "task name error"})
  95. else:
  96. return jsonify({"message": "no task name"})
  97. return TL_blueprint