routes.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Blueprint, jsonify, request
  5. from applications.functions.log import logging
  6. from applications.schedule import recall_videos
  7. from applications.deal import ReSearchDeal, SearchDeal2, ProcessDeal
  8. my_blueprint = Blueprint('LongArticles', __name__)
  9. def Routes(mysql_client):
  10. """
  11. 路由代码
  12. """
  13. @my_blueprint.route('/healthcheck')
  14. def healthcheck():
  15. """
  16. Hello World Test
  17. :return:
  18. """
  19. return jsonify({'message': 'Hello, World!'})
  20. @my_blueprint.route('/search_videos', methods=['POST'])
  21. async def search_videos_from_the_web():
  22. """
  23. 从web 搜索视频并且存储到票圈的视频库中
  24. :return:
  25. """
  26. params = await request.get_json()
  27. SD = SearchDeal2(params=params, mysql_client=mysql_client)
  28. result = await SD.deal()
  29. return jsonify(result)
  30. @my_blueprint.route('/recall_videos', methods=['POST'])
  31. async def find_videos():
  32. """
  33. 请求接口代码
  34. :return:
  35. """
  36. data = await request.get_json()
  37. trace_id = data['traceId']
  38. logging(
  39. code="1001",
  40. info="请求接口成功",
  41. port="recall_videos",
  42. trace_id=trace_id
  43. )
  44. try:
  45. result = await recall_videos(
  46. trace_id=trace_id,
  47. mysql_client=mysql_client
  48. )
  49. print(result)
  50. except Exception as e:
  51. result = {
  52. "traceId": trace_id,
  53. "error": str(e)
  54. }
  55. print(result)
  56. return jsonify(result)
  57. @my_blueprint.route('/re_search_videos', methods=['POST'])
  58. async def ree_search_videos():
  59. """
  60. 重新搜索
  61. :return:
  62. """
  63. params = await request.get_json()
  64. RSD = ReSearchDeal(params=params)
  65. res = await RSD.deal()
  66. return jsonify(res)
  67. @my_blueprint.route("/task")
  68. async def schedule_task():
  69. """
  70. 执行代码
  71. :return:
  72. """
  73. PD = ProcessDeal(mysql_client=mysql_client)
  74. await PD.deal()
  75. return jsonify({"success": "true"})
  76. return my_blueprint