routes.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import time
  6. import uuid
  7. from quart import Blueprint, jsonify, request
  8. from applications.functions.log import logging
  9. from applications.schedule import ProcessParams, search_videos
  10. from applications.functions.common import MySQLServer
  11. from applications.functions.kimi import KimiServer
  12. from applications.schedule.main_schedule import AskForInfo
  13. my_blueprint = Blueprint('kimi', __name__)
  14. @my_blueprint.route('/healthcheck')
  15. def hello():
  16. """
  17. Hello World Test
  18. :return:
  19. """
  20. logging(
  21. code="1001",
  22. info="请求接口成功",
  23. port="healthcheck"
  24. )
  25. return jsonify({'message': 'Hello, World!'})
  26. @my_blueprint.route('/title_to_search', methods=['POST'])
  27. async def search_videos_from_the_web():
  28. """
  29. 从web 搜索视频并且存储到票圈的视频库中
  30. :return:
  31. """
  32. params = await request.get_json()
  33. K = KimiServer()
  34. gh_id = params['ghId']
  35. trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
  36. params['trace_id'] = trace_id
  37. logging(
  38. code="2000",
  39. info="搜索视频内容接口请求成功",
  40. port="title_to_search",
  41. function="search_videos_from_the_web",
  42. trace_id=trace_id
  43. )
  44. # try:
  45. kimi_info = await K.search_kimi_schedule(params=params)
  46. await search_videos(
  47. kimi_info=kimi_info,
  48. trace_id=trace_id,
  49. gh_id=gh_id
  50. )
  51. print(json.dumps(kimi_info, ensure_ascii=False, indent=4))
  52. res = {
  53. "trace_id": trace_id,
  54. "code": 0,
  55. "kimi_title": kimi_info['k_title']
  56. }
  57. # except Exception as e:
  58. # res = {
  59. # "trace_id": trace_id,
  60. # "code": 1,
  61. # "message": str(e)
  62. # }
  63. return jsonify(res)
  64. @my_blueprint.route('/out_videos', methods=['POST'])
  65. async def find_in_mysql():
  66. """
  67. 搜索是否存在外站视频 video_list, 如果存在,则返回成功
  68. :return:
  69. """
  70. data = await request.get_json()
  71. trace_id = data['traceId']
  72. logging(
  73. code="2000",
  74. info="请求接口成功",
  75. port="title_to_video",
  76. trace_id=trace_id,
  77. function="find_in_mysql"
  78. )
  79. res = MySQLServer().select_download_videos(trace_id=trace_id)
  80. return jsonify(res)
  81. @my_blueprint.route('/find_video', methods=['POST'])
  82. async def post_data():
  83. """
  84. 请求接口代码
  85. :return:
  86. """
  87. data = await request.get_json()
  88. trace_id = data['traceId']
  89. logging(
  90. code="1001",
  91. info="请求接口成功",
  92. port="title_to_video",
  93. trace_id=trace_id
  94. )
  95. p = ProcessParams(t_id=trace_id)
  96. processed_data = await p.deal(data)
  97. return jsonify(processed_data)
  98. @my_blueprint.route('/title_to_video', methods=['POST'])
  99. async def delay_response():
  100. """
  101. main
  102. :return:
  103. """
  104. # 从请求体中解析 JSON 数据
  105. data = await request.get_json()
  106. A = AskForInfo(data)
  107. res = await A.schedule()
  108. return jsonify(res)